2

In a debug version app works fine. But when I generate sign apk and install this, after open app - it immediately crashes due to a logcat error:

 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mypackage.AppClass" on path: DexPathList[[zip file "/data/app/com.mypackage-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]].

I use AppClass to extends MultiDexApplication and I've got there some functions also. I have declared this class correctly in a manifest.

The most complicated is that it works in a debug version but only in release version this problem occurs.

I would be really grateful if someone could help me to resolve this situation.

Regards

gryzek
  • 537
  • 9
  • 25
  • (1) Run Build > Clean Project first. (2) Proguard removes all unused code, and sometimes make mistakes, review your Proguard settings. (3) You need to change minifyEnabled attribute to false to keep unused methods permanently. Your build.gradle maybe useful. – Jon Goodwin Jan 18 '18 at 21:15
  • @JonGoodwin I cleaned many times. minifyEnabled is set to false also. I will look more deeper on build.gradle. – gryzek Jan 18 '18 at 21:21
  • See [multidex](https://medium.com/groupon-eng/android-s-multidex-slows-down-app-startup-d9f10b46770f) "While setting up multidexing for your project, you may notice a java.lang.NoClassDefFoundError when running your app. This means that the class for app startup is not located in the main dex file. The Android plugin for Gradle in Android SDK Build Tools 21.1 or higher has multidex support." – Jon Goodwin Jan 20 '18 at 15:24

2 Answers2

1

Check this options:

Option 1: decrease your gradle version

Option 2: minifyEnabled false

Option 3: use stable support library and build tools.

Option 4: Invalidate caches/restart, file->invalidate caches/restart

Option 5: If you are using private platform libraries, make sure your non-NDK libraries with your APK.

josedlujan
  • 5,357
  • 2
  • 27
  • 49
  • I cannot decrease gradle from 3.0.1 to i.e: 2.3.3. I use Android Studio 3.0.1 and the newest one is needed. I did restart many times without any positive results. Maybe the problem is with some libraries but why it works on unsigned apk (just build apk) but not working on signed. As I check I use more that 64k methods but in previous version it worked correctly (last signed apk was 4 months ago). – gryzek Jan 18 '18 at 23:20
0

Finally, I found a solution which helped me to resolve this problem. I had to add this part of code in a gradle:

  dexOptions {
      preDexLibraries = false
   }

And the following to the general part of your apps build.gradle

afterEvaluate {
   tasks.matching {
      it.name.startsWith('dex')
   }.each { dx ->
      if (dx.additionalParameters == null) {
         dx.additionalParameters = ['--multi-dex']
      } else {
         dx.additionalParameters += '--multi-dex'
      }
   }
}

For the others who can have similar issue I'm referring to a post in which I obtained a solution: https://stackoverflow.com/a/26627133/5736917

gryzek
  • 537
  • 9
  • 25