Android:启用ProGuard后,谷歌云消息传递(GCM)无效

时间:2018-05-17 21:47:44

标签: android google-cloud-messaging proguard

我正在开发一款在ProGuard被禁用时正常运行的应用。然后我尝试缩小我的apk大小并找到ProGuard as a recommended tool

当我启用ProGuard时,我收到了总 1153 警告。然后添加proguard-rules.txt进行自定义。我刚刚添加了ProGuard Manual Example for Android Application中给出的代码段。并在-ignorewarnings文件的末尾添加了proguard-rules.text。然后,它编译,构建一个签名的apk和apk运行顺利。

但是有一个问题(可能还有其他未发现的问题)。那就是apk无法设置GCM ID,服务正在连续向服务器发送单个请求,没有收到GCM通知。但所有这些问题都在debug apk中解决,因为没有为调试apks启用ProGuard。

这是我的build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.2'

    defaultConfig {
        applicationId "com.example.ett"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 31
        versionName "1.0.18"
        multiDexEnabled true
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            useProguard true
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.txt'
        }
    }

    dexOptions {
        preDexLibraries = false
        incremental true
        javaMaxHeapSize "2048M"
    }

    lintOptions {
        // set to true to turn off analysis progress reporting by lint
        quiet true
        // if true, stop the gradle build if errors are found
        abortOnError false
        // if true, only report errors
        ignoreWarnings true
    }
}

dependencies {
    compile files('libs/MultipartUtility.jar')
    compile files('libs/javax.mail.jar')
    compile files('libs/picasso-2.5.0.jar')
    compile files('libs/FCJsonParser.jar')
    compile files('libs/JSON.jar')
    compile files('libs/FCJsonChatParser.jar')
    compile files('libs/revmob.jar')
    compile files('libs/commons-net-3.6.jar')

    compile project(':viewPagerIndicator')
    compile project(':connectionclass')
    compile project(':emojicons')

    compile 'com.android.support:support-v4:23.1.0'

    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:support-annotations:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.getbase:floatingactionbutton:1.10.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services-location:11.8.0'
    compile 'com.google.android.gms:play-services-gcm:11.8.0'
    compile 'com.google.android.gms:play-services-analytics:11.8.0'
    compile 'com.google.android.gms:play-services-ads:11.8.0'
    compile 'com.google.zxing:core:3.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'net.glxn.qrgen:android:2.0'
    compile 'org.apmem.tools:layouts:1.10@aar'
    compile 'me.dm7.barcodescanner:zbar:1.8.4'
    compile 'com.soundcloud.android:android-crop:1.0.0@aar'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.bartoszlipinski.recyclerviewheader:library:1.2.0'
    compile 'com.makeramen:roundedimageview:2.2.0'
    compile 'de.hdodenhof:circleimageview:2.0.0'
    compile 'com.github.danielnilsson9:color-picker-view:1.4.0@aar'

    compile 'com.facebook.stetho:stetho:1.3.1'
    compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'
    compile 'com.squareup.okhttp3:okhttp:3.3.1'
    compile 'com.facebook.stetho:stetho-js-rhino:1.3.1'

    compile 'com.github.chrisbanes:PhotoView:1.3.0'

    compile 'com.github.orangegangsters:swipy:1.2.3@aar'

    compile 'com.anjlab.android.iab.v3:library:1.0.44'
}

这是我的proguard-rules.txt

#-injars      bin/classes
-injars      libs
#-outjars     bin/classes-processed.jar
#-libraryjars /home/adnan/Android/Sdk/platforms/android-23/android.jar

-android
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keepattributes Signature

-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

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

-dontwarn android.support.**
-ignorewarnings

如何解决这个问题?有没有我在proguard-rules.txt档案中没有提及的内容?提前致谢。我使用了ProGuard version 6.0.3

0 个答案:

没有答案