Proguard不会更改包名称

时间:2017-08-11 10:25:15

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

我遇到了问题,因为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不重命名任何模型类,适配器或任何只重命名的类名成员。就像我的整个代码是用户可见的。 任何人都可以知道我做错了。

这是截图: enter image description here 提前谢谢。

1 个答案:

答案 0 :(得分:0)

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