13

On my latest release a few of my users (less than 0.2%) are getting a crash because android.support.v7.app.AppCompatDelegateImplV23 can not be found. I can not reproduce the issue, I'm only getting reports over crashlytics. I have used apktool to extract the files out of my apk and I can see AppCompatDelegateImplV23.smali in there. Any idea what could be happening?

This is my compile line on gradle:

compile 'com.android.support:appcompat-v7:23+'

This is the exception:

Fatal Exception: java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV23
       at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:133)
       at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117)
       at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456)
       at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
       at MyActivityClass.onCreate(MyActivityClass.java:353)
       at android.app.Activity.performCreate(Activity.java:6248)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
       at android.app.ActivityThread.access$900(ActivityThread.java:150)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:168)
       at android.app.ActivityThread.main(ActivityThread.java:5845)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
       at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)

EDIT: This is my main gradle file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        jcenter() // version plugin support

    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        classpath 'com.android.tools.build:gradle:1.3.1'

    }
    allprojects {
        repositories {
            jcenter()
        }
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'


repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    signingConfigs {
        config {
......
        }
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    useLibrary 'org.apache.http.legacy'

    productFlavors {
        // Define separate dev and prod product flavors.
        dev {
            // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
            // to pre-dex each module and produce an APK that can be tested on
            // Android Lollipop without time consuming dex merging processes.
            minSdkVersion 21
        }
        prod {
            // The actual minSdkVersion for the application.
            minSdkVersion 14
        }
    }
    defaultConfig {
        applicationId "mypackage"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode some number
        versionName "some version number"
        multiDexEnabled true
        signingConfig signingConfigs.config

    }


    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    output.outputFile = new File(output.outputFile.parent,"myapk.apk")

                }
            }
        }
        debug {
            signingConfig signingConfigs.config
        }

    }
    repositories {
        mavenCentral()
        mavenLocal()
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7

    }
    packagingOptions {
        exclude 'AndroidManifest.xml'
        exclude 'META-INF/beans.xml'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }
    productFlavors {
    }
    dexOptions {
     //   preDexLibraries = false
        jumboMode = true
        javaMaxHeapSize "2g"
        //doesn't seem to be supported with multidex
       //   incremental true

    }
    lintOptions{
        disable 'MissingTranslation'
        disable 'ExtraTranslation'
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
    //multidex
    compile 'com.android.support:multidex:1.0.0'
    //support libs
    compile 'com.android.support:support-v4:23+'
    compile 'com.android.support:appcompat-v7:23+'
    compile 'com.android.support:cardview-v7:23+'
    compile 'com.android.support:design:23+'

    //app invites
    compile 'com.google.android.gms:play-services-appinvite:8+'

    compile 'com.google.android.gms:play-services-analytics:8+'
    //chromecast
    compile 'com.google.android.gms:play-services-cast:8+'
    compile 'com.android.support:mediarouter-v7:23+'

    //plus button
    compile 'com.google.android.gms:play-services-plus:8+'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }


    compile 'com.github.navasmdc:MaterialDesign:1.+@aar'


    //material lib needs it
    compile 'com.nineoldandroids:library:2.4.+'


    compile 'com.facebook.stetho:stetho:1+'
    compile 'com.facebook.stetho:stetho-okhttp:1+'



    //debugCompile 'com.squareup.leakcanary:leakcanary-android:1+'
    debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1+'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1+'

    compile 'com.makeramen:dragsortadapter:1.3+'

    compile 'com.github.amlcurran.showcaseview:library:5.0.0'


}

EDIT: just had a new report but for a different version of the same class

Fatal Exception: java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
       at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:135)
       at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117)
       at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456)
       at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
       at MyActivity.onCreate(MyActivity.java:353)
       at android.app.Activity.performCreate(Activity.java:5008)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
       at android.app.ActivityThread.access$600(ActivityThread.java:133)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4795)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
       at dalvik.system.NativeStart.main(NativeStart.java)

EDIT: I've just gone over a lot of the reports, some are for AppCompatDelegateImplV23 and some are for AppCompatDelegateImplV14, some involved XPosed but most don't. The one thing that is common to all of them is that they are all for rooted phones.

casolorz
  • 8,486
  • 19
  • 93
  • 200
  • post your build.gradle – Gabriele Mariotti Feb 22 '16 at 10:27
  • See [this](http://stackoverflow.com/questions/31384935/getting-exception-java-lang-noclassdeffounderror-android-support-v7-app-appco) may help you. – pRaNaY Feb 22 '16 at 12:58
  • @GabrieleMariotti added the gradle file. – casolorz Feb 22 '16 at 14:27
  • @pRaNaY I am already using multidex. Like I said, this only happens to a few people, not everyone and I can't reproduce. – casolorz Feb 22 '16 at 14:28
  • Have you looked into that one http://stackoverflow.com/questions/31384935/getting-exception-java-lang-noclassdeffounderror-android-support-v7-app-appco – Eduardo Feb 23 '16 at 19:46
  • @Eduardo that's the same one pRaNaY pointed out. I am already using multidex and I am already using the split google play services. – casolorz Feb 23 '16 at 20:34
  • call `classpath 'com.android.tools.build:gradle:1.5.0'` & `compile 'com.android.support:appcompat-v7:23.1.1'` HOPE THIS HELPS – IntelliJ Amiya Feb 24 '16 at 09:21
  • 1
    I'll change the 'com.android.tools.build:gradle` version but I'm already using 23+ on the appcompat library. – casolorz Feb 24 '16 at 15:21
  • @mntgoat is there any problem if you call `compile 'com.android.support:appcompat-v7:23.0.1'` – IntelliJ Amiya Feb 25 '16 at 08:39
  • 1
    @IntelliJAmiya no there is no problem but I'm actually going to switch to `23.2` this week. – casolorz Feb 25 '16 at 14:48
  • @mntgoat me too . Using this `"com.android.support:appcompat-v7:23.1.1"` – IntelliJ Amiya Feb 25 '16 at 14:55
  • let me feedback about `v7:23.1.1` . – IntelliJ Amiya Feb 25 '16 at 15:02
  • http://stackoverflow.com/questions/32107568/updated-appcompat-v7-to-the-newest-version-get-noclassdeffound-for-appcompatdel – IntelliJ Amiya Feb 29 '16 at 08:39
  • His issue is slightly different because it happens every time, for me it only happens for a small percentage of my users and I'm unable to reproduce. Also I am using gradle so I shouldn't have the issues that person had with importing projects. – casolorz Feb 29 '16 at 12:26
  • put apply plugin: 'com.google.gms.google-services' at the bottom, something same happened with be and by doing so helped me. – UMESH0492 Feb 29 '16 at 19:48
  • 1
    I think this question is the same http://stackoverflow.com/questions/31384935/getting-exception-java-lang-noclassdeffounderror-android-support-v7-app-appco did you tried it ? – Sunil Sunny Mar 01 '16 at 04:50
  • Is the crash only happening on Samsung running Android 5 or later? – DDsix Mar 01 '16 at 12:53
  • @sunilsunny that's the same one others have pointed, it is different. – casolorz Mar 01 '16 at 15:06
  • @DDsix nope, I just had a new one very similar on 4.1.1 but for `android.support.v7.app.AppCompatDelegateImplV14` – casolorz Mar 01 '16 at 15:07
  • It seems your app is runnig on devices which doesn't support any api requied by `android.support.v7.app.AppCompatDelegateImplV23` I guest. – Eugene Kirin Mar 01 '16 at 15:18

2 Answers2

3

First of all, we need to understand why java.lang.NoClassDefFoundError error occurs :

So the answer is that when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.

So there are some options by that you can remove this error:

1) Make preDexLibraries to true:

 dexOptions {
        preDexLibraries = true
        jumboMode = true
        javaMaxHeapSize "2g"
        //doesn't seem to be supported with multi dex
       //   incremental true
    }

2) There may be the problem with the incremental build system. So try to try to remove your build folder from your project and Rebuild the project OR Right click on your project -> "Open module settings" -> Dependencies tab -> check if Export is checked for your library

3) You need to do more than just provide MultiDex support.

  • multiDexEnabled = true in your defaultConfig block
  • Include compile 'com.android.support:multidex:1.0.0' in your dependencies
  • Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application

For more reference you can check the below link which has provided more advance understanding of multi dex.

https://developer.android.com/tools/building/multidex.html

4) Or at last you can add jar files of V7 into your project's libs folder and then add it your build System.

5) Also try removing the jar files as well as it still includes the com.android.support:support-v4:23+ as gradle has a repository where it downloads the jars delcared like compile 'compile 'com.android.support:appcompat-v7:23+'

Hope this can give you some clue about your error.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
  • 3
    If the class is not packaged inside the apk, then the exception should occur for **all** users, not just 0.2% of users. – Jiyong Park Mar 01 '16 at 06:08
  • I think you have not read my answer properly. For you please understand the meaning of this sentence "NoClassDefFoundError will come if a class was present during compile time but not available in java classpath during runtime" – KishuDroid Mar 01 '16 at 06:31
  • 1
    Sure, I have read your answer and I know well about `NoClassDefFoundError`. Recall what @mntgoat said: **I have used apktool to extract the files out of my apk and I can see AppCompatDelegateImplV23.smali in there.** This means that the class is packaged inside the apk. And also recall that Android uses a `DexClassLoader` that tries to load classes from the loaded apk. So, the problem cannot occur in any **compatible** Android device. This is why the problem is happening on only a few user's devices. – Jiyong Park Mar 01 '16 at 07:09
  • @JiyongPark is correct. First this only happens to a small percentage of my users. Second, I have verified that the class is present by unpacking the apk. – casolorz Mar 01 '16 at 15:05
1

My guess is that the problem is due to the xposed framework. At the bottom of the stack trace, you can find that the zygote was started by the xposed framework.

   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
   at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)

This means that the user is using a custom Android rom with the xposed framework installed. The framework is usually used to modify the behavior of the Android framework (and any app of course) code by injecting new code at run-time.

You can check how it works at: https://github.com/rovo89/XposedBridge/tree/art/app/src/main/java/de/robv/android/xposed

Since the code behavior can be altered in various degrees depending on what mods are installed via the xposed framework, I cannot pinpoint the exact cause of your exception. However, if all the stack traces you have got start with the XposedBrigde.main(), then I can say that your problem is due to the exposed framework or the mods installed via the framework.

Jiyong Park
  • 664
  • 3
  • 6
  • I have found a few other reports that don't involve XPosed, however I think you might have gotten close to the issue. Every single report I have seen involves a rooted phone. – casolorz Mar 01 '16 at 15:33