0

由於proguard不會更改我的軟件包名稱和類名稱,因此我陷入了一個問題,我正在使用不同的軟件庫GSon,Retrofit,支持v-4,v7,okhttp,glide,facebook,fcm ,自定義選項卡,crashlytics,MULTIDEX,jsonwebtoken jjwt,和其他人,我已經啓用了的build.gradle文件的ProGuard: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:[email protected]') { 
     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 在此先感謝。

回答

0

Proguard的沒有一個標準來命名包還 U可以使用手動創建的Proguard的映射文件 像 this

0

使用

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

這是行不通的。我面臨的問題是我的文件沒有被重命名爲ab.class。我已經添加屏幕截圖 –

+0

我已經更新了答案,嘗試它並添加其他需要根據您使用的庫的規則 –

+0

它不起作用,我想我已經添加了不同的庫,所以progaurd不是不工作。 –

相關問題