我在Android手机上手动安装APK时遇到了问题(在多个Android版本上测试过)。 stacktrace向我显示 ClassNotFoundException ,因为它无法找到类 BootstrapApplication 。
当我从Android Studio安装APK时("运行"),我没有收到此错误。
我该如何解决这个问题?
这是完整的stackTrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: mypackage.myapp, PID: 19686
java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" on path: DexPathList[[zip file "/data/app/mypackage.myapp.apk"],nativeLibraryDirectories=[/data/app-lib/mypackage.myapp, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4745)
at android.app.ActivityThread.access$1600(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5635)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" on path: DexPathList[[zip file "/data/app/mypackage.myapp.apk"],nativeLibraryDirectories=[/data/app-lib/mypackage.myapp, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:981)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4745)
at android.app.ActivityThread.access$1600(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5635)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
我做了一些研究,我认为问题来自于gradle,但我无法处理它,所以这里是模块:应用程序的gradle:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '4.2.0'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
repositories {
maven {
url 'http://an.url'
credentials {
username = '********'
password = '********'
}
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
defaultPublishConfig 'develop'
publishNonDefault true
applicationId "mypackage.myapp"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
develop {
versionNameSuffix '-develop'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
qualif {
versionNameSuffix '-develop'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// To avoid error of jackson "duplicate files copied in apk meta-inf/license"
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
// Android annotations
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
// Android annotation modules
compile "org.androidannotations:rest-spring-api:$AAVersion"
apt "org.androidannotations:rest-spring:$AAVersion"
compile "org.androidannotations:ormlite-api:$AAVersion"
apt "org.androidannotations:ormlite:$AAVersion"
// Use ormlite DAO
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
// Use jackson rest converter
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
compile 'com.fasterxml.jackson.core:jackson-core:2.8.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.0'
// Maply
compile 'com.mousebirdconsulting.maply:Android:2.5'
// Google play services for geolocation
compile 'com.google.android.gms:play-services-location:10.0.1'
// Dependant modules of Wizway
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
// ACRA for bug report
compile 'ch.acra:acra:4.5.0'
}
apt {
arguments {
// you can set annotation processing options here
logLevel 'TRACE'
logAppenderConsole 'true'
}
}