gpt4 book ai didi

android - 当 minifyEnabled=true 时 GMail API 无法正常工作

转载 作者:太空狗 更新时间:2023-10-29 16:31:03 25 4
gpt4 key购买 nike

我正在开发一个使用 GMail API 发送电子邮件的 Android 应用程序。我在 Android Quickstart 使用了示例代码和 Sending Email当我调试应用程序时一切正常。当我使用 minifyEnabled=true 构建发布版本时出现问题。在这种情况下,对 service.users().messages().send(userId, message).execute(); 的调用会因 IOException 而出错。异常消息是“404 Not Found”。

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

-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 在可调试时会更大,因此我认为保留了一些基本的东西。

gradle文件中的依赖如下

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' 但删除它并不能解决问题。

最佳答案

我遇到了这个完全相同的问题,虽然你的 -keep class com.google.** {*;} 确实解决了这个问题,但它有点笨手笨脚,可能会让你无法保护的东西不想不 protected 。根据 Google API Documentation regarding ProGaurd ,您应该将以下行添加到您的 ProGuard 配置中。

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

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault

这使得 Google API 可以正常工作,同时受到 ProGuard 的保护。

关于android - 当 minifyEnabled=true 时 GMail API 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38768111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com