【问题标题】:Proguard not shrinking test APKProguard不收缩测试APK
【发布时间】:2017-06-11 02:44:52
【问题描述】:

我正在使用 Proguard 来缩小我的调试 apk 并测试 apk

buildTypes {
    debug {
        applicationIdSuffix ".debug"
        debuggable true
        signingConfig signingConfigs.debug
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        testProguardFile 'proguard-test-rules.pro'
    }

当我启用 minify 并运行集成测试时,调试 apk 方法数会减少,但测试 apk 不会。

我知道 Proguard 正在做某事,因为如果我在 proguard-test-rules.pro 中没有正确的规则,我会看到警告并且测试 apk 将无法编译。

那么发生了什么?为什么我的测试 apk 没有缩小?仅供参考,这是我的 .pro 文件:

proguard-rules.pro:

# general
-dontobfuscate

# for Retrofit2
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

# for RetroLambda
-dontwarn java.lang.invoke.*

# for Saripaar
-keep class com.mobsandgeeks.saripaar.** {*;}
-keep @com.mobsandgeeks.saripaar.annotation.ValidateUsing class * {*;}

# for OKIO
-dontwarn okio.**

# for RxJava
-dontwarn sun.misc.Unsafe

# for android.content.res classes
-dontwarn org.xmlpull.v1.**

# for Butterknife
-dontwarn rx.functions.Func1

proguard-test-rules.pro

-include proguard-rules.pro

-dontobfuscate
-dontwarn

-dontwarn org.hamcrest.**
-dontwarn android.test.**

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

-keep class junit.runner.** { *; }
-keep class junit.framework.** { *; }
-keep class org.jmock.core.** { *; }
-keep class org.easymock.** { *; }


-dontwarn com.fasterxml.jackson.databind.**
-dontwarn com.fasterxml.jackson.core.**
-dontwarn com.fasterxml.jackson.annotation.**
-dontwarn org.ietf.jgss.**
-dontwarn javax.xml.**
-dontwarn javax.swing.**
-dontwarn javax.lang.**
-dontwarn java.nio.**
-dontwarn java.lang.**
-dontwarn org.w3c.dom.traversal.**
-dontwarn org.eclipse.jetty.**
-dontwarn java.beans.**
-dontwarn org.slf4j.**
-dontwarn org.apache.http.**

【问题讨论】:

标签: android testing proguard android-proguard


【解决方案1】:

ProGuard 仅在您以发布模式构建应用程序时运行,因此当您以调试模式或测试模式构建应用程序时,您不必处理混淆代码。 在调试模式或构建应用程序时test 不调用 ProGuard,因为它使调试更加麻烦。 Check this link

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-22
相关资源
最近更新 更多