Moh*_*tif 24 java x86 android android-studio
这似乎是Stack Overflow中提出的最高问题之一,但即使在尝试了10多个问题的20多个解决方案并引用Android Docs之后,我的问题仍未解决.
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
Run Code Online (Sandbox Code Playgroud)
问题
1.应用程序在非x86设备上运行良好,如摩托罗拉,三星S6,三星S7
2.应用程序在x86架构设备上抛出该错误.
我到目前为止尝试过的内容
1.我在Manifest,包等中交叉检查包名称
.2.将完整和部分包名称提供给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.CompileSDKVersion -
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(app)的一部分
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/')
}
}
Run Code Online (Sandbox Code Playgroud)
PS交叉检查了Manifest几次,似乎没有问题.在任何Android文档中都找不到任何可能的异常原因.
更新:在参考此答案后启用即时运行不会导致问题.但是通过安装应用程序debug.apk会产生同样的问题.
将jack-compiler和MultiDex一起使用时,这是一个已知问题.这导致NoClassDefFoundErrorPre-Lollipop设备,也可能在Pre-Marshmallow上.解决方案是禁用jack-compiler,然后使用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
}
}
}
Run Code Online (Sandbox Code Playgroud)
不要忘记向Thomas Sunderland提出他的回答,因为这就是我找到这个解决方案的方式.
此错误的原因之一是由于 MultiDexApplication 。我在其他一些库中遇到过此类问题
要解决这个问题,您需要处理多个 Dex 文件。在应用程序的帮助下build.gradle&Application class
build.gradle以下是文件中所需的更改
dexOptions {
incremental true
// here heap size give 4g(for ubuntu you can try with 2g) i got this thing from //https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY
javaMaxHeapSize "4g"
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
// your dependencies which you are using.
}
Run Code Online (Sandbox Code Playgroud)
全部的build.gradle
android {
signingConfigs {
/*
releasebuild {
keyAlias 'hellotest'
keyPassword 'hellotest'
storeFile file('path to keystore')
storePassword 'hellotest'
}
*/
}
compileSdkVersion 'Google Inc.:Google APIs:22'
buildToolsVersion '23.0.0'
/* if you got error regarding duplicate file of META-INF/LICENSE.txt from jar file
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
*/
dexOptions {
jumboMode = true
incremental true
// here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY
javaMaxHeapSize "4g"
}
defaultConfig {
multiDexEnabled true
applicationId "com.myapp.packagenme"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releasebuild
}
debug {
signingConfig signingConfigs.releasebuild
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
// your dependencies which you are using.
}
Run Code Online (Sandbox Code Playgroud)
如果您的应用程序使用扩展的Application类,您可以重写attachBaseContext()方法并调用MultiDex.install(this)来启用multidex。使用应扩展的 Applicaiton 类 安装 Multipledex 文件上下文
public class MyAppClass extends MultiDexApplication{
@Override
protected void attachBaseContext(Context newBase) {
MultiDex.install(newBase);
super.attachBaseContext(newBase);
}
}
Run Code Online (Sandbox Code Playgroud)
javaMaxHeapSize "4g" 尝试使用2gif 以防 ubuntu 系统出现任何错误。
如果有什么事情请告诉我
| 归档时间: |
|
| 查看次数: |
9419 次 |
| 最近记录: |