Ramesh Kumar
Ramesh Kumar

Reputation: 1229

Proguard does not changing package names

I am stuck in a problem as proguard does not change my package names and classes names, I am using different libraries GSon, Retrofit, support v-4, v7, okhttp, glide, facebook, fcm, custom tabs, crashlytics, MULTIDEX, jsonwebtoken jjwt, and others, I have enabled proguard in build.gradle file :

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://artifactory.9elements.com/artifactory/imgly" }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'

//        classpath 'com.android.tools.build:gradle:2.3.1'
//        classpath 'com.mutualmobile.gradle.plugins:dexinfo:0.1.2'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


//apply plugin: 'com.mutualmobile.gradle.plugins.dexinfo'
android {
//    compileSdkVersion 25
//    buildToolsVersion "25.0.2"
    signingConfigs {
        release {
            keyAlias 'a'
            keyPassword 'a'
            storeFile file('J:/Android Studio Projects/a-android/a_Keystore.jks')
            storePassword 'a'
            v2SigningEnabled false
        }
    }
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        applicationId "com.test.r"

        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
//        minSdkVersion 16
//        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
        multiDexEnabled true
        //to remove conflicts of compress library and editor sdk
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }

    }
    buildTypes {
        buildTypes.each {
            it.resValue 'string', 'facebook_app_id', Facebook_APP_ID
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable false
            jniDebuggable false
            signingConfig signingConfigs.release
            renderscriptDebuggable false
        }
    }
    dexOptions {
        incremental true
        javaMaxHeapSize "2048M"
        jumboMode = true

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


    lintOptions{
        disable 'MissingTranslation'
    }
}
repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile project(':sdp-android')
    compile files('libs/universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar')
    compile project(':customTab')
    compile project(':gallery')
    compile project(':camera')
    compile project(':cameraVideo')
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.okhttp:okhttp:2.7.2'
    //    compile 'com.github.bumptech.glide:glide:3.5.2'
    compile 'com.android.support:support-v4:25.1.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    testCompile 'junit:junit:4.12'
    compile 'com.daasuu:BubbleLayout:1.1.1'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.+'
    compile 'com.google.firebase:firebase-messaging:9.4.0'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    compile 'com.google.android.gms:play-services-location:9.4.0'
    compile 'io.jsonwebtoken:jjwt:0.7.0'
    //    compile 'com.uniquestudio:parsingplayer:2.0.4'

    // compile 'com.google.android.exoplayer:exoplayer:r2.3.0'

    //    compile 'com.devbrackets.android:exomedia:3.1.1'
    compile 'com.android.support:multidex:1.0.1'
    compile project(':exoMediaPlayer')
    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }
    compile project(':videocompress')
    compile project(':videoPlayer')
    compile project(':videoPlayerLib')
    compile project(':chromeTab')
    compile 'com.android.support:customtabs:25.1.1'
    //    compile 'ly.img.android:photo-editor-sdk:3.1.0'
    compile 'ly.img.android:photo-editor-sdk:4.0.1'
    compile 'com.danikula:videocache:2.7.0'
    compile 'commons-io:commons-io:2.4'
}

apply plugin: 'com.google.gms.google-services'

and here is Proguard file:

-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }

-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }



##---------------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

# For using GSON @Expose annotation
-keepattributes *Annotation*

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

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

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



-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

-keepclasseswithmembers class retrofit2.* {
    @retrofit2.http.* <methods>;
}






# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**

# for Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

## Google Play Services 4.3.23 specific rules ##
## https://developer.android.com/google/play-services/setup.html#Proguard ##

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

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}


# end



# Custom Tabs
-dontwarn android.support.customtabs.**
-keep class android.support.customtabs.** { *; }
-keep interface android.support.customtabs.** { *; }


# Render Script
-keep class android.support.v8.renderscript.** { *; }

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

-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*


#
-keep class io.github.memfis19.** { *; }
-dontwarn io.github.memfis19.**



-dontwarn com.googlecode.mp4parser.**

-dontwarn io.jsonwebtoken.impl.**
-dontwarn io.jsonwebtoken.**
-keep class io.jsonwebtoken.** { *; }




-dontwarn com.fasterxml.**
-keep class com.fasterxml.** { *; }

-keepattributes *Annotation*,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.** { *; }
 -dontwarn com.fasterxml.jackson.databind.**
 -keepclassmembers public final enum com.fasterxml.jackson.annotate.JsonAutoDetect$Visibility {
 public static final com.fasterxml.jackson.annotate.JsonAutoDetect$Visibility *; }


-keep public class * extends android.app.Activity
-keep public class * extends android.support.v7.app.AppCompatActivity
-keep public class * extends android.app.Application
-keep public class * extends android.support.multidex.MultiDexApplication

-keep class android.support.multidex.**{*;}

But my release apk does not renaming any model classes, adapters or anything only members of the class names renamed. Like my whole code is user visible. Can any one have idea I am doing wrong.

Here is screenshot: enter image description here Thanks in advance.

Upvotes: 2

Views: 4366

Answers (2)

Om Infowave Developers
Om Infowave Developers

Reputation: 1565

Use

 -overloadaggressively
-useuniqueclassmembernames


-dontwarn org.apache.http.**



#Crashlytics
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable

#-keep class com.crashlytics.** { *; }
#-dontwarn com.crashlytics.**

#end crashlytics



-dontpreverify
-repackageclasses 'android_spt'
-allowaccessmodification
-optimizations !code/simplification/arithmetic,!field
-keepattributes *Annotation*

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

Upvotes: 1

Sunilkumar Ramamurthy
Sunilkumar Ramamurthy

Reputation: 133

Proguard doesn't have a standard to rename packages yet U can use a Manually created Proguard mapping file like this

Upvotes: 0

Related Questions