2016-06-22 14 views
2

私はproguardを使用してコードを難読化しようとしていました。リリースapkをビルドするとapkが生成されますが、コードは難読化されていません。私のコードをチェックし、解決策を提供してください。ProguardはAndroidでコードを難読化していません

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:[email protected]' 
    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:[email protected]') { 
     transitive = true; 
    } 
} 

はここであまりにも一般的で、あなたのProGuardの設定で様々なルールがほとんどすべてを維持する、すなわちあります

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

答えて

2

私proguard-rules.proファイルです。

このルールは(そのようなルールはライブラリに対してのみ有効です)すべてのパブリッククラスのすべてのpublicまたはprotectedフィールド/メソッドを保持します。このルールは、パッケージコム内のすべてのクラス/インタフェースを保つ

-keep public class * { 
    public protected *; 
} 

とそのサブパッケージ:

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

アプリケーションパッケージも同様com.で始まると仮定すると、これは難読化されているから、あなたのアプリケーションから何かを防ぐことができます。

関連する問題