【问题标题】:Proguard does not changing package namesProguard 不会更改包名称
【发布时间】:2017-08-11 10:25:14
【问题描述】:

我遇到了一个问题,因为 proguard 没有更改我的包名和类名,我正在使用不同的库 GSon、Retrofit、支持 v-4、v7、okhttp、glide、facebook、fcm、自定义选项卡、crashlytics、 MULTIDEX、jsonwebtoken jjwt等,我在build.gradle文件中启用了proguard:

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'

这是 Proguard 文件:

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

但我的发布 apk 不会重命名任何模型类、适配器或任何仅重命名类名称的成员。就像我的整个代码是用户可见的。 谁能知道我做错了。

截图如下: 提前致谢。

【问题讨论】:

    标签: android android-studio proguard obfuscation android-proguard


    【解决方案1】:

    Proguard 还没有重命名包的标准 你可以使用手动创建的 Proguard 映射文件 喜欢 this

    【讨论】:

      【解决方案2】:

      使用

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

      【讨论】:

      • 它不工作。我面临的问题是我的文件都没有像 ab.class 那样重命名。我添加了截图
      • 我已经更新了答案,尝试一下并根据您使用的库添加其他需要的规则
      • 它不起作用,我想我添加了不同的库,所以 progaurd 不是不起作用。
      猜你喜欢
      • 1970-01-01
      • 2022-01-18
      • 2013-03-24
      • 1970-01-01
      • 2012-07-14
      • 2016-08-16
      • 1970-01-01
      • 2017-03-05
      • 2012-05-04
      相关资源
      最近更新 更多