- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
这似乎是 Stack Overflow 中提出的最高问题之一,但即使在尝试了 10 多个问题中的 20 多个解决方案并引用了 Android 文档之后,我的问题仍然没有解决。
LogCat:
FATAL EXCEPTION: main
Process: com.some.app, PID: 22838
java.lang.RuntimeException: Unable to instantiate application com.some.app.utils.Application: java.lang.ClassNotFoundException: Didn't find class "com.some.app.utils.Application" on path: DexPathList[[zip file "/data/app/com.some.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.some.app-1/lib/x86_64, /vendor/lib64, /system/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:563)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4526)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.some.app.utils.Application" on path: DexPathList[[zip file "/data/app/com.some.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.some.app-1/lib/x86_64, /vendor/lib64, /system/lib64]]
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:980)
at android.app.LoadedApk.makeApplication(LoadedApk.java:558)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4526)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: com.some.app.utils.Application
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)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
问题
1. 应用在摩托罗拉、三星 S6、三星 S7 等非 x86 设备上运行良好
2. 应用在 x86 架构设备上抛出该错误。
到目前为止我所尝试的
1.我在Manifest、packages等中交叉检查了包名。
2. 将完整和部分包名称赋予 list 中的 android:name
属性。
3. 尝试将 Application
类从 utils
包移动到主包。
背景
1. 安装 Android Studio - sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 lib32bz2-1.0
- 除了 lib32bz2-1.0
一切正常,但到目前为止没有任何问题。 (之前从未尝试在 x86 设备上安装该应用程序)
2.编译SDK版本 - 25
3. BuildToolsVersion - 25.0.0
4. Gradle 版本 - 2.2.2
工作环境
1. Ubuntu 16.04
2.更新了JAVA 8
3.Android Studio 2.2.2
编辑:我认为可能导致问题的部分 gradle(应用程序)
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
robolectric {
java.srcDir file('src/test/java/')
}
}
P.S. cross checked the Manifest several times and seems no issue with that. Couldn't find any possible cause for this anomaly in any Android docs too.
更新:引用 this answer 后启用即时运行不会导致问题。但是通过 debug.apk
安装应用程序会出现同样的问题。
最佳答案
这是 known issue一起使用 jack-compiler 和 MultiDex 时。这会在 Pre-Lollipop 设备上导致 NoClassDefFoundError
,也可能在 Pre-Marshmallow 上。解决方案是禁用千斤顶编译器,并使用 RetroLambda而是。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
repositories {
mavenCentral()
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "your.application.id"
minSdkVersion 16
targetSdkVersion 25
multiDexEnabled true
jackOptions {
enabled false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
别忘了点赞 Thomas Sunderland his answer ,因为这就是我找到此解决方案的方式。
关于java.lang.RuntimeException : Unable to instantiate application : ClassNotFoundException (Only on X86 architecture device),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40546581/
我是一名优秀的程序员,十分优秀!