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.IncompatibleClassChangeError on Android 5.0-6.0 #17

Open mik9 opened 6 years ago

mik9 commented 6 years ago

Exception message in runtime:

Class 'ua.pl.mik.app.DaggerAppComponent$SomeLongNameBuilder' does not implement interface 'ua.pl.mik.app.net.ApiComponent$Builder' in call to 'ua.pl.mik.app.net.ApiComponent ua.pl.mik.app.net.ApiComponent$Builder.build()

Class names was changed a bit. On Android 7.0+ same apks (main + androidTest) working fine.

tmurakami commented 6 years ago

If you have a custom AndroidJUnitRunner, please make sure that the class literal of your Application class is not used on AndroidJUnitRunner#newApplication.

It would be helpful if you can share a minimal project that can reproduce this issue.

mik9 commented 6 years ago

My newApplication method looks like next (TestApp class that extends App class from main module):

    @Override
    public Application newApplication(ClassLoader cl, String className, Context context) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        DexOpener.builder(context)
                .buildConfig(BuildConfig.class)
                .build()
                .installTo(cl);
        return super.newApplication(cl, TestApp.class.getName(), context);
    }

I will try to setup simple project with this issue.

tmurakami commented 6 years ago

Don't call TestApp.class.getName() on newApplication(). Instead, use a string literal of the Application class name.

return super.newApplication(cl, "your.app.test.TestApp", context);
mik9 commented 6 years ago

Tried using raw string: still same exception.

Currently can't identify what of my code cause this to setup minimal project... The only thing I see that: this classes was generated by Dagger (subcomponent builders).

mik9 commented 6 years ago

Also I use multidex for debug builds, but as I see, all this classes in exception located in a single dex...

RocketRider commented 6 years ago

Just found the corresponding issue in the google bug tracker, if anyone is interested. https://issuetracker.google.com/issues/75295983