test ending with error in my project - android

My test Class:
#RunWith(AndroidJUnit4.class)
#LargeTest
public class LoginActivityTest4 {
#Rule
public ActivityTestRule<LoginActivity> mActivityRule =
new ActivityTestRule(LoginActivity.class);
#Test
public void testContainsIntialViews() {
onView(withId(R.id.Mot_de_passe)).check(matches(isDisplayed()));
onView(withId(R.id.Identifiant)).check(matches(isDisplayed()));
onView(withId(R.id.button_connexion)).check(matches(isClickable()));
}
}
my error
java.lang.ClassNotFoundException:
com.macuverie.mobile.vue.activity.LoginActivityTest4
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at android.support.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:72)
at android.support.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:539)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:382)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.macuverie.mobile.vue.activity.LoginActivityTest4" on path:
DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file
"/data/app/com.macuverie.mobile.test-2/base.apk", zip file
"/data/app/com.macuverie.mobile-1/base.apk"],nativeLibraryDirectories=
[/data/app/com.macuverie.mobile.test-2/lib/x86,
/data/app/com.macuverie.mobile-1/lib/x86, /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)
... 8 more
Tests ran to completion.
my package for test :
It is the first time which I test under android so about one wants to explain me what I had of the evil or what I forgot please help me..

Are you using any third-party plugin? In my case I was using android-aspectjx and for obscure reasons it leveraged my test runs. Removing the line below from my build.gradle file helped :
apply plugin: 'android-aspectjx'
I would suggest you to check if you have any third-party plugins that could influence your issue and removing them one by one to see if one of them is the culprit.

Related

Mockito not working in instrumentation test

I am getting error when I use mockito in instrumentation.
This is the library I am using:
def mockitoVersion = "3.10.0"
androidTestImplementation "org.mockito:mockito-android:$mockitoVersion"
I have added a file resources/mockito-extensions/org.mockito.plugins.MockMaker which contains mock-maker-inline
and when I try to mock any object
This is a sample class to mock:
open class TestFile {
val hit=12
}
Here we are mocking:
class InsTest {
#Mock
lateinit var testFile: TestFile
#Before
fun init(){
MockitoAnnotations.initMocks(this)
}
#Test
fun shouldCallMockedListener(){
assertTrue(testFile.hit==0)
}
}
Also tried this one, but same error returned:
val testFile = Mockito.mock(TestFile::class.java)
I got 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:84)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy4.isTypeMockable(Unknown Source)
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:33)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:250)
at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:232)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:83)
at org.mockito.Mockito.mock(Mockito.java:1954)
at org.mockito.Mockito.mock(Mockito.java:1865)
at com.example.mytestlab.InsTest.shouldCallMockedListener(InsTest.kt:24)
... 26 trimmed
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration#13cf6d2
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:57)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:65)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:26)
at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:20)
at org.mockito.internal.configuration.plugins.Plugins.getMockMaker(Plugins.java:36)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:28)
... 35 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:52)
... 41 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker.
It appears as if you are trying to run this mock maker on Android which does not support the instrumentation API.
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:
https://search.maven.org/artifact/org.mockito/mockito-android
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 : 5.10.66-android12-9-00041-gfa9c9074531e-ab7914766
at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<init>(InlineDelegateByteBuddyMockMaker.java:246)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:25)
... 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:1302)
at net.bytebuddy.agent.ByteBuddyAgent$ProcessProvider$ForCurrentVm.resolve(ByteBuddyAgent.java:1285)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:586)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:538)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:515)
at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<clinit>(InlineDelegateByteBuddyMockMaker.java:117)
... 45 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 "/system/framework/android.test.base.jar", zip file "/data/app/~~SX1N6uxVq4_7KPEsETMR6A==/com.example.mytestlab.test-bjBXAf871pg19Xz-kKuSPQ==/base.apk", zip file "/data/app/~~faUk2vI3EdLKP3K8V1Py2Q==/com.example.mytestlab-2M3Ni-tFODEFqqY2eXcDMA==/base.apk"],nativeLibraryDirectories=[/data/app/~~SX1N6uxVq4_7KPEsETMR6A==/com.example.mytestlab.test-bjBXAf871pg19Xz-kKuSPQ==/lib/arm64, /data/app/~~faUk2vI3EdLKP3K8V1Py2Q==/com.example.mytestlab-2M3Ni-tFODEFqqY2eXcDMA==/lib/arm64, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 51 more
Any suggestion to resolve this issue?

java.lang.NoClassDefFoundError for an aar library

I followed the official instructions to Add an AAR as a dependency.
The build.gradle of the app has:
implementation files('libs/androidLibrary-release.aar')
The app builds and starts fine. However, it crashes when it uses a method of the library with the following in the logcat:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/joda/time/DateTime;
at net.mydomain.android.utility.getCurrentTime(SourceFile:1)
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.joda.time.DateTime" on path: DexPathList[[zip file "/data/app/com.mydomain.foo-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
...
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Method getCurrentTime() uses joda-time. The library has the following in its build.gradle:
implementation 'joda-time:joda-time:2.10.5'
I also tried api as follows to no avail:
api 'joda-time:joda-time:2.10.5'
Could anyone offer a tip to help find the culprit?
I used to import aar libraries as modules and they worked flawlessly. I have just updated Android Studio to Arctic Fox and the option to import an aar library is no longer available.

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.

Unable to get provider - rarely crash on kitkat

Few times in the week i receive crash report in GP console:
java.lang.RuntimeException: Unable to get provider mypackage.MyProvider: java.lang.ClassNotFoundException: Didn't find class "mypackage.MyProvider" on path: DexPathList[[zip file "/mnt/asec/mypackage-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/mypackage-1/lib, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5018)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4589)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.ClassNotFoundException: Didn't find class "mypackage.MyProvider" on path: DexPathList[[zip file "/mnt/asec/mypackage-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/mypackage-1/lib, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:5003)
... 12 more
Suppressed: java.io.IOException: unable to open DEX file
at dalvik.system.DexFile.openDexFileNative(DexFile.java)
at dalvik.system.DexFile.openDexFile(DexFile.java:296)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexFile.<init>(DexFile.java:59)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:263)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
at dalvik.system.DexPathList.<init>(DexPathList.java:112)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:57)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:326)
at android.app.LoadedApk.makeApplication(LoadedApk.java:508)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4514)
... 10 more
Also, after adding Firebase features to my project i start to receive same crash reports about com.google.firebase.provider.FirebaseInitProvider.
According to reports, this errors happens only on:
Android 4.4 98,7 %
Android 4.2 1,3 %
I've try all this ClassNotFoundException for a ContentProvider, but no result.
Is this really a system bug and every developer deals with it, or it's my error? I really want to stop annoying users. Thanks.
Your case really looks like bug described there in Android's Issue Tracker.
There you got issue when user starting app immediately after apk update.
There is workaround from comments which could help you to prevent this bug:
public class DevToolsApplication extends Application {
private static final String TAG = "DevToolsApplication";
#Override
public void onCreate() {
super.onCreate();
AppLogger.i(TAG, "app start...");
checkAppReplacingState();
}
private void checkAppReplacingState() {
if (getResources() == null) {
AppLogger.w(TAG, "app is replacing...kill");
Process.killProcess(Process.myPid());
}
}
}

Duplicated Play Store app fails to instantiate

Compiled an APK and tested it successfully on my device, tried it through the Google Play Store and it stops working immediately. This app is a copy of an existing app, since you cannot have the same package name twice I simply renamed the package name in the AndroidManifest.xml, compiled it, tested it and then uploaded it to the Play Store.
I do not understand why the app works when I copy it to a device but the same app fails when loaded through the Play Store. I generated a crash report which I accessed from the Play Store Developer Console. If anyone has experience of successfully duplicating apps on the Store then your help would be appreciated.
java.lang.RuntimeException: Unable to instantiate application de.schildbach.wallet.artbyte.WalletApplication: java.lang.ClassNotFoundException: Didn't find class "de.schildbach.wallet.artbyte.WalletApplication" on path: DexPathList[[zip file "/data/app/de.schildbach.wallet.artbyte-1/base.apk"],nativeLibraryDirectories=[/data/app/de.schildbach.wallet.artbyte-1/lib/arm, /data/app/de.schildbach.wallet.artbyte-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:680)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6395)
at android.app.ActivityThread.access$1800(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "de.schildbach.wallet.artbyte.WalletApplication" on path: DexPathList[[zip file "/data/app/de.schildbach.wallet.artbyte-1/base.apk"],nativeLibraryDirectories=[/data/app/de.schildbach.wallet.artbyte-1/lib/arm, /data/app/de.schildbach.wallet.artbyte-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
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:1005)
at android.app.LoadedApk.makeApplication(LoadedApk.java:670)
... 9 more
Suppressed: java.lang.ClassNotFoundException: de.schildbach.wallet.artbyte.WalletApplication
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)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
The Exception says that build is failed due to class not found on dex path list. Build the apk by cleaning the project and also recompile the native code using the ndk-build command. Then try it on the local device and then upload to play store.
The package name in AndroidManifest.xml is often also used for the code base, e.g. as class name of the activities. If you only rename the package name but leave the Java/dex code unchanged Android will not be able to find some classes as you already have noticed.
Check the AndroidManifest.xml for package relative class names (those that start with a .) and prepend the old package name:
Example
Old package name: org.example.myapp
Old activity name: <activity android:name=".MyActivity" ..>
New package name: com.example.newappname
New activity name: <activity android:name="org.example.myapp.MyActivity" ..>

Categories

Resources