tmurakami / dexopener

An Android library that provides the ability to mock your final classes on Android devices.
Apache License 2.0
113 stars 4 forks source link

java.lang.ClassNotFoundException thrown when using multidex #11

Closed shymmq closed 7 years ago

shymmq commented 7 years ago

I'm using api 26, with multidex enabled. My gradle.build for app:

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.wabadaba.dziennik"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 5
        versionName "0.4"
        flavorDimensions "versionCode"
        testInstrumentationRunner 'com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner'
        multiDexEnabled true
        testBuildType 'debug'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
            multiDexKeepFile file('multidex-config.txt')
        }
    }
}
dependencies{
    androidTestImplementation 'com.github.tmurakami:dexopener:0.11.0'
}

I already added a multidex-config.txt file in the same directory:

com/wabadaba/dziennik/BuildConfig.class

Full logcat output:

I: Not late-enabling -Xcheck:jni (already on)
W: Unexpected CPU variant for X86 using defaults: x86
W: Zip open failed: Failure to verify dex file '/data/app/com.wabadaba.dziennik.test-mpAczVGBtCHcMZ9NDzO8OQ==/base.apk:classes2.dex': Invalid field name: 'Verify no further interactions'
W: ClassLoader referenced unknown path: 
D: Shutting down VM
E: FATAL EXCEPTION: main
   Process: com.wabadaba.dziennik, PID: 18879
   java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.wabadaba.dziennik.test/com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner}: java.lang.ClassNotFoundException: Didn't find class "com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system/vendor/lib]]
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5730)
       at android.app.ActivityThread.-wrap1(Unknown Source:0)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6541)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.github.tmurakami.dexopener.DexOpenerAndroidJUnitRunner" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system/vendor/lib]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5728)
       at android.app.ActivityThread.-wrap1(Unknown Source:0) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 
       at android.os.Handler.dispatchMessage(Handler.java:105) 
       at android.os.Looper.loop(Looper.java:164) 
       at android.app.ActivityThread.main(ActivityThread.java:6541) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

Could this be related to #9 ?

tmurakami commented 7 years ago

Does the same error occur if you set android.support.test.runner.AndroidJUnitRunner as the default test instrumentation runner?

android {
    defaultConfig {
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
}
shymmq commented 7 years ago

This time I'm getting

java.lang.ClassNotFoundException: Didn't find class "android.support.test.runner.AndroidJUnitRunner" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64]]
tmurakami commented 7 years ago

Thank you for your reporting.

If it were a DexOpener issue, AndroidJUnitRunner would be loaded. However, since the same error occurred, I think that this is not a DexOpener issue.

tmurakami commented 7 years ago

@shymmq I looked into your project and probably identified the cause.

Kluent does not support Android. You should use kluent-android instead.

dependencies {
    androidTestImplementation "org.amshove.kluent:kluent-android:$kluent_version"
}

See the changelog.

shymmq commented 7 years ago

Thank you, that was the problem. Everything is working now.