slackhq/keeper

Inner R classes aren't kept for tests

Closed this issue · 1 comments

Keeper version: main

Imagine a library module :main defining an Android resource. Library :android-test-only references the resource in Java / Kotlin code. The :app module depends on :main in the main source code and on :android-test-only for Android tests only. A test in :app calls the code from :android-test-only referencing the resource, but the resource is otherwise nowhere else being used. I'd expect Keeper to generate a rule to keep the inner R class in order to reference the resource. Instead, I'm seeing a crash that the class was removed:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/slack/keeper/sample/main/R$bool;
at com.slack.keeper.example.android.test.SomeClass.isTablet(SomeClass.kt:10)
at com.slack.keeper.example.android.test.SomeClass.test(SomeClass.kt:13)
at com.slack.keeper.sample.KeeperSampleTest.testFunctionKept(KeeperSampleTest.kt:28)
... 31 trimmed
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.slack.keeper.sample.main.R$bool

The workaround is to add following rule to the main (not test) proguard rules:

-keep class com.slack.keeper.sample.main.R$bool { *; }

I was able to reproduce the issue within the Keeper project: main...vRallev:keeper:ralf/bug

Looking more into this, there's no top-level R class kept either. This is ultimately the same issue as #22