我尝试使用Android架构组件,它在API 21+上运行良好 但是在API 14上:
java.lang.RuntimeException: Unable to get provider android.arch.lifecycle.LifecycleRuntimeTrojanProvider: java.lang.ClassNotFoundException: android.arch.lifecycle.LifecycleRuntimeTrojanProvider
at android.app.ActivityThread.installProvider(ActivityThread.java:4240)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:3992)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3946)
at android.app.ActivityThread.access$1300(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: android.arch.lifecycle.LifecycleRuntimeTrojanProvider
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.installProvider(ActivityThread.java:4225)
Dependensies
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:+'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'android.arch.lifecycle:runtime:+'
compile 'android.arch.lifecycle:extensions:+'
annotationProcessor "android.arch.lifecycle:compiler:+"
implementation 'com.android.support:support-v4:26.+'
}
有没有办法解决它?
答案 0 :(得分:0)
自1.0.0-alpha4以来,大多数的arch proguard问题都应该修复。如果你想使用Room:
,你需要在proguard文件中做的唯一的补充是以下规则-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource
原始回答:
您是否尝试过使用这些规则来解决问题?适合我。
# LifecycleObserver's empty constructor is considered to be unused by proguard
-keep class * implements android.arch.lifecycle.LifecycleObserver {
<init>(...);
}
# ViewModel's empty constructor is considered to be unused by proguard
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
<init>(...);
}
# keep Lifecycle State and Event enums values
-keepclassmembers class android.arch.lifecycle.Lifecycle$State { *; }
-keepclassmembers class android.arch.lifecycle.Lifecycle$Event { *; }
# keep methods annotated with @OnLifecycleEvent even if they seem to be unused
# (Mostly for LiveData.LifecycleBoundObserver.onStateChange(), but who knows)
-keepclassmembers class * {
@android.arch.lifecycle.OnLifecycleEvent *;
}