9

I'm trying to test release build of Android app with Proguard turned on. I've created additional Proguard rules file for test dependencies which is included in the release rules file.

-keep class android.test.** { *; }
-dontwarn android.test.**

# Reuse the release ProGuard mapping
-applymapping proguard.map
-dontshrink
-dontoptimize

Everything compiles fine but it fails at runtime.

java.lang.NoSuchMethodError: android.test.AndroidTestRunner.addTestListener
    at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.start(ProGuard:135)
    at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner$BridgeTestRunner.start(ProGuard:249)
    at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:389)
    at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(ProGuard:114)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4702)
    at android.app.ActivityThread.access$1600(ActivityThread.java:172)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5586)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    at dalvik.system.NativeStart.main(Native Method)

I'm using Espresso for testing, the instrumentation runner is defined in build.gradle

defaultConfig {
    testApplicationId 'package.name.test'
    testInstrumentationRunner 'com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner'
}

Any chance to run tests for proguarded release build? I've found topic back from May and it looks like it's impossible. For me it looks like it's just wrong Proguard configuration (missing method), but the line -keep class android.test.** { *; } should fix such issue. Am I missing something?

tomrozb
  • 25,773
  • 31
  • 101
  • 122

1 Answers1

0

Im trying to help Sir.

instead of that

-keep class android.test.** { *; } 
-dontwarn android.test.**

add this to it

-keep class android.test.** { *; }
-keep class junit.** { *; }
-dontwarn android.test.**
-dontwarn junit.**

actually this is a hard "guess-a-code" hope it helps

Elltz
  • 10,730
  • 4
  • 31
  • 59
  • No this is not an issue. It fails at runtime with `NoSuchMethodError` at `android.test.AndroidTestRunner.addTestListener`, so your solution doesn't solve the problem. – tomrozb Jan 06 '15 at 23:29