I am trying to make an HTTP call to a server to get its HTML contents everything is working fine on other android versions. But in android 6 when the app is calling HTMLunit it crashes.
I know it has to do with something that works on API above 23. but not on the 23.. I tried many things but I sill can't fix it...
Why it's important to run the app on android 6:
A big number of my users is using android 6 and 5
The error:
FATAL EXCEPTION: Thread-9255
Process: bd.maruf.myapplication, PID: 7773
java.lang.NoClassDefFoundError: java.util.function.Supplier
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:476)
at java.lang.reflect.Method.getReturnType(Method.java:183)
at java.lang.Class.getDeclaredMethods(Class.java:678)
at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.process(AbstractJavaScriptConfiguration.java:212)
at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.getClassConfiguration(AbstractJavaScriptConfiguration.java:193)
at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.<init>(AbstractJavaScriptConfiguration.java:67)
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.<init>(JavaScriptConfiguration.java:685)
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(JavaScriptConfiguration.java:701)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.<init>(JavaScriptEngine.java:161)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:326)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:275)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:265)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:257)
at bd.maruf.myapplication.MainActivity.main(MainActivity.kt:32)
at bd.maruf.myapplication.MainActivity.onCreate$lambda$1$lambda$0(MainActivity.kt:22)
at bd.maruf.myapplication.MainActivity.$r8$lambda$VtPJx1mT1BVGpp5vWQWqcx_e4kM(MainActivity.kt)
at bd.maruf.myapplication.MainActivity$$ExternalSyntheticLambda2.run(D8$$SyntheticClass)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.util.function.Supplier" on path: DexPathList[[zip file "/data/app/bd.maruf.myapplication-1/base.apk"],nativeLibraryDirectories=[/data/app/bd.maruf.myapplication-1/lib/arm, /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 libcore.reflect.InternalNames.getClass(InternalNames.java:53)
at java.lang.Class.getDexCacheType(Class.java:476)
at java.lang.reflect.Method.getReturnType(Method.java:183)
at java.lang.Class.getDeclaredMethods(Class.java:678)
at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.process(AbstractJavaScriptConfiguration.java:212)
at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.getClassConfiguration(AbstractJavaScriptConfiguration.java:193)
at com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.<init>(AbstractJavaScriptConfiguration.java:67)
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.<init>(JavaScriptConfiguration.java:685)
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(JavaScriptConfiguration.java:701)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.<init>(JavaScriptEngine.java:161)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:326)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:275)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:265)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:257)
at bd.maruf.myapplication.MainActivity.main(MainActivity.kt:32)
at bd.maruf.myapplication.MainActivity.onCreate$lambda$1$lambda$0(MainActivity.kt:22)
at bd.maruf.myapplication.MainActivity.$r8$lambda$VtPJx1mT1BVGpp5vWQWqcx_e4kM(MainActivity.kt)
at bd.maruf.myapplication.MainActivity$$ExternalSyntheticLambda2.run(D8$$SyntheticClass)
at java.lang.Thread.run(Thread.java:818)
Suppressed: java.lang.ClassNotFoundException: java.util.function.Supplier
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)
... 20 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
2022-11-12 18:11:50.861 7773-7807 Surface bd.maruf.myapplication D Surface::disconnect(this=0xaddb7b00,api=1)
what I have tried :
cleaning and rebuilding that project
adding:
defaultConfig { multiDexEnabled true}
dependencies {implementation 'com.android.support:multidex:1.0.3'
3. deleting .gradel and .idea file
java.util.function.Supplier is documented as "Added in API level 24", hence code requiring it will not work on pre 24 SDK due to class absence.
Will try to solve this in HtmlUnit - check https://github.com/HtmlUnit/htmlunit-android/issues/9 or https://twitter.com/htmlunit for progress.
After some analysis and experiments i decide to not fix this. The js engine (Rhino) uses classes from the java.util.function package. Changing this is not a simple task and there are many other thinks to do.
So sorry, but i like to stay with android 7 as minimum requirement.
Problem
So I integrated Jetpack Compose dependencies in the application module. But the below exception is occurring whenever the app is started/launched. It's failing in the Application class.
Stacktrace:
2021-10-22 11:16:01.079 16281-16281/com.example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 16281
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_8ff85ea/Offline;
at com.example.app.MyApplication.attachBaseContext(MyApplication.java:719)
at android.app.Application.attach(Application.java:361)
at android.app.Instrumentation.newApplication(Instrumentation.java:1159)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1324)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7223)
at android.app.ActivityThread.access$1600(ActivityThread.java:298)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2172)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8248)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_8ff85ea.Offline" on path: DexPathList[[zip file "/data/app/~~MsNoI2GIvO6hDqGPC9BKfw==/com.example-jknI-wJelwi0a-NSFCz0ig==/base.apk"]
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 com.example.app.MyApplication.attachBaseContext(MyApplication.java:719)
at android.app.Application.attach(Application.java:361)
at android.app.Instrumentation.newApplication(Instrumentation.java:1159)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1324)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7223)
at android.app.ActivityThread.access$1600(ActivityThread.java:298)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2172)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8248)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/~~MsNoI2GIvO6hDqGPC9BKfw==/com.example-jknI-wJelwi0a-NSFCz0ig==/split_config.arm64_v8a.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:379)
at dalvik.system.DexFile.<init>(DexFile.java:112)
at dalvik.system.DexFile.<init>(DexFile.java:85)
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:981)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:1038)
at android.app.LoadedApk.getResources(LoadedApk.java:1270)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2750)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2742)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7128)
2021-10-22 11:16:01.080 16281-16281/com.example E/AndroidRuntime: ... 8 more
Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/~~MsNoI2GIvO6hDqGPC9BKfw==/com.example-jknI-wJelwi0a-NSFCz0ig==/split_config.xxhdpi.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:379)
at dalvik.system.DexFile.<init>(DexFile.java:112)
at dalvik.system.DexFile.<init>(DexFile.java:85)
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:981)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:1038)
at android.app.LoadedApk.getResources(LoadedApk.java:1270)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2750)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2742)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7128)
... 8 more
My Setup
IDE: Android Studio Arctic Fox - Stable | Patch 3
Java JDK 11
Kotlin 1.5.30
Jetpack Compose 1.0.3
Android Gradle Plugin 7.0.2
Gradle Wrapper Version 7.0.2
JaCoCo Version 0.8.7
build.gradle:
jacoco {
toolVersion = "0.8.7"
}
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
buildTypes {
debug {
testCoverageEnabled true
}
}
The solution to the issue is very interesting.
Our project has remote submodules which were also using JaCoCo and in the main project we upgraded the Android Gradle Plugin version and not upgraded AGP in remote submodules then this issue was occurring. This is because those submodules also use the JaCoCo plugin.
Once we upgraded all submodules which were using the JaCoCo plugin and updated respective versions in the main application, this issue got resolved.
Earlier we were using AGP 4.2.2 and this issue was coming after upgrading AGP to 7.x.x.
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.
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.
I updated my Android Studio to version 2.0. But I had a problem, I don't know why?
The important error info:
Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.eallcn.rentagent.MyDebugEallApplication
I searched a long time, But I didn't find the right answer
you can see the link
At the same time when I click File->Project structure
It shows this error:
Is there any problem somewhere in the libs? When gradle build the program the libs didn't load completely for current program. Is there any problem with Android Studio version 2.0?
When I use Android studio 1.4.0 to build and run the program. It works fine for me! But when I use the Android Studio 2.0, the problem shows up!
Why? Could you help me, please?
Here is detailed error log:
11-28 11:57:00.489 19890-19890/com.eallcn.rentagent.debug
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.eallcn.rentagent.debug, PID: 19890 java.lang.RuntimeException: Unable to instantiate application
com.android.tools.fd.runtime.BootstrapApplication:
java.lang.IllegalStateException: java.lang.ClassNotFoundException:
com.eallcn.rentagent.MyDebugEallApplication
at android.app.LoadedApk.makeApplication(LoadedApk.java:537) at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4586)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5314)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException:
java.lang.ClassNotFoundException:
com.eallcn.rentagent.MyDebugEallApplication
at
com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:167)
at
com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:179)
at android.app.Application.attach(Application.java:194)
at
android.app.Instrumentation.newApplication(Instrumentation.java:992)
at
android.app.Instrumentation.newApplication(Instrumentation.java:976)
at android.app.LoadedApk.makeApplication(LoadedApk.java:532)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4586)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5314)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException:
com.eallcn.rentagent.MyDebugEallApplication
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at
com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:155)
at
com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:179)
at android.app.Application.attach(Application.java:194)
at
android.app.Instrumentation.newApplication(Instrumentation.java:992)
at
android.app.Instrumentation.newApplication(Instrumentation.java:976)
at android.app.LoadedApk.makeApplication(LoadedApk.java:532)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4586)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5314)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError:
com/eallcn/rentagent/MyDebugEallApplication
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at
com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:155)
at
com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:179)
at android.app.Application.attach(Application.java:194)
at
android.app.Instrumentation.newApplication(Instrumentation.java:992)
at
android.app.Instrumentation.newApplication(Instrumentation.java:976)
at android.app.LoadedApk.makeApplication(LoadedApk.java:532)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4586)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5314)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.eallcn.rentagent.MyDebugEallApplication" on path:
DexPathList[[zip file
"/data/app/com.eallcn.rentagent.debug-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.eallcn.rentagent.debug-1,
/vendor/lib, /system/lib, /data/datalib]]
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 java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at
com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:155)
at
com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:179)
at android.app.Application.attach(Application.java:194)
at
android.app.Instrumentation.newApplication(Instrumentation.java:992)
at
android.app.Instrumentation.newApplication(Instrumentation.java:976)
at android.app.LoadedApk.makeApplication(LoadedApk.java:532)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4586)
at android.app.ActivityThread.access$1800(ActivityThread.java:139)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5314)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
Disable the Instant Run option in Android Studio. Instructions are in the Android Studio Instant Run documentation.
Instant Run tries to do hot swapping of your code; this causes the application class to be moved.
To disable Instant Run Go to File --> Settings--> Build,Execution,Deployment -->Instant Run ---> uncheck "Enable instant run"
I had the same error after trying to use the 2.0.
I solved it by reverting some gradle changes:
1/3:
Changing:
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
By:
classpath 'com.android.tools.build:gradle:1.2.3'
2/3:
Changing:
buildToolsVersion '23.0.2'
By:
buildToolsVersion "21.1.2"
3/3: (in <project folder>/.idea/gradle.xml)
And:
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.8" />
By:
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.4" />
I don't know what line is exactly the origin of the error, but with this three changes it was solved.
Hope that it helps you :)
I had the same error.
I solved it by cleaning the project ( Build > Clean Project )
Just go to Android Studio menu - Build --> Rebuild Project.
I was able to get rid of this error by updating gradle-wrapper.properties to gradle-2.14.1-all, and cleaning/rebuilding the project. Then it ran fine. No other changes were needed (as those suggested in the above answer)...
Changing to
classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
fixed issue
I also got this error with Android 2.0 in stable channel.
What I did?
- I had an older version of the app already installed on the device (which was built using older version of the Studio) which I was trying to replace by running the newer app on device.
I just uninstalled the older version completely before running the new app and the trick worked.
Just for those who want to update classPath with latest gradle plugin version, Where to find latest plugin version?
Check in http://tools.android.com/tech-docs/new-build-system and update your classPath. Latest one at current is
classpath 'com.android.tools.build:gradle:2.0.0'.
Always try to build with latest plugin version.
If you don't want to disable Instant Run, just do a project clean and rerun.
Change classpath 'com.android.tools.build:gradle:2.1.2' to classpath 'com.android.tools.build:gradle:2.1.0' fixes my problem.
I also faced the same problem and i solved it. In my case it was due to a mistake in global class ( Throughout Application context class ) , my mistake was in AndroidManifest.xml i have declared the Application class VolleyHelper as :-
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true" android:name=".VolleyHelper"
android:theme="#style/AppTheme">
but in VolleyHelper.java i don't have a Default constructor . So i added default constructor in VolleyHelper.java ( Application Class ) .
you can also add this into your gradle to prevent making dex on debug
debug {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
In some Android devices with versions before OS 5.0 we get the error message:
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.android.tools.fd.runtime.BootstrapApplication
We must disable "Instant Run".
Go to File > Settings > Built, Execution, Deployment > Instant Run
Then disable the option Enable Instant Run to hot swap code.
I just needed to reboot my device. Tried everything else first unfortunately so wasted hours.
If you are sharing your app then another solution is
go to Android Studio --> Build --> Build APK
A pop up will come with APK generated successfully. Show in Explorer will get you to the generated apk folder.
This error will happen when you add a blank activity with .java file. So to solve this error 1st you have to Build the project again. Then run it. Solved
Thank You.
No need to disable "instant run".
go to project's root using File Explorer
Finish Android Studio(AS)
delete(relocate somewhere) ".gradle" 's folder content
(to clean some cashs and old artifacts)
in res folder clean off all inappropriate files
launch the AS again
in module's build.gradle set buildTypes { debug {minifyEnabled true to false
(that looks like an error was in my proguard file)
Sync, compile and run the app again.
I just update Android Studio to the last version (2.0 Beta 5). It changes itself to classpath 'com.android.tools.build:gradle:2.0.0-beta5' and works like a charm.