启用proguard后出现StackOverflow错误

时间:2018-05-28 08:22:12

标签: android proguard

启用proguard在构建项目时出现StackOverflow错误。在我收到错误之后,需要花费将近一个小时的时间来构建。

完整错误日志https://hastebin.com/wigodovasi.css

Cause: java.lang.StackOverflowError
    at com.android.build.gradle.shrinker.parser.GrammarActions.method(GrammarActions.java:302)
    at com.android.build.gradle.shrinker.parser.GrammarActions.fieldOrAnyMember(GrammarActions.java:210)
    at com.android.build.gradle.shrinker.parser.ProguardParser.member(ProguardParser.java:2280)
    at com.android.build.gradle.shrinker.parser.ProguardParser.members(ProguardParser.java:1982)
    at com.android.build.gradle.shrinker.parser.ProguardParser.classSpecification(ProguardParser.java:1599)
    at com.android.build.gradle.shrinker.parser.ProguardParser.prog(ProguardParser.java:331)
    at com.android.build.gradle.shrinker.parser.GrammarActions.parse(GrammarActions.java:64)
    at com.android.build.gradle.shrinker.parser.GrammarActions.include(GrammarActions.java:82)
    at com.android.build.gradle.shrinker.parser.ProguardParser.prog(ProguardParser.java:316)
    at com.android.build.gradle.shrinker.parser.GrammarActions.parse(GrammarActions.java:64)
    at com.android.build.gradle.shrinker.parser.GrammarActions.include(GrammarActions.java:82)
    //Stacktrace containing repeated elements shortened
    at com.android.build.gradle.shrinker.parser.GrammarActions.include(GrammarActions.java:82)
    at com.android.build.gradle.shrinker.parser.ProguardParser.prog(ProguardParser.java:316)
    at com.android.build.gradle.shrinker.parser.GrammarActions.parse(GrammarActions.java:64)
    at com.android.build.gradle.shrinker.parser.GrammarActions.include(GrammarActions.java:82)

Gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "package_name"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 5
        versionName "1.0.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
        multiDexEnabled true
    }
    signingConfigs {
        release {
            //key info
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support.test:runner:1.0.2'

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:multidex:1.0.3'

    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'

    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
    implementation 'com.google.firebase:firebase-crash:16.0.0'
    implementation 'com.google.firebase:firebase-config:16.0.0'

    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'

    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'

    implementation 'com.squareup.picasso:picasso:2.5.2'

    implementation ('com.facebook.android:facebook-android-sdk:4.33.0') {
        exclude module: 'support-compat'
    }

    implementation ('com.appyvet:materialrangebar:1.4.1') {
        exclude module: 'support-compat'
    }
}
apply plugin: 'com.google.gms.google-services'

Proguard文件

-keepclassmembers class fqcn.of.javascript.interface.for.webview {
   public *;
}

# Uncomment this to preserve the line number information for
# debugging stack traces.
-include proguard-rules.pro
-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
-renamesourcefileattribute SourceFile

# Proguard rules that are applied to your test apk/code.
-ignorewarnings

-keepattributes *Annotation*

-dontnote junit.framework.**
-dontnote junit.runner.**

-dontwarn android.test.**
-dontwarn android.support.test.**
-dontwarn org.junit.**
-dontwarn org.hamcrest.**
-dontwarn com.squareup.javawriter.JavaWriter
# Uncomment this if you use Mockito
#-dontwarn org.mockito.**

# Support design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

# Appcompat Support v7
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}

# Cardview
-keep class android.support.v7.widget.RoundRectDrawable { *; }

# support constraint
-dontwarn android.support.constraint.**
-keep class android.support.constraint.** { *; }
-keep interface android.support.constraint.** { *; }
-keep public class android.support.constraint.R$* { *; }

# Retrofit
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# 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

# Okio
-dontwarn okio.**

# -keep class com.example.app.json.** { *; }
-keep class package_name.models.** { *; }

# 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
-dontwarn sun.misc.**
-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

# Picasso
-dontwarn com.squareup.okhttp.**

# OkHttp 3
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# Facebook
-keepclassmembers class * implements java.io.Serializable {
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keepnames class com.facebook.FacebookActivity
-keepnames class com.facebook.CustomTabActivity

-keep class com.facebook.all.All

-keep public class com.android.vending.billing.IInAppBillingService {
    public static com.android.vending.billing.IInAppBillingService asInterface(android.os.IBinder);
    public android.os.Bundle getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle);
}

# Material Rangebar
-keep class com.appyvet.** { *; }

1 个答案:

答案 0 :(得分:0)

proguard文件中存在问题。所以,我删除了所有规则,然后逐一添加,现在它正在工作

正确的proguard文件

-keepclassmembers class fqcn.of.javascript.interface.for.webview {
   public *;
}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile


# ----------------Retrofit 2 starts here  --------------------

# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# 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

# ----------------Retrofit 2 ends here -------------------------

# ----------------OkHttp 3 as well as Picasso starts here  --------

-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-dontwarn org.conscrypt.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

-dontwarn com.squareup.okhttp.**

# ---------------OkHttp 3 as well as Picasso ends here  -----------


##---------------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
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class package_name.models.** { *; }

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

# ---------------Material Rangebar starts here ------------------
-keep class com.appyvet.** { *; }
# --------------Material Rangebar ends here  --------------------

# ------------- Facebook starts here ----------------------------
-keepclassmembers class * implements java.io.Serializable {
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keepnames class com.facebook.FacebookActivity
-keepnames class com.facebook.CustomTabActivity

-keep class com.facebook.all.All

-keep public class com.android.vending.billing.IInAppBillingService {
    public static com.android.vending.billing.IInAppBillingService asInterface(android.os.IBinder);
    public android.os.Bundle getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle);
}
# -------------- Facebook ends here --------------------------------

-keep class org.xmlpull.v1.** { *; }
-dontwarn org.xmlpull.v1.**