【问题标题】:Obfuscation of Apk>>Application crashes after splash screenApk的混淆>>闪屏后应用程序崩溃
【发布时间】:2016-01-10 20:21:42
【问题描述】:

我面临混淆我的 android 应用程序的问题。我的应用程序有 3 个模块。 我使用 android studio 在我的应用中启用了 proguard。

我的 gradle.build 文件如下:-

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.scconline"
    minSdkVersion 14
    targetSdkVersion 14
}

buildTypes {
    release {
        minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'),                  'proguard-rules.pro'

    }
      }
  }

  dependencies {
compile project(':androidHorizontalListView')
compile project(':library')
 // compile 'com.google.code.gson:gson:2.2'
  compile files('libs/eventbus-2.4.0.jar')
compile files('libs/fastjson.jar')
compile files('libs/itextpdf-5.5.4.jar')
compile files('libs/jsoup-1.8.1.jar')
compile files('libs/ksoap2-android-assembly-3.1.1-jar-with-   dependencies.jar')
compile files('libs/mockito-all-1.9.0.jar')
compile files('libs/xmlworker-5.5.4.jar')
compile files('libs/gson-2.2.4.jar')
compile files('libs/gson-2.2.4-javadoc.jar')
compile files('libs/gson-2.2.4-sources.jar')

 }

我的 proguard 规则文件如下:-

-dontshrink
-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
 -verbose
  -keepattributes *Annotation*

  -keep public class com.scconline.**

  -dontnote com.itextpdf.**
  -dontnote org.mockito.**
  -dontwarn com.itextpdf.**
   -dontwarn org.mockito.**
  -dontwarn android.**
  -dontwarn android.support.**
   -keep class android.support.** { *; }
  -keep interface android.support.** { *; }
  -keep class android.support.design.widget.** { *; }
  -keep interface android.support.design.widget.** { *; }
   -dontwarn android.support.design.*
 -dontwarn org.objenesis.**

-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
 }

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
 }

 -keepclasseswithmembers class * {
  public <init>(android.content.Context, android.util.AttributeSet, int);
  }

 -keepclassmembers class * extends android.content.Context {
  public void *(android.view.View);
  public void *(android.view.MenuItem);
  }

  -keepclassmembers class * implements android.os.Parcelable {
  static ** CREATOR;
  }

  -keepclassmembers class **.R$* {
  public static <fields>;
 }

  -keepclassmembers class * {
  @android.webkit.JavascriptInterface <methods>;
  }

我在我的主模块中使用上述规则文件,其余两个模块使用默认规则文件,我也在模块中启用 proguard。

请帮忙!!我将非常感激...

【问题讨论】:

    标签: android apk android-proguard


    【解决方案1】:

    使用这个:

        apply plugin: 'com.android.library'
    
    android {
    compileSdkVersion 17
    buildToolsVersion "21.1.2"
    
    defaultConfig {
        minSdkVersion 5
        targetSdkVersion 17
    }
    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    
    }
    }
    
    dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    }
    

    【讨论】:

    • 我想加入 proguard..你的回答会关闭 proguard。感谢您的回答。
    【解决方案2】:

    我在我的 proguard 规则文件中使用了以下代码。它将解决我的问题。

     -dontusemixedcaseclassnames
    -dontskipnonpubliclibraryclasses
    -dontpreverify
    -verbose
    -ignorewarnings
    -repackageclasses ''
    -allowaccessmodification
     -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
    -keepattributes *Annotation*, EnclosingMethod
    -keepattributes Signature
    
    -keep class com.fasterxml.jackson.**
    -keepnames class com.fasterxml.jackson.** { *; }
    -keep public class * extends android.support.v4.app.FragmentActivity
    
    -keep public class * extends android.app.Activity
    
    
    -keep public class * extends com.fasterxml.jackson.**
    -keep public class * implements java.io.Serializable
    -keep public class com.scconline.response.**
    -keepclassmembers public class com.scconline.response.**{
    <init>(...);
    *;
    }
    -keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
    }
    -keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    -keepclassmembers enum * {
      public static **[] values();
      public static ** valueOf(java.lang.String);
     }
    -keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
    }
    -keepclassmembers class **.R$* {
    public static <fields>;
    }
    -keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
    }
        -keepclassmembers class * implements java.io.Serializable {
        static final long serialVersionUID;
        private static final java.io.ObjectStreamField[] serialPersistentFields;
        private void writeObject(java.io.ObjectOutputStream);
        private void readObject(java.io.ObjectInputStream);
        java.lang.Object writeReplace();
        java.lang.Object readResolve();
    }
    
    -assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
    }
    -adaptresourcefilenames    **.properties,**.gif,**.jpg,**.png,**.xml
    -adaptresourcefilecontents **.properties,**.xml
    -dontwarn android.**
    -dontwarn android.support.**
    -dontwarn android.support.design.*
    -dontwarn org.objenesis.**
     -dontwarn com.fasterxml.jackson.databind.**
    

    【讨论】:

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