0

My app worked well until recently. Then, I updated compileSdk and buildTools to 25. Since then my app crashes immidiately on opening. Setting minSdkVersion to 18 solves the issue, but whe I put it back to 21, this is what happenes. Attaching stack trace and parts of my gradle file

01-25 19:07:59.848 18879-18879/com.vimi.vimichat E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.vimi.vimichat, PID: 18879
   java.lang.RuntimeException: Unable to instantiate application com.vimi.vimichat.Common: java.lang.ClassNotFoundException: Didn't find class "com.vimi.vimichat.Common" on path: DexPathList[[zip file "/data/app/com.vimi.vimichat-1/base.apk"],nativeLibraryDirectories=[/data/app/com.vimi.vimichat-1/lib/arm64, /vendor/lib64, /system/lib64]]
       at android.app.LoadedApk.makeApplication(LoadedApk.java:586)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5041)
       at android.app.ActivityThread.access$1500(ActivityThread.java:187)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)
       at android.os.Handler.dispatchMessage(Handler.java:111)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5844)
       at java.lang.reflect.Method.invoke(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1109)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.vimi.vimichat.Common" on path: DexPathList[[zip file "/data/app/com.vimi.vimichat-1/base.apk"],nativeLibraryDirectories=[/data/app/com.vimi.vimichat-1/lib/arm64, /vendor/lib64, /system/lib64]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
       at android.app.Instrumentation.newApplication(Instrumentation.java:988)
       at android.app.LoadedApk.makeApplication(LoadedApk.java:581)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5041) 
       at android.app.ActivityThread.access$1500(ActivityThread.java:187) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643) 
       at android.os.Handler.dispatchMessage(Handler.java:111) 
       at android.os.Looper.loop(Looper.java:194) 
       at android.app.ActivityThread.main(ActivityThread.java:5844) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at java.lang.reflect.Method.invoke(Method.java:372) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1109) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875) 
    Suppressed: java.lang.ClassNotFoundException: com.vimi.vimichat.Common
       at java.lang.Class.classForName(Native Method)
       at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
       at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 13 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Attaching parts of my project gradle file

    apply plugin: 'com.android.application'
apply plugin: 'io.fabric'



repositories {

    mavenCentral()

}
android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
    defaultConfig {

        minSdkVersion 21
        targetSdkVersion 21
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
        // Enabling multidex support.
        multiDexEnabled true
    }



    dexOptions {
        javaMaxHeapSize "4g"
        jumboMode = true
    }

    useLibrary 'org.apache.http.legacy'

}

I saw these stack trace erros many times here, but no clear answer on what is the problem.

I tried cleaning and rebuilding, clearing Android Studio caches, updating gradle version and plugin. Nothing seems to work for me.

EDIT 1

It seems like the problem relies in one or more of the android support libraries

compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'

reverting all of them to 24.1.0 seems to fix the issue. However, I am using some of the features in later versions of them, so that is not helping.

amitfr
  • 1,033
  • 1
  • 9
  • 29
  • Are you using any native libraries by any chance? I went back to compiling with compileSdkVersion 24 to solve a host of random errors. – Ewald Jan 26 '17 at 08:38
  • What device are you running? Which API version? – Michael Meyer Feb 01 '17 at 15:24
  • Multiple devices and API levels. Emulators, Meizu m3s, SG note 5, Android 5.1 and 6 – amitfr Feb 01 '17 at 15:47
  • maybe you can try the following http://stackoverflow.com/questions/26609734/how-to-enable-multidexing-with-the-new-android-multidex-support-library. You may have to create your custom Application Class with Multidex enabled (dont forget to register the class) – Michael Meyer Feb 02 '17 at 07:39
  • I seem to have the exact same issue on Lollipop devices. No problem on Marshmallow or newer, but on Lollipop if I set minSdk to 21 I get the same stacktrace and crash. Setting minSdk = 19, all works on Lollipop too. I have Multidex support library and Application extends MultiDexApplication. Did you find a solution to this? Or bug in Android toolchain and/or support library? – Johan Paul Oct 22 '17 at 14:04
  • @JohanPaul no, sorry, I just left it at minSdk 18. I've moved to another project since then – amitfr Oct 25 '17 at 06:16

1 Answers1

0

I had the same issue. I resolved the issue by doing two things.

  1. Add the following to the app's build.gradle file.

android { ... dexOptions { preDexLibraries false } } For me it crashed because of a ClassNotFoundException regarding the RxJava2 BehaviourSubject, thus disabling predex for libraries resolved it.

  1. Disable Instant Run from the project. Uncheck Settings -> Build, Execute, Deployment -> Instant Run -> Enable Instant Run
Johan Paul
  • 2,203
  • 2
  • 22
  • 38