2017-07-14 64 views
2

我嘗試使用Android的體系結構組件,其做工精細的API 21+ 但在API 14:Android的架構組件與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

看看這個問題。可能與您的問題有關https://stackoverflow.com/questions/44075089/noclassdeffounderror-landroid-arch-lifecycle-lifecycledispatcher – Neil

+0

是的,我看到了您的解決方案,但對我來說它不起作用 – Hagakurje

+0

不是我的解決方案,只是看到回答並認爲它可能有所幫助。 – Neil

回答

0

由於1.0.0-alpha4大部分arch prouard問題應該修復。你需要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 *; 
} 
+0

同樣的錯誤,沒有變化。 – Hagakurje