Firebase compatibility errors - android

I have a problem that I always had, and tried to understand it, but never succesfully. The compatibility between firebase implementations. I take the repositories from https://mvnrepository.com/artifact/com.google.firebase , but it doesn't help me. I event put apply plugin: 'com.google.gms.google-services' at the end of build.gradle, such in dependecies.
My implementations are:
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.google.firebase:firebase-firestore:18.1.0'
implementation 'com.google.firebase:firebase-storage:16.1.0'
It works very well without last one (storage) but I needed that, and when I put it there, i get some errors. If someone can explain why it works well with some versions, and with some not, I would apreciate that.
The error i get is:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListenersCountChangedListener;
at com.google.firebase.auth.zzp.create(Unknown Source:3)
at com.google.firebase.components.ComponentRuntime.lambda$new$0(com.google.firebase:firebase-common##17.0.0:66)
at com.google.firebase.components.ComponentRuntime$$Lambda$1.get(Unknown Source:4)
at com.google.firebase.components.Lazy.get(com.google.firebase:firebase-common##17.0.0:53)
at com.google.firebase.components.ComponentRuntime.initializeEagerComponents(com.google.firebase:firebase-common##17.0.0:155)
at com.google.firebase.FirebaseApp.initializeAllApis(com.google.firebase:firebase-common##17.0.0:642)
at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common##17.0.0:358)
at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common##17.0.0:321)
at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common##17.0.0:305)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common##17.0.0:53)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1917)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1892)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common##17.0.0:47)
at android.app.ActivityThread.installProvider(ActivityThread.java:6391)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5938)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5853)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp$IdTokenListenersCountChangedListener" on path: DexPathList[[zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/base.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_resources_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.ainkiwi.taskme-gQJ3Y9hPNu2sUu1YIJxWBA==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134).... and so on.

Upgrade the following dependencies into this:
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.google.firebase:firebase-firestore:19.0.0'
implementation 'com.google.firebase:firebase-storage:17.0.0'
Check the list of dependencies here:
https://firebase.google.com/support/release-notes/android#latest_sdk_versions

Related

Resource linking fails on lStar with error

I'm working on a android Native application. My Android builds began to fail without any changes.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':etndoorcontrol:processHesuan_faceDebugResources'.
> Android resource linking failed
C:\Users\xqf\.gradle\caches\transforms-2\files-2.1\fe7b90aa462d9a2e04dd8216aa450a51\res\values\values.xml:2422:5-2449:25: AAPT: error: resource android:attr/lStar not found.
error: failed linking references.
Then I tried 2 solutions
//soultion 1.
configurations.all {
resolutionStrategy {
// Java language implementation
force "androidx.core:core:1.6.0"
// Kotlin
force "androidx.core:core-ktx:1.6.0"
}
}
After I add this to app/build.gradle, the app can build correct.but after I install the apk and run .there is a new problem.
java stacktrace:
java.lang.NoClassDefFoundError: androidx.appcompat.widget.Toolbar
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:2551)
at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:169)
at java.lang.reflect.Method.getParameterTypes(Method.java:193)
at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:163)
at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingInfo(SubscriberMethodFinder.java:88)
at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:64)
at org.greenrobot.eventbus.EventBus.register(EventBus.java:140)
at com.yarward.a10doorcontrol.homepage.HomePageActivity.initFields(HomePageActivity.java:334)
at com.yarward.base.mvp.view.BaseActivity.onCreate(BaseActivity.java:82)
at com.yarward.a10doorcontrol.homepage.HomePageActivity.onCreate(HomePageActivity.java:257)
at android.app.Activity.performCreate(Activity.java:6709)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2628)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2736)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1487)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6157)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
Caused by: java.lang.ClassNotFoundException: androidx.appcompat.widget.Toolbar
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
... 22 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/MenuHost;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
at java.lang.Class.getDexCacheType(Class.java:2551)
at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:169)
at java.lang.reflect.Method.getParameterTypes(Method.java:193)
at java.lang.Class.getDeclaredMethods(Class.java:1812)
at org.greenrobot.eventbus.SubscriberMethodFinder.findUsingReflectionInSingleClass(SubscriberMethodFinder.java:154)
... 18 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.MenuHost" on path: DexPathList[[zip file "/data/app/com.yarward.hesuanface-1/base.apk"],nativeLibraryDirectories=[/data/app/com.yarward.hesuanface-1/lib/arm, /data/app/com.yarward.hesuanface-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 28 more
After this, I tried the other solution, as below:
ext{
androidX = 1.6.0
}
but this is not working for me.
axel8888 thank your sir, yes, I have solved this problem. yes, you are right , when I try solution one again
configurations.all {
resolutionStrategy {
// Java language implementation
force "androidx.core:core:1.6.0"
// Kotlin
force "androidx.core:core-ktx:1.6.0"
}
}
and as you the problem is now in
androidx.appcompat:appcompat:1.4.0-alpha
so I checked the gradle dependencies, yes , even I used
androidx.appcompat:appcompat:1.3.1
but my project shows the version is 1.4.0-alpha. here is my solution
configurations.all {
resolutionStrategy.eachDependency { details ->
def requested = details.requested
if (requested.group == "androidx.appcompat") {
if (requested.name == "appcompat") {
details.useVersion "1.3.1"
}
}
}
}
and it worked, now my project can build and run correctly, thank you, sir!
Obveiously the problem is now in androidx.appcompat:appcompat:1.4.0-alpha. If your UI use Toolbar, you will get the MenuHost not found crash.BUT, evenif I use resolutionStrategy to force 'androidx.appcompat:appcompat:1.3.1', dependency still make it toandroidx.appcompat:appcompat:{strictly 1.4.0-beta01}
It still confuse me a lot.
SOLVED -- someone write a update code for appcompat before... now it can force to 1.3.1 and solve the problem
change
implementation 'androidx.appcompat:appcompat:1.4.0'
to
implementation 'androidx.appcompat:appcompat:1.3.1'
that's it
implementation 'androidx.appcompat:appcompat:1.4.1'
was causing the problem, going back to 1.3.1 worked.
implementation 'androidx.appcompat:appcompat:1.3.1'
ill update once I get an official solution.

RuntimeException: Unable to instantiate application com.company.app.Application: ClassNotFoundException

I've read a few answers on this site with the same or similar error messages, and I've tried all the solutions already. Sadly, none of them have worked so far.
My gradle files all look like they're properly set up for Multidex, the Application class extends MultiDexApplication and is referenced correctly in the manifest, I've cleaned all caches and restarted the IDE, deleting builds from the project and the device and re-building/re-installing, etc. etc.
Inspecting the APK, I found the Application in classes2.dex, correctly referencing .super Landroidx/multidex/MultiDexApplication;
The stack I'm getting is like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.<REDACTED>, PID: 25475
java.lang.RuntimeException: Unable to instantiate application com.<REDACTED>.Application: java.lang.ClassNotFoundException: Didn't find class "com.<REDACTED>.Application" on path: DexPathList[[zip file "/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk"],nativeLibraryDirectories=[/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1306)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7401)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7374)
at android.app.ActivityThread.access$1500(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.<REDACTED>.Application" on path: DexPathList[[zip file "/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk"],nativeLibraryDirectories=[/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1298)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7401) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7374) 
at android.app.ActivityThread.access$1500(ActivityThread.java:301) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:246) 
at android.app.ActivityThread.main(ActivityThread.java:8425) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 
Suppressed: java.io.IOException: Failed to open dex files from /data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk because: Failure to verify dex file '/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk': Bad index for method_handle_item method_idx: ffff >= de57
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:367)
at dalvik.system.DexFile.<init>(DexFile.java:109)
at dalvik.system.DexFile.<init>(DexFile.java:82)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:439)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:398)
at dalvik.system.DexPathList.<init>(DexPathList.java:166)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:129)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:104)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:933)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:990)
at android.app.LoadedApk.getResources(LoadedApk.java:1234)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2788)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2780)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7263)
... 8 more
Can anyone figure out what this is all about?
In the module level build.gradle, we added these lines:
// Near the top
apply plugin: 'com.google.firebase.crashlytics'
// ...
android {
// ...
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
// ...
}
// ...
I have no idea how this fixed this crash, but I suppose that's what I get for using "It just works" libraries.

Android java.lang.ClassNotFoundException: Didn't find class

I'm a total Android newbie here, so hopefully someone can help me out.
I have an Android library (myLib.aar) that I am including/using in the HelloAR demo app.
Now, I want to use Instacapture within myLib.aar. I followed the instructions on the README:
dependencies {
...
compile "com.github.tarek360:instacapture:2.0.1"
}
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
I also tried downloading, compiling instacapture source, adding the instacapture.aar to my libs dir and modifying my Gradle files:
dependencies{
...
implementation(name:'instacapture', ext:'aar')
}
allprojects {
repositories {
...
flatDir {
dirs 'libs'
}
}
In both cases, I get the following exception:
--------- beginning of crash
2020-08-11 22:34:35.965 32761-32761/com.google.ar.core.examples.java.helloar E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.ar.core.examples.java.helloar, PID: 32761
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/tarek360/instacapture/Instacapture;
at com.cambridge.myLib.ScreenShotter.takeScreenshot(ScreenShotter.java:139)
at com.google.ar.core.examples.java.helloar.HelloArActivity$2.run(HelloArActivity.java:164)
at com.google.ar.core.examples.java.helloar.HelloArActivity.startRepeatingTask(HelloArActivity.java:171)
at com.google.ar.core.examples.java.helloar.HelloArActivity$1.run(HelloArActivity.java:152)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.tarek360.instacapture.Instacapture" on path: DexPathList[[zip file "/data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/base.apk"],nativeLibraryDirectories=[/data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/lib/arm64, /data/app/com.google.ar.core.examples.java.helloar-bhCcJ--GEjsJ6mxAFvnUYw==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.cambridge.myLib.ScreenShotter.takeScreenshot(ScreenShotter.java:139)
at com.google.ar.core.examples.java.helloar.HelloArActivity$2.run(HelloArActivity.java:164)
at com.google.ar.core.examples.java.helloar.HelloArActivity.startRepeatingTask(HelloArActivity.java:171)
at com.google.ar.core.examples.java.helloar.HelloArActivity$1.run(HelloArActivity.java:152)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
However, if I add the dependencies to the main HelloAR app (as per the instructions in the README), the issue resolves.
Can someone please explain what is going on, why I'm getting the error, and how to resolve it without having to add the dependencies to the main HelloAR app?
Considering your quote,
I'm a total Android newbie here, so hopefully someone can help me out.
Follow these steps (in android studio) :
Go to build menu.
Clean the project by clicking on clean project.
Build the project by clicking on make project.
This process is known as clean build which is usually done after adding some dependencies.

Mockito 2 for Android Instrumentation test : Could not initialize plugin: interface org.mockito.plugins.MockMaker

I'm using Mockito 2 and Espresso for Unit tests, and met a problem trying to use Mockito 2 in Instrumentation test. While running the test, I'm getting this error
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:74)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy5.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:232)
at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:226)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:64)
at org.mockito.Mockito.mock(Mockito.java:1864)
at org.mockito.Mockito.mock(Mockito.java:1777)
at com.armop.insight.views.activity.InsightActivityTest.testUserResultReturnsEmpty(InsightActivityTest.kt:66)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:369)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration#5ea25e5
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:54)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:21)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:18)
at org.mockito.internal.configuration.plugins.Plugins.getMockMaker(Plugins.java:34)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:24)
... 38 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
IMPORTANT INFORMATION FOR ANDROID USERS:
The regular Byte Buddy mock makers cannot generate code on an Android VM!
To resolve this, please use the 'mockito-android' dependency for your application:
http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22mockito-android%22%20g%3A%22org.mockito%22
Java : 0.9
JVM vendor name : The Android Project
JVM vendor version : 2.1.0
JVM name : Dalvik
JVM version : 0.9
JVM info : null
OS name : Linux
OS version : 3.18.91+
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:171)
at java.lang.Class.newInstance(Native Method)
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:49)
... 44 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;
at net.bytebuddy.agent.ByteBuddyAgent$ProcessProvider$ForCurrentVm$ForLegacyVm.resolve(ByteBuddyAgent.java:940)
at net.bytebuddy.agent.ByteBuddyAgent$ProcessProvider$ForCurrentVm.resolve(ByteBuddyAgent.java:925)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:352)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:320)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:306)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<clinit>(InlineByteBuddyMockMaker.java:101)
... 46 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.management.ManagementFactory" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.armop.debug.test-GWx-9OMGi9FTj01c1acroQ==/base.apk", zip file "/data/app/com.armop.debug-28ywc-fJ-zzWAgMPBESlGQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.armop.debug.test-GWx-9OMGi9FTj01c1acroQ==/lib/x86, /data/app/com.armop.debug-28ywc-fJ-zzWAgMPBESlGQ==/lib/x86, /data/app/com.armop.debug.test-GWx-9OMGi9FTj01c1acroQ==/base.apk!/lib/x86, /data/app/com.armop.debug-28ywc-fJ-zzWAgMPBESlGQ==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 52 more
And here is the test code.
#Test
fun testUserResultReturnsEmpty() {
val userMock = Mockito.mock(UserModel::class.java)
Mockito.`when`(ArmOpApplication.getUserFromPrefs()).thenReturn(userMock)
mActivityRule.launchActivity(Intent())
mCountDownLatch.await(3000, TimeUnit.MILLISECONDS)
assertNotNull(mActivityRule.activity.mInsightCategories)
assertNull(mActivityRule.activity.mData)
assertNull(mActivityRule.activity.insightsRecyclerView.adapter)
}
I've googled for more information and found out, that I need to use mockito-android instead of mockito core, and added those lines in application's build.gradle file
androidTestImplementation "org.mockito:mockito-android:${libMockitoAndroidVersion}"
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
where libMockitoAndroidVersion = 2.16.0
Also, I've added org.mockito.plugins.MockMaker file into the androidTest resource directory to work with Kotlin's classes.
Is there any way to fix this issue? Any help will be appreciated.
Working with Android replace
androidTestImplementation "org.mockito:mockito-core:$mockito_core_version"
androidTestImplementation "org.mockito:mockito-inline:$mockito_core_version"
for
androidTestImplementation "org.mockito:mockito-android:$mockito_core_version"
My version was: $mockito_core_version = '2.28.2'
I was having this issue and none of the solutions here worked for me. My problem was that I was mixing both mockito libraries
//BAD CODE
testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
testImplementation "org.mockito:mockito-android:3.3.3"
//GOOD CODE - just use one
testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
I've got similar problem. I my case that was invalid declaration in resource/mockito-extensions/org.mockito.plugins.MockMaker file. During some refactoring process IDE replaced correct value:
mock-maker-inline
with this one:
infrastructure-maker-inline
I've noticed that accidental change while reviewing the commit diff because it didn't look suspicious for first look.
This helped me
androidTestImplementation("org.koin:koin-test:1.0.2")
{ exclude("org.mockito", "mockito-inline") }
androidTestImplementation("org.mockito:mockito-android:2.24.5")
Koin represents some library that contain org.mockito
In the stacktrace I found this:
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration
Enlighted by this issue(#824 Exception when using mock-maker-inline), I resolved the same problem by adding tools.jar to my classpath in intellij
add tools.jar to classpath
From the stack trace it seems like you are using the inline Byte Buddy mock maker which does not work on Android. Make sure that you have not included it transitively somehow as both plugins being available would load the one that is added to the class path first.
In my case it worked with adding mockito kotlin dependency and i think it would be better to stay away from inline library, because as i read somewhere it is just a dependency to check final class mocking issue solution and later it will be stopped of updating
use these 2 dependencies
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"

Cannot reference activity of library module in application

I'm using Android Studio 2.3.3, with Android Plugin for Gradle 2.3.3.
Please see my sample project, https://github.com/Uni-/AndroidModuleTest. In this project, there are two sample modules (as Android Studio names), app and library.
library has com.example.test.myapplication.MainActivity class, and it's referenced in AndroidManifest.xml of app. The application is compiled well, but it crashes on startup:
10-31 22:20:55.031 30084-30084/? I/zygote64: Late-enabling -Xcheck:jni
10-31 22:20:55.312 30084-30084/? I/InstantRun: starting instant run server: is main process
10-31 22:20:55.325 30084-30084/? D/AndroidRuntime: Shutting down VM
10-31 22:20:55.327 30084-30084/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.test.myapplication, PID: 30084
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test.myapplication/com.example.test.myapplication.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.test.myapplication.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/base.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
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.example.test.myapplication.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/base.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.test.myapplication-dsBQ8b1LFh9WtKzvdfrLYg==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
10-31 22:20:55.328 30084-30084/? E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
... 9 more
10-31 22:21:00.439 30084-30093/com.example.test.myapplication I/zygote64: Waiting for a blocking GC ObjectsAllocated
10-31 22:21:00.537 30084-30093/com.example.test.myapplication I/zygote64: WaitForGcToComplete blocked for 97.913ms for cause ObjectsAllocated
The MainActivity class seems not existing in the application artifact, according to the log.
In fact, build.gradle of app contains these lines:
debugCompile project(path: ':library', configuration: 'debugCompile')
releaseCompile project(path: ':library', configuration: 'releaseCompile')
When I replace these lines by a line below, the error goes fixed:
compile project(':library')
However, this is not what I want. I have various product flavors and custom build types in my real project, so just a compile, or even implementation in 3.0, can't be a solution.
What did I wrong in my sample project?
I fixed this by myself.
The key point is setting publishNonDefault true in build.gradle of library.
Also, the contextual dependencies should be declared as:
debugCompile project(path: ':library', configuration: 'debug')
releaseCompile project(path: ':library', configuration: 'release')
Fixed in 151f6e4. Thanks.
adding in module gradle implementation project(':yourLib') in my case solved the problem

Categories

Resources