我的应用程序运行良好,直到最近。然后,我将compileSdk和buildTools更新为25.从那时起,我的应用程序在打开时不知不觉地崩溃了。将minSdkVersion设置为18可以解决问题,但是当我把它放回到21时,就会发生这种情况。 附加堆栈跟踪和gradle文件的一部分
01-25 19:07:59.848 18879-18879/com.vimi.vimichat E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.vimi.vimichat, PID: 18879
java.lang.RuntimeException: Unable to instantiate application com.vimi.vimichat.Common: java.lang.ClassNotFoundException: Didn't find class "com.vimi.vimichat.Common" on path: DexPathList[[zip file "/data/app/com.vimi.vimichat-1/base.apk"],nativeLibraryDirectories=[/data/app/com.vimi.vimichat-1/lib/arm64, /vendor/lib64, /system/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:586)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5041)
at android.app.ActivityThread.access$1500(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5844)
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:1109)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.vimi.vimichat.Common" on path: DexPathList[[zip file "/data/app/com.vimi.vimichat-1/base.apk"],nativeLibraryDirectories=[/data/app/com.vimi.vimichat-1/lib/arm64, /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:988)
at android.app.LoadedApk.makeApplication(LoadedApk.java:581)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5041)
at android.app.ActivityThread.access$1500(ActivityThread.java:187)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5844)
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:1109)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875)
Suppressed: java.lang.ClassNotFoundException: com.vimi.vimichat.Common
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
附加项目gradle文件的部分
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
mavenCentral()
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 21
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
jumboMode = true
}
useLibrary 'org.apache.http.legacy'
}
我在这里多次看到这些堆栈跟踪错误,但没有明确答案是什么问题。
我尝试清理和重建,清除Android Studio缓存,更新gradle版本和插件。似乎没有什么对我有用。
编辑1
似乎问题依赖于一个或多个android支持库
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
将所有这些恢复到24.1.0似乎解决了这个问题。但是,我在其后续版本中使用了一些功能,因此没有帮助。
答案 0 :(得分:0)
我有同样的问题。我做了两件事来解决这个问题。
build.gradle
文件中。
android {
...
dexOptions {
preDexLibraries false
}
}
对我来说,由于关于RxJava2 BehaviourSubject的ClassNotFoundException而崩溃,因此禁用了解析它的prex forx。
Settings -> Build, Execute, Deployment -> Instant Run -> Enable Instant Run