解析、ParseFacebookUtils ProGuard 异常

Parse, ParseFacebookUtils ProGuard exceptions

我正在尝试在基于解析的应用程序上应用混淆器。并尝试了各种排列组合,但在这里和那里我无法实现。如果有人帮助我使我的代码标准化并帮助我删除任何冗余。 这是我的应用程序(gradle)

   apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 27
        versionName "1.2.27"
    }

    productFlavors {
        // Define separate dev and prod product flavors.
        dev {
            // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
            // to pre-dex each module and produce an APK that can be tested on
            // Android Lollipop without time consuming dex merging processes.
            minSdkVersion 21
            multiDexEnabled true
        }
        prod {
            // The actual minSdkVersion for the application.
            minSdkVersion 19
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug{
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


    packagingOptions {
        exclude 'META-INF/maven/com.squareup.picasso/picasso/pom.properties'
        exclude 'META-INF/maven/com.squareup.picasso/picasso/pom.xml'
    }
}

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}

/*

    compile 'com.parse:parsefacebookutils-v4-android:1.10.4@aar'
    compile 'com.parse:parsefacebookutils-v4-android:1.10.3@aar'
    compile files('libs/ParseFacebookUtilsV4-1.10.1.jar')
*/

/*
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
*/


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    /*compile fileTree(include: 'Parse-*.jar', dir: 'libs')*/
    /*compile files('libs/volley.jar')*/
    compile files('libs/pgsdk.jar')
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
   /* compile 'com.parse.bolts:bolts-android:1.2.1'*/
    compile 'com.parse:parse-android:1.13.1'
    compile('com.facebook.android:facebook-android-sdk:4.8.2') {
        exclude module: 'bolts-android'
        exclude module: 'support-v4'
    }
    compile ('com.parse:parsefacebookutils-v4-android:1.10.4@aar'){
        transitive=true
    }
    compile 'com.parse:parsetwitterutils-android:1.10.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:support-v13:24.0.0'
    compile 'com.google.android.gms:play-services-location:9.8.0'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
    compile 'com.android.support:support-v4:24.0.0'
    compile 'com.google.android.gms:play-services-ads:9.8.0'
    compile 'com.google.android.gms:play-services-identity:9.8.0'
    compile 'com.google.android.gms:play-services-gcm:9.8.0'
    compile 'com.google.android.gms:play-services-plus:9.8.0'
    compile 'com.google.android.gms:play-services-auth:9.8.0'
    compile 'com.google.android.gms:play-services-places:9.8.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
        transitive = true;
    }
    compile 'com.mcxiaoke.volley:library:1.0.19'
}
apply plugin: 'com.google.gms.google-services'
}

这是我的progaurd-rules.pro

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/android/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

#common
-dontobfuscate
#-dontoptimize


# attributes
-keepattributes InnerClasses, Signature, *Annotation*, Exceptions

#Current Project packages
-keep class com.example.**{*;}
-keep interface com.example.**{*;}

#Paytm
-keep class com.paytm.**{*;}



# java
-dontwarn javax.naming.**
-dontwarn java.lang.invoke**
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

#retrofit
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

# gson
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }

# otto
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}

# google play services
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

#appengine
-keep  class com.google.appengine.api.urlfetch.**{*;}
-keep interface com.google.appengine.api.urlfetch.**{*;}
-dontwarn com.google.appengine.api.**

#DOM
-keep class org.w3c.dom.bootstrap.DOMImplementationRegistry{*;}
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry



#joda
-keep class org.joda.convert.**{*;}
-keep interface org.joda.convert.**{*;}
-dontwarn org.joda.convert.**

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


# Keep source file names, line numbers, and Parse class/method names for easier debugging
-keepattributes SourceFile,LineNumberTable
-keepnames class com.parse.** { *; }
-keep class com.parse.** { *; }

# Required for Parse
-dontwarn com.squareup.**
-dontwarn okio.**
-dontwarn com.parse.**

-keepnames class com.fasterxml.jackson.** { *; }
#-keep class com.shaded.fasterxml.jackson.** { *; }
-keep class com.fasterxml.jackson.databind.ObjectMapper {
    public <methods>;
    protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
    public ** writeValueAsString(**);
}


#piccaso
#-keep class com.squareup.picasso.**{*;}
#-keep interface com.squareup.picasso.**{*;}

-keep class org.apache.** { *; }
-dontwarn org.apache.**
-dontwarn android.net.SSLCertificateSocketFactory
-dontwarn android.app.Notification

-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }


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

散落了这么多解法。我发现 bolt 库之间的冲突最多。 我不再使用 Parse_abc.jar。

使用 Fabric 库来使用 facebook 功能,并将其定义到您的 progaurd-rules.pro

这是解决方法 bolt-android 的重复条目嵌套在各种库中。我只是将它们排除在 app.gradle 之外。还将所有库版本和 buildToolVersions 更新为 25.0.0

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.example"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 27
        versionName "1.2.27"
    }

    productFlavors {
        // Define separate dev and prod product flavors.
        dev {
            // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
            // to pre-dex each module and produce an APK that can be tested on
            // Android Lollipop without time consuming dex merging processes.
            minSdkVersion 21
            multiDexEnabled true
        }
        prod {
            // The actual minSdkVersion for the application.
            minSdkVersion 19
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


    packagingOptions {
        exclude 'META-INF/maven/com.squareup.picasso/picasso/pom.properties'
        exclude 'META-INF/maven/com.squareup.picasso/picasso/pom.xml'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'

    }
}

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}




dependencies {
    //compile fileTree(include: ['*.jar'], dir: 'libs')
    /*compile fileTree(include: 'Parse-*.jar', dir: 'libs')*/
    /*compile files('libs/volley.jar')*/
    compile files('libs/pgsdk.jar')
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
    //compile 'com.parse.bolts:bolts-android:1.2.1'
    compile ('com.parse:parse-android:1.13.1'){
        exclude module: 'bolts-android'
    }
    compile('com.facebook.android:facebook-android-sdk:4.8.2') {
        exclude module: 'bolts-android'
        exclude module: 'support-v4'
    }
    compile('com.parse:parsefacebookutils-v4-android:1.10.4@aar') {
        transitive = true
        exclude module: 'bolts-android'

    }
    compile 'com.parse:parsetwitterutils-android:1.10.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:support-v13:25.1.0'
    compile 'com.google.android.gms:play-services-location:10.0.1'
    //compile 'com.google.android.gms:play-services-appindexing:10.0.1'
    compile 'com.google.firebase:firebase-appindexing:10.0.1'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.google.android.gms:play-services-ads:10.0.1'
    compile 'com.google.android.gms:play-services-identity:10.0.1'
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
    compile 'com.google.android.gms:play-services-plus:10.0.1'
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'com.google.android.gms:play-services-places:10.0.1'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
        transitive = true;
        exclude module: 'bolts-android'
        exclude module: 'support-v4'
    }
    compile 'com.mcxiaoke.volley:library:1.0.19'
}
apply plugin: 'com.google.gms.google-services'

这是我的决赛 proguard-rules.pro

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/android/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

#common
-dontobfuscate
#-dontoptimize


# attributes
-keepattributes InnerClasses, *Annotation*

#Current Project packages
-keep class com.example.**{*;}
-keep interface com.example.**{*;}

#Paytm
-keep class com.paytm.**{*;}



# java
-dontwarn javax.naming.**
-dontwarn java.lang.invoke**
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

#retrofit
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

# gson
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }

# otto
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}

# google play services
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

#appengine
-keep  class com.google.appengine.api.urlfetch.**{*;}
-keep interface com.google.appengine.api.urlfetch.**{*;}
-dontwarn com.google.appengine.api.**

#DOM
-keep class org.w3c.dom.bootstrap.DOMImplementationRegistry{*;}
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry



#joda
-keep class org.joda.convert.**{*;}
-keep interface org.joda.convert.**{*;}
-dontwarn org.joda.convert.**

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


# Keep source file names, line numbers, and Parse class/method names for easier debugging
-keepattributes SourceFile,LineNumberTable
-keepnames class com.parse.** { *; }
-keep class com.parse.** { *; }
-dontwarn com.parse.ParseOkHttpClient**

# Required for Parse
-keep class com.squareup.** { *; }
-dontwarn com.squareup.**
-dontwarn okio.**
-dontwarn android.net.SSLCertificateSocketFactory
-dontwarn android.app.Notification
-keep class org.apache.http.** { *; }
-keep interface org.apache.http.** { *; }

-dontwarn org.apache.http.**



-keep class javax.servlet.** { *; }
-keep class org.ietf.jgss.** { *; }


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

虽然我没有完全理解,无法统一地向您解释。但是 Google 和我的排列组合让我得到了这个结果。我仍在测试任何崩溃的应用程序。那样的话我也会更新这个答案。