当minifyEnabled = true时,GMail API无法正常工作 [英] GMail API not working properly when minifyEnabled=true

查看:125
本文介绍了当minifyEnabled = true时,GMail API无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,该应用程序使用GMail API发送电子邮件.我在 Android快速入门

I am developing an Android app that sends e-mails using the GMail API. I have used the example code at Android Quickstart and Sending Email and everything works fine when I debug the app. The problem arises when I build the release version with minifyEnabled=true. In that case, the call to service.users().messages().send(userId, message).execute(); goes into error with IOException. The message of the exception is "404 Not Found".

Proguard文件包含我在其他帖子中找到的所有-keep class-dontwarn:

The Proguard file includes all the -keep class and -dontwarn that I have found in other posts:

-dontwarn com.google.**
-dontwarn java.awt.**
-dontwarn javax.security.**
-dontwarn java.beans.**

-keep class com.google.**
-keep public class Mail {*;}
-keep class com.sun.activation.** {*;}
-keep class com.sun.activation.registries {*;}
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}

我不认为这是凭据的问题,因为如果我使用minifyEnabled=false签名应用程序,则会发送电子邮件.我还在模拟器上测试了应用程序的发行版,设置了minifyEnabled=truedebuggable=true.在这种情况下,已发送电子邮件,但可调试的APK较大,因此我认为保留了一些基本内容.

I don't think it is a problem of credentials as e-mails are sent if I sign the app with minifyEnabled=false. I also tested the release version of the app on the emulator, setting minifyEnabled=true and debuggable=true. In this case e-mails are sent but the APK is larger when it is debuggable so I think that something fundamental is retained ase.

gradle文件中的依赖项如下

Dependecies in the gradle file are the following

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile('com.google.api-client:google-api-client-android:1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    compile('com.google.apis:google-api-services-gmail:v1-rev47-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    compile 'org.achartengine:achartengine:1.2.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.12.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    compile 'com.google.android.gms:play-services-auth:9.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
    compile 'pub.devrel:easypermissions:0.1.5'
}

我不确定exclude group: 'org.apache.httpcomponents',但是删除它并不能解决问题.

I am not sure about exclude group: 'org.apache.httpcomponents' but removing it does not solve the problem.

推荐答案

我遇到了这个完全相同的问题,尽管您的-keep class com.google.** {*;}确实解决了该问题,但处理起来有点繁重,可能会使您无法保护的事情没有得到保护.想要不受保护.根据有关ProGaurd的Google API文档,则应在ProGuard配置中添加以下几行.

I ran into this exact same issue and while your -keep class com.google.** {*;} does fix the problem, it's a bit heavy handed and may leave things unprotected that you don't want unprotected. As per the Google API Documentation regarding ProGaurd, you should add the following lines to your ProGuard configuration.

-keepclassmembers class * {
  @com.google.api.client.util.Key <fields>;
}

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault

这允许Google API在受到ProGuard保护的同时正常运行.

This allows the Google APIs to work properly while being protected with ProGuard.

这篇关于当minifyEnabled = true时,GMail API无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆