问题描述
我正在用图库创建一个应用程序,为我生成SQL数据库和内容提供程序。 我还使用了许多其他库,我将gradle文件放在底部。
当我第一次部署应用程序时,它可以正常运行,但是如果我更改了代码中的某些内容(即使我只是插入了日志)并重新部署了该应用程序,它也会在启动时崩溃,但会出现以下异常:
02-08 20:53:40.279 29400-29400/hu.bendaf.udacity.popularmovies.popularmoviesapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: hu.bendaf.udacity.popularmovies.popularmoviesapp, PID: 29400
java.lang.RuntimeException: Unable to get provider hu.bendaf.udacity.popularmovies.popularmoviesapp.data.generated.MovieProvider: java.lang.ClassNotFoundException: Didn't find class "hu.bendaf.udacity.popularmovies.popularmoviesapp.data.generated.MovieProvider" on path: DexPathList[[zip file "/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/base.apk"],nativeLibraryDirectories=[/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5856)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "hu.bendaf.udacity.popularmovies.popularmoviesapp.data.generated.MovieProvider" on path: DexPathList[[zip file "/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/base.apk"],nativeLibraryDirectories=[/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.ActivityThread.installProvider(ActivityThread.java:5841)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
MovieProvider类应使用逻辑示意图库生成(该逻辑库在第一次部署时,但由于某种原因其消失了)。
如果我清理项目,则可以正确部署并再次运行我的应用程序,但是每次修改后清理项目都非常烦人。 :)
您能帮我造成问题的原因吗?
这是我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "hu.bendaf.udacity.popularmovies.popularmoviesapp"
minSdkVersion 15
targetSdkVersion 25
versionCode 2
versionName "1.1"
vectorDrawables.useSupportLibrary = true
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:25.1.1'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.android.support:cardview-v7:25.1.1'
annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.7.0'
compile 'net.simonvt.schematic:schematic:0.7.0'
}
您可以在上找到我的整个项目
1楼
我已经解决了问题,这是因为我使用了jack和java 1.8。 在我从gradle中删除了这些行(以及我的应用中的lambda函数)后,崩溃消失了:
jackOptions {
enabled true
}
...
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
谢谢您的帮助!
2楼
这可能是由于ProGuard缩小了尺寸。 您必须手动指定以忽略您的外部库。
您可以像这样在proguard-rules.pro
文件中指定它。
-keep class com.package.** { *; }
阅读更多..