javaandroidkotlingradle

Android native app not working after upgrade to SDK 34


I recently upgraded two of my android apps to SDK 34 on request from Google, because the app was in violation of policy and need to be upgraded to SDK 34 by the end of the month.

The apps work fine in debug mode. When signed and bundled and uploaded to Google play, upon download, opening the app fails, it simply crashes.

The stack trace from Google Play console gives me the following, and that's it:

Exception java.lang.LinkageError:
  at java.lang.VMClassLoader.findLoadedClass
  at java.lang.ClassLoader.findLoadedClass (ClassLoader.java:738)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:363)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
  at android.app.AppComponentFactory.instantiateActivity (AppComponentFactory.java:95)
  at androidx.core.app.CoreComponentFactory.instantiateActivity (CoreComponentFactory.java:44)
  at android.app.Instrumentation.newActivity (Instrumentation.java:1378)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:4034)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:4322)
  at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:103)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:139)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:96)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2685)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:230)
  at android.os.Looper.loop (Looper.java:319)
  at android.app.ActivityThread.main (ActivityThread.java:8919)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)

Any ideas anyone?


Solution

  • Simply connecting the release build of the app to Android Studio and monitoring the logcat was enough to get to the bottom of the issue.

    The stack trace in logcat was more informative and pointed to a "missing method".

    Further investigation revealed that Gradle 8+ (I had upgraded from Gradle 7 to 8 prior to the upgrade to SDK 34, as was recommended) causes this problem during the "minify" step. You are unlikely to get this problem if your application isn't a multi-module app.

    Essentially, all that needs doing is to update the proguard-rules file(s) in the depending module(s) (not the dependent one(s)), to include a keep rule that looks something like this for the package which contains the missing method(s)/class(es):

    -keep class com.yourcompany.yourpackageroot.yourpackagename.** { *; }

    Then the minify step works properly.

    Some SO answers on here suggest setting minifyEnabled to false on your release build(s), but while that will make your release builds work, it would mean your code would no longer be obfuscated - therefore not really an option.