【问题标题】:Obsucate filenames with proguard使用 proguard 隐藏文件名
【发布时间】:2015-05-04 17:08:32
【问题描述】:

我正在使用 proguard 和 Android Studio 混淆我的 apk。

当我反编译我的 apk 时,我可以看到很多文件,例如 aaa.java、aab.java。等等... 但我项目中的所有文件都具有原始名称。

有没有办法混淆我的项目的文件名????

这是我的 proguard-rules.pro

    ##---------------Begin: proguard configuration common for all Android apps ----------
-optimizationpasses 5
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*


#-injars      bin/classes
#-injars      libs
#-outjars     bin/classes-processed.jar



-allowaccessmodification
#-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable, LocalVariableTable,LocalVariableTypeTable
-repackageclasses ''


#-keep public class * extends android.app.Activity
-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
-dontnote com.android.vending.licensing.ILicensingService

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

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-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();
}


# Preserve all native method names and the names of their classes.
-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

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

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


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


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


# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
  public static <fields>;
}


# Preserve the special static methods that are required in all enumeration classes.
#-keepclassmembers enum * {
#    public static **[] values();
#    public static ** valueOf(java.lang.String);
#}


#-keep public class * {
#    public protected *;
#}

##---------------End: proguard configuration common for all Android apps ----------


##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature


# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }


# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }


##---------------End: proguard configuration for Gson  ----------

##---------------Begin proguard configuration for Google Maps --------------------

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

-keep class org.** { *; }
-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}


-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

##---------------End proguard configuration for Google Maps --------------------

##---------------Begin proguard configuration for my libs  -----------------------
-keep class com.todddavies.components.progressbar.** { *; }
-dontwarn com.todddavies.components.progressbar.**

-dontwarn org.apache.**

#-keep class * implements android.os.Parcelable {
#  public static final android.os.Parcelable$Creator *;
#}
-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}
-keep class com.myapp.mobile.Pdv.** { *; }
-keep interface  com.myapp.mobile.Pdv.** { *; }

#Disable logging

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
    public static *** i(...);
}
-keep class com.myapp.mobile.vo.Captura { *; }
-keep class com.myapp.mobile.vo.Formulario { *; }
-keep class com.myapp.mobile.vo.Metrica { *; }
-keep class com.myapp.mobile.vo.Pdv { *; }
-keep class com.myapp.mobile.vo.Proyecto { *; }
-keep class com.myapp.mobile.vo.Producto { *; }    

编辑 1:我的 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:21'
    buildToolsVersion "21.1.2"
    lintOptions {
        abortOnError false
    }

    defaultConfig {
        applicationId "com.myapp.mobile"
        minSdkVersion 16
        targetSdkVersion 20
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}

dependencies {
    compile project(':progressWheel')
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/crashlytics.jar')
    compile files('libs/httpcore-4.3.2.jar')
    compile files('libs/httpmime-4.3.3.jar')

}

【问题讨论】:

  • aaa.java 是你的混淆文件名,还有什么意思?
  • 啊,所以你的意思是除了你的包名下的文件之外,一切都被混淆了。
  • 好吧,在我的包中,代码被混淆了,但我想混淆文件名,这样我就更难找到核心代码了
  • 目前没有 proguard 不会混淆 XML,这也是为什么它不会混淆自定义视图类,因为它们是从 XML 引用的。

标签: java android proguard


【解决方案1】:

您是否尝试添加此内容?

-flattenpackagehierarchy

我建议你也检查一下你是否真的需要这些keep(如果不需要,删除它们):

-keep class com.myapp.mobile.vo.Captura { *; }
-keep class com.myapp.mobile.vo.Formulario { *; }
-keep class com.myapp.mobile.vo.Metrica { *; }
-keep class com.myapp.mobile.vo.Pdv { *; }
-keep class com.myapp.mobile.vo.Proyecto { *; }
-keep class com.myapp.mobile.vo.Producto { *; } 
...  

并检查您的 build.gradle 文件是否真的是 using Proguard in the desidered build type

【讨论】:

  • 是的,我真的需要它......我的对象可读性没有问题,但模型和控制器不应该。我会尝试第一行并告诉你
  • 我试过 -flattenpackagehierarchy 并没有发现任何差异 :(
  • @JuliatzindelToro 好的,您确定您在 build.gradle 中正确使用了 Proguard 吗?我用另一个建议更新了我的答案
  • 是的,我敢肯定,我只有一个要发布的配置...我加入了我的 build.gradle 以便您可以看到它
  • - flattenpackagehierarchy 什么都不做,因为我已经有了:- repackageclasses '',它根据文档覆盖它:proguard.sourceforge.net/manual/usage.html
猜你喜欢
  • 2011-04-12
  • 2019-02-23
  • 2014-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多