简体   繁体   English

测试Android应用的发布和受保护版本-NoSuchMethodError

[英]Testing release and proguarded version of Android app - NoSuchMethodError

I'm trying to test release build of Android app with Proguard turned on. 我正在尝试在打开Proguard的情况下测试Android应用的发布版本。 I've created additional Proguard rules file for test dependencies which is included in the release rules file. 我已经创建了用于测试依赖性的其他Proguard规则文件,该文件包含在发行规则文件中。

-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 我正在使用Espresso进行测试,仪器运行器在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.** { *; } 对我来说,这似乎是错误的Proguard配置(缺少方法),但是行-keep class android.test.** { *; } -keep class android.test.** { *; } should fix such issue. -keep class android.test.** { *; }应该解决此问题。 Am I missing something? 我想念什么吗?

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 实际上,这是一个很难的“猜测代码”,希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM