6

I'm obfuscating my apk with proguard and Android Studio.

When I decompilate my apk, I can see a lot of file like aaa.java, aab.java. etc... but all files from my project has the original name.

Is there a way to obfuscate filenames of my project????

Here is my 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 { *; }    

EDIT 1: my 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')

}
Juliatzin
  • 18,455
  • 40
  • 166
  • 325
  • aaa.java is your obfuscated filename, what else do you mean? – Blundell May 04 '15 at 17:48
  • 2
    @Blundell I'm not sure what do you mean... I want my MainActivity.class having a name like aaa.java like others files in my apk. – Juliatzin May 04 '15 at 17:54
  • Ahh so you mean everything is obfuscated EXCEPT the files under your package name. – Blundell May 04 '15 at 20:49
  • 2
    Well, in my package, code is obfusced, but I'd like to obfuscate filename, so that I became more dificult to reach core code – Juliatzin May 04 '15 at 20:50
  • but the filename is needed because it is referenced in your AndroidManifest.java - thats how android system looks it up. How else would it work? – Blundell May 04 '15 at 20:52
  • It should obfuscate the Manifest too no??? When I try to uncompile Google Maps, I have no original filename... that what's I would like to achieve – Juliatzin May 04 '15 at 20:53
  • 1
    No proguard does not obfuscate XML at the moment, that is also why it does not obfuscate custom view classes as they are referenced from XML. – Blundell May 04 '15 at 21:08
  • I see. So what I want is not posible??? Your filenames can't change??? – Juliatzin May 04 '15 at 21:10
  • They can, your Activities, Services etc can't be changed. Least I think. FYI what is the benefit of your Activity name changing? As it can just be looked up in the AndroidManifest anyway – Blundell May 05 '15 at 07:31
  • Any update on this? – Shailendra Madda May 13 '21 at 14:53

1 Answers1

1

Did you tried to add this?

-flattenpackagehierarchy

I suggest also to check if you really need these kind of keep (if not, remove them):

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

And check that your build.gradle file is really using Proguard in the desidered build type.

bonnyz
  • 13,458
  • 5
  • 46
  • 70
  • 1
    yep, I really need it... I have no problem that my objects are readable, but models and controllers should not. I will try the first line and tell you – Juliatzin May 04 '15 at 17:29
  • 1
    I tried -flattenpackagehierarchy and see no differences :( – Juliatzin May 04 '15 at 17:34
  • 1
    @JuliatzindelToro ok, are you sure you are using Proguard correctly in your build.gradle? I've updated my answer with another suggestion – bonnyz May 04 '15 at 17:47
  • 1
    yep, I would say I'm sure, I only have one config for release... I joined my build.gradle so that you can see it – Juliatzin May 04 '15 at 17:57
  • 1
    - flattenpackagehierarchy does nothing because I already have : - repackageclasses '', and it overrides it according to doc: http://proguard.sourceforge.net/manual/usage.html – Juliatzin May 04 '15 at 19:31