3

I try to use Android Architecture Components, and its work fine on API 21+ But on 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.+'
}

Is there any way to fix it?

Hagakurje
  • 1,002
  • 2
  • 11
  • 17
  • Have a look at this question. Might be related to your problem https://stackoverflow.com/questions/44075089/noclassdeffounderror-landroid-arch-lifecycle-lifecycledispatcher – the-ginger-geek Jul 14 '17 at 06:18
  • Yes, I saw your solution, but for me it doesn't work – Hagakurje Jul 14 '17 at 06:26
  • Not my solution, just saw that answer and thought it might help. – the-ginger-geek Jul 14 '17 at 06:30
  • WHy do you care about 14? THat's Honeycomb- there were never many honeycomb devices, and few of them are still used. Its such a low percentage of use it isn't even tracked in Google's dashboard- its less than .1% of all devices in use. There's currently no reason to care about anything before 16, and I'd really argue new code shouldn't target below 19. (targetting 19 removes only about 9.5% of the world's users, mostly in low income countries, and supporting them takes a lot of effort). – Gabe Sechan Jul 14 '17 at 06:36

1 Answers1

0

Since 1.0.0-alpha4 most of the arch proguard issues should be fixed. The only addition you need to do inside the proguard file is the following rule, if you want to use Room:

-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource

Original answer:

Have you tried to use those rules to fix your problem? Works for me.

# 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 *;
}
Mordag
  • 487
  • 7
  • 20