Proguard:忽略App pro-guard规则并仅保留库规则

时间:2017-06-16 07:35:28

标签: android gradle android-gradle build.gradle proguard

myApp拥有肝脏人员SDK link的libaray模块以及我的应用程序所需的其他依赖项(roboguice / support library / volley etc)

我已在proguard-project.txt文件中设置了所有依赖项所需的pro-guard规则,并在发布版本类型中引用如下所示

app/build.gradle.file
  android{
repositories {
        flatDir {
            dirs project(':lp_messaging_sdk').file('aars')
        }
    }
   compile "org.roboguice:roboguice:$depRoboguiceVersion"
   compile "com.google.code.findbugs:jsr305:$depJsr305Version"
    ...
   compile project(':lp_messaging_sdk'
    ....
  }

  defaultConfig {
     .....      
   proguardFile getDefaultProguardFile('proguard-android.txt')
     .....
   }

 buildTypes {
         debug {
            debuggable = true
            minifyEnabled = false
            signingConfig signingConfigs.debug
        }
     release {
            debuggable = false
            minifyEnabled = true
            signingConfig signingConfigs.release
            proguardFile 'proguard-project.txt'
        }
}
productFlavors{
        prod {
        isProduction = true
        }
        develop{
        isProduction = false
        }

lp_messaging_sdk /的build.gradle

android{

 defaultConfig {
        consumerProguardFiles 'proguard.cfg'
    }
}

当我准备发布版本并在设备上运行应用程序崩溃时,我在通过回溯工具运行后在控制台上找到了以下堆栈跟踪

Android\Sdk\tools\proguard\bin>retrace mapping.txt str.txt
1) Could not find a suitable constructor in d.e.x$a. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at roboguice.inject.SharedPreferencesProvider$PreferencesNameHolder.class(Unknown Source)
while locating d.e.x$a for parameter 0 at d.e.x.<init>(Unknown Source) at d.b.a.configure(Unknown Source

似乎应用程序什么时候发布它而忽略了app pro-guard规则并只保留库中的

proguard-txt
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
       public *;
    }

    -keepclassmembers class ** {
        @com.squareup.otto.Subscribe public *;
        @com.squareup.otto.Produce public *;
    }

    -keepattributes Exceptions,InnerClasses,Signature,Deprecated,*Annotation*

    # Webview
    -keepclassmembers class fqcn.of.javascript.interface.for.webview {
       public *;
    }

    # Otto 
    -keepclassmembers class ** {
        @com.squareup.otto.Subscribe public *;
        @com.squareup.otto.Produce public *;
    }

    -keep class com.xdc.app** { *; }

    -keep class com.google.inject.** { *; } 
    -keepclassmembers class * {
        @com.google.inject.Inject <fields>;
        @com.google.inject.Inject <init>(...);
    }
    -keep class javax.inject.** { *; } 
    -keep class javax.annotation.** { *; } 

    -keep class com.liveperson.** { *; }
    -keep class android.** { *; }
    -keep class com.facebook.** { *; }
    -keep class com.fasterxml.jackson.** { *; }
    -keep class com.flurry.** { *; }
    -keep class com.neonstingray.** { *; }
    -keep class com.octo.android.robospice.** { *; }
    -keep class net.sf.cglib.** { *; }
    -keep class org.objectweb.asm.** { *; }
    -keep class org.springframework.** { *; }
    -keep class twitter4j.** { *; }

    -dontwarn java.beans.**
    -dontwarn com.liveperson.**
    -dontwarn roboguice.activity.**
    -dontwarn java.lang.management.**
    -dontwarn javax.**
    -dontwarn com.android.**
    -dontwarn com.flurry.**
    -dontwarn com.google.android.**
    -dontwarn com.google.code.**
    -dontwarn com.google.gson.**
    -dontwarn com.xtremelabs.robolectric.**
    -dontwarn net.sf.cglib.transform.**
    -dontwarn org.apache.tools.ant.**
    -dontwarn org.apache.commons.httpclient.**
    -dontwarn org.apache.commons.logging.**
    -dontwarn org.apache.log4j.**
    -dontwarn org.codehaus.jackson.**
    -dontwarn org.joda.**
    -dontwarn org.junit.**
    -dontwarn org.objectweb.asm.**
    -dontwarn org.simpleframework.xml.**
    -dontwarn org.slf4j.**
    -dontwarn org.w3c.dom.**

    -dontnote dalvik.**

=================================
    proguard-cfg
    -keep public class com.liveperson.** { *; }

    #----------------------OkHttp rules----------------------
     -keepattributes Signature
     -keepattributes *Annotation*
     -keep class okhttp3.** { *; }
     -keep interface okhttp3.** { *; }
     -dontwarn okhttp3.**
    #----------------------OkHttp----------------------


    #----------------------Fresco rules----------------------
    # Keep our interfaces so they can be used by other ProGuard rules.
    # See http://sourceforge.net/p/proguard/bugs/466/
    -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

    # Do not strip any method/class that is annotated with @DoNotStrip
    -keep @com.facebook.common.internal.DoNotStrip class *
    -keepclassmembers class * {
        @com.facebook.common.internal.DoNotStrip *;
    }

    # Keep native methods
    -keepclassmembers class * {
        native <methods>;
    }

    -dontwarn okio.**
    -dontwarn javax.annotation.**
    -dontwarn com.android.volley.toolbox.**
    -dontwarn com.facebook.imagepipeline.**
    #----------------------Fresco----------------------

0 个答案:

没有答案