1

I have been facing following crash with Room stable version when proguard is enabled

FATAL EXCEPTION: main
              Process: <mypackage>.debug, PID: 27841
              java.lang.RuntimeException: Unable to create application <mypackage>.DebugBaseApplication: java.lang.RuntimeException: cannot find implementation for <mypackage>.database.c. c_Impl does not exist
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5015)
                  at android.app.ActivityThread.-wrap1(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1573)
                  at android.os.Handler.dispatchMessage(Handler.java:111)
                  at android.os.Looper.loop(Looper.java:207)
                  at android.app.ActivityThread.main(ActivityThread.java:5811)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)
               Caused by: java.lang.RuntimeException: cannot find implementation for <mypackage>.database.c. c_Impl does not exist
                  at android.a.c.b.d.a(Unknown Source)
                  at android.a.c.b.e$a.b(Unknown Source)
                  at <mypackage>.database.c.getFuelDatabase(Unknown Source)
                  at <mypackage>.database.b.init(Unknown Source)
                  at <mypackage>.c.onCreate(Unknown Source)
                  at <mypackage>.DebugBaseApplication.onCreate(Unknown Source)
                  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1041)
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5012)
                  at android.app.ActivityThread.-wrap1(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1573) 
                  at android.os.Handler.dispatchMessage(Handler.java:111) 
                  at android.os.Looper.loop(Looper.java:207) 
                  at android.app.ActivityThread.main(ActivityThread.java:5811) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)

Here is my proguard configuration for room

## Room
-dontwarn android.arch.util.paging.CountedDataSource
-dontwarn android.arch.persistence.room.paging.LimitOffsetDataSource

Here are how dependencies are being declared in build.gradle

// room for local cache
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
implementation "android.arch.persistence.room:rxjava2:1.0.0"

I have gone through many stackoverflow posts regarding this. Like Room Persistence Library run time exception when calling Rooms inMemoryBuilder method and Room cannot find implementation but thing is I am not using Kotlin and everything seems correctly configured to me. I am not sure whats the problem here please suggest.

Abhishek Bansal
  • 5,197
  • 4
  • 40
  • 69
  • @user1643723 Added full stacktrace – Abhishek Bansal Feb 08 '18 at 10:21
  • It seems, that you have enabled Proguard, but didn't properly configure it's exceptions (and neither did the Room itself). If you plan to use Proguard, you should learn, how to use it (which, unfortunately, implies knowing how everything in your application and it's dependencies works). Room, like many annotation processors, uses name-matching strategy for finding generated classes: if the template class is called "Foo", Room will name it's generated class something like "Foo_Impl". Proguard renames both (or some of) these classes, breaking Room's lookups. `-keep` Room-related classes. – user1643723 Feb 08 '18 at 10:33
  • Yeah, I am keeping whole package with `-keepclassmembers au.exxonmobil.fuelfinder.database.** { *; }` I will try keep though. – Abhishek Bansal Feb 08 '18 at 10:36
  • @user1643723 changing `-keepclassmembers` to `-keep` worked for me. Thanks! – Abhishek Bansal Feb 08 '18 at 10:42
  • `-keepclassmembers` does not impact the class itself (it can still be removed/renamed), only it's methods and properties. To be precise, you need `-keep,allowoptimization`. This way Proguard will still be able to do inlining and other optimizations on Room-generated code. – user1643723 Feb 08 '18 at 10:54
  • okay, great thanks! – Abhishek Bansal Feb 08 '18 at 11:14
  • having with the issue when update to 3.6, I didn't have proguard rule before. What to fix here? – Ken Zira Mar 05 '20 at 03:09

0 Answers0