Gradle connectedCheck fails with 'No tests found' after migrating to AndroidX - android

I'm working on a multi-module project, and after making the transition from the support libraries to AndroidX, ./gradlew connectedCheck fails:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':MyProject:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/justinpollard/Dev/android-app/MyProject/build/reports/androidTests/connected/index.html
A bit further up, I see this message:
11:48:13 I/RemoteAndroidTest: Running am instrument -w -r com.myproject.test/androidx.test.runner.AndroidJUnitRunner on Pixel XL - 9
11:48:13 V/ddms: execute: running am instrument -w -r com.myproject.test/androidx.test.runner.AndroidJUnitRunner
11:48:15 V/InstrumentationResultParser: INSTRUMENTATION_RESULT: shortMsg=Process crashed.
11:48:15 I/InstrumentationResultParser: test run failed: 'Instrumentation run failed due to 'Process crashed.''
Starting 0 tests on Pixel XL - 9
Tests on Pixel XL - 9 failed: Instrumentation run failed due to 'Process crashed.'
11:48:15 I/XmlResultReporter: XML test result file generated at /Users/justinpollard/Dev/android-app/MyProject/build/outputs/androidTest-results/connected/TEST-Pixel XL - 9-MyProject-.xml. Total tests 0,
11:48:15 V/InstrumentationResultParser: INSTRUMENTATION_CODE: 0
11:48:15 V/InstrumentationResultParser:
11:48:15 V/ddms: execute 'am instrument -w -r com.myproject.test/androidx.test.runner.AndroidJUnitRunner' on 'HT73Y0200438' : EOF hit. Read: -1
11:48:15 V/ddms: execute: returning
com.android.builder.testing.ConnectedDevice > No tests found.[Pixel XL - 9] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack #Test annotations).
This makes it seem like the failure is caused by a test apk crash before the tests can run. When I run one of my connected tests from Android Studio, I see a little more information:
2019-05-13 11:55:55.927 29839-29839/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myproject, PID: 29839
java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.myproject.test/androidx.test.runner.AndroidJUnitRunner}: java.lang.ClassNotFoundException: Didn't find class "androidx.test.runner.AndroidJUnitRunner" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.myproject.test-2MzWVeeaNLfexBOU_5tLPw==/base.apk", zip file "/data/app/com.myproject-Hd0c3YX8pUlOxZVK3mlgMA==/base.apk"],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5855)
at android.app.ActivityThread.access$1100(ActivityThread.java:200)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
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 "androidx.test.runner.AndroidJUnitRunner" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.myproject.test-2MzWVeeaNLfexBOU_5tLPw==/base.apk", zip file "/data/app/com.myproject-Hd0c3YX8pUlOxZVK3mlgMA==/base.apk"],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5851)
at android.app.ActivityThread.access$1100(ActivityThread.java:200) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6718) 
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) 
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/runner/MonitoringInstrumentation;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 10 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.test.runner.MonitoringInstrumentation" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/com.myproject.test-2MzWVeeaNLfexBOU_5tLPw==/base.apk", zip file "/data/app/com.myproject-Hd0c3YX8pUlOxZVK3mlgMA==/base.apk"],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 13 more
It's surprising to me that AndroidJUnitRunner and MonitoringInstrumentation are not found on the path since I include androidx.text:runner in the app-level build.gradle dependencies:
dependencies {
...
androidTestImplementation(
"androidx.test.ext:junit:1.1.0",
"androidx.test:rules:1.1.0",
"androidx.test:runner:1.1.0",
"androidx.test.espresso:espresso-core:3.1.0",
)
...
}
I've also made sure I'm following the instructions listed here at https://developer.android.com/training/testing/set-up-project:
1) My project build.gradle includes the google() repository (the instructions do say to include this in the app-level build.gradle, but I'm assuming that's incorrect given allprojects exists in the project-level build.gradle?)
2) I've got my dependencies listed in the app-level dependencies.androidTestImplementation (see above)
3) Add useLibrary 'android.test.runner' to the android section of my app build.gradle
4) Add <uses-library android:name="android.test.runner" android:required="false" /> to the app's AndroidManifest.xml (the instructions make it seem like this may not be required since I'm using gradle to run the tests)
For reference, without including an entire test, here's an illustrative example of my setup:
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.ext.junit.runners.AndroidJUnit4;
#RunWith(AndroidJUnit4.class)
public class ExampleTest {
#Before
public void setUp() throws Exception {
// Setup here
}
#After
public void tearDown() {
// Tear down here
}
#Test
public void testExample() {
// Test code here
}
...
}
Can anyone help me get these tests up and running again? Thanks!

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?

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.

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.

adb shell am start giving ClassNotFoundException

I am trying to launch an apk through adb command, soon after installing the apk but i am getting ClassNotFoundException and app is crashing.
My Log :
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sample.test.one/com.sample.test.one.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.sample.test.one.MainActivity" on path: DexPathList[[zip file "/data/app/com.sample.test.one-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sample.test.one-1/lib/arm, /system/lib, /vendor/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2849)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sample.test.one.MainActivity" on path: DexPathList[[zip file "/data/app/com.sample.test.one-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sample.test.one-1/lib/arm, /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)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2839)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6776) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) 
Flow :
adb install test.apk
adb shell am start -n com.sample.test.one/com.sample.test.one.MainActivity
or
adb shell am start -a android.intent.action.Main -n com.sample.test.one/.MainActivity
I am trying above adb shell commands but app is failing to launch but one scenario i have observed, if i will run the code in Android Studio and app gets installed in the device and after that if i will try "adb shell am start" command then it works fine but if i try through "adb install apk" then this command is not working.
I came across this situation once, but after adding MultiDex to my gradle , everything works great.
Step 1
defaultConfig {
minSdkVersion minVersion+
targetSdkVersion targetVersion+
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
Step 2
add gradle
compile 'com.android.support:multidex:1.0.0'
Step 3
Change gradle properties
org.gradle.jvmargs=-Xmx4096m
Please try this trick.
English is not my native language; please excuse typing errors.
Solution:
take a look in your App project file AndroidMainfest.xml , look for the activity contain this
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
in this scope ,remember this activity name property.
use this command
adb shell am start -D -n com.mycompany.moba.lala/com.epicgames.ue4.SplashActivity
replace the com.epicgames.ue4.SplashActivity with the previous name path.

Categories

Resources