Proguard没有混淆Android中的代码

时间:2016-06-22 14:01:28

标签: android android-proguard

我试图使用proguard来混淆我的代码。当构建一个版本apk时,它正在生成apk但代码没有被混淆。请检查我的代码并提供解决方案。

的build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    useLibrary 'org.apache.http.legacy'

    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE.uas.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

    defaultConfig {
        applicationId "com.infolabs.tv"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile files('libs/ez_cast_sdk_v_2.1.109.jar')
    compile files('libs/gson-2.4.jar')
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.github.d-max:spots-dialog:0.4@aar'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.android.support:design:23.3.0'
    compile files('libs/Parse-1.8.0.jar')
    compile 'com.github.satyan:sugar:1.4'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
        transitive = true;
    }
}

这是我的proguard-rules.pro文件

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-printmapping out.map
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-allowaccessmodification
-keepattributes *Annotation*,Signature,InnerClasses
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepattributes InnerClasses
-dontoptimize
-repackageclasses ''
-dontwarn android.support.**
-dontwarn android.support.design.**
-dontwarn butterknife.internal.ButterKnifeProcessor
-dontwarn com.parse.**
-dontwarn org.apache.harmony.awt.**
-dontwarn com.sun.mail.imap.protocol.**
-dontwarn com.aem.api.AEMPrinter
-dontwarn com.usb.api.USBPrinter
-dontwarn com.bewo.mach.tools.MACHOPTFPHelper
-dontwarn com.bewo.mach.tools.MACHDPHelper
-dontwarn javax.activation.CommandInfo
-dontwarn com.google.zxing.**
-dontwarn com.actionsmicro.androidkit.ezcast.imp.googlecast.**
-dontwarn org.apache.http.entity.mime.**
-dontwarn com.thetransactioncompany.jsonrpc2.server.MessageContext
-dontwarn com.actionsmicro.d.a.a
-dontwarn com.google.common.**
-dontwarn com.crashlytics.**

-keep public class * extends java.lang.Exception

# Gson specific classes
-keep class sun.misc.Unsafe { *; }

# Library projects.
# Priority jobqueue
#-keep class com.path.android.jobqueue.** { *; }
#-keep interface com.path.android.jobqueue.** { *; }

# Crashlytics Library
-keep class com.crashlytics.** { *; }
-keep interface com.crashlytics.** { *; }

# EventBus Library
-keep class de.greenrobot.event.EventBus.** { *; }
-keep interface de.greenrobot.event.EventBus.** { *; }

# Sugar ORM Library
-keep class com.orm.** { *; }
-keep interface com.orm.** { *; }

# Butterknife library
-keep class butterknife.** { *; }
-keep interface butterknife.** { *; }
-keep class **$$ViewInjector { *; }

# Parse Library
-keep class com.parse.** { *; }
-keep interface com.parse.** { *; }

# Bolts Library
-keep class bolts.** { *; }
-keep interface bolts.** { *; }

# sports dialoge Library
-keep class dmax.dialog.** { *; }
-keep interface dmax.dialog.** { *; }

# MACH Library
#-keep class com.bewo.mach.** { *; }
#-keep interface com.bewo.mach.** { *; }

# SlickUSB2SerialLib Library
#-keep class slickdevlabs.apps.usb2seriallib.** { *; }
#-keep interface slickdevlabs.apps.usb2seriallib.** { *; }

# SwipeMenu Listview Library
#-keep class com.baoyz.swipemenulistview.** { *; }
#-keep interface com.baoyz.swipemenulistview.** { *; }

# Background mail library
#-keep class com.kristijandraca.backgroundmaillibrary.** { *; }
#-keep interface com.kristijandraca.backgroundmaillibrary.** { *; }

# Zxing Library
#-keep class com.google.zxing.** { *; }
#-keep interface com.google.zxing.** { *; }

# ez_cast_sdk
-keep class a.a.a.** { *; }
-keep interface a.a.a.** { *; }

# ez_cast_sdk
-keep class c.a.a.** { *; }
-keep interface c.a.a.** { *; }

-keep class com.google.gson.** { *; }
-keep interface com.google.gson.** { *; }

-keep class com.** { *; }
-keep interface com.** { *; }

# The official support library.
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v7.appcompat.** { *; }
-keep interface android.support.v7.appcompat.** { *; }

# The official design support library.
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

# Keep fragments
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment

-keep public class * extends android.app.Activity
-keep public class * extends android.support.v7.app.ActionBarActivity
-keep public class * extends android.support.v7.app.AppCompatActivity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep class com.infolabs.tv.databases.** { *; }

-dontskipnonpubliclibraryclassmembers

-keep public class * {
    public protected *;
}

-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);
}

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

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

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

# Serializables

-keepnames class * implements java.io.Serializable

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    !private <fields>;
    !private <methods>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Native Methods

-keepclasseswithmembernames class * {
    native <methods>;
}

# Android Support Library

-keep class android.** {*;}

# Button methods

-keepclassmembers class * {

public void *ButtonClicked(android.view.View);

}

# Reflection

-keepclassmembers class com.elsinga.sample.proguard.SensorDescriptionFragment {

public void updateFields(com.elsinga.sample.proguard.SensorData);

}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Remove Logging
-assumenosideeffects class android.util.Log {
    public static *** e(...);
    public static *** w(...);
    public static *** wtf(...);
    public static *** d(...);
    public static *** v(...);
}

1 个答案:

答案 0 :(得分:2)

你的proguard配置中有各种规则过于通用,即保留几乎所有内容。

此规则将每个公共类或受保护的字段/方法保存在每个公共类中(这样的规则仅对库有用):

-keep public class * {
    public protected *;
}

此规则保留包com及其子包中的每个类/接口:

-keep class com.** { *; }
-keep interface com.** { *; }

假设您的应用程序包也以com.开头,这将阻止您的应用程序中的任何内容被混淆。