如何使用 Google Drive REST API 修复 Proguard 问题 [英] How to fix Proguard issue with Google Drive REST API

查看:35
本文介绍了如何使用 Google Drive REST API 修复 Proguard 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google Rest API v3 将我的 Android 应用程序连接到 Google Drive.当我在没有 Proguard (minifyEnabled=false) 的情况下运行时,一切都很好.但是,当我启用 proguard 时,会调用错误的 REST API 方法.当我在驱动器根别名root"上调用 Drive.Files.get().execute 时,我得到 Drive.Files.list().execute 的结果.当我禁用minifyEnabled"时,我看到了正确的结果.下面是控制 Proguard 运行的 build.gradle 部分:

I'm using the Google Rest API v3 to connect my android app to Google Drive. When I run without Proguard (minifyEnabled=false), all is well. However, when I enable proguard the wrong REST API methods are called. When I call Drive.Files.get().execute on the drive root alias "root" I get the result for a Drive.Files.list().execute. When I disable "minifyEnabled" I see the correct result. Here is the section of the build.gradle that controls running Proguard:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

默认的 Proguard 文件是随 Android Studio 2.2 分发的未经修改的文件(不是优化版本)

The default Proguard file is the unmodified one that gets distributes with Android Studio 2.2 (not the optimized version)

这是我的 proguard-rules.pro 文件的内容

And this is the contents of my proguard-rules.pro file

-keepattributes EnclosingMethod
-keepattributes InnerClasses
-dontoptimize

-keep class com.google.**
-keep class com.fasterxml.**
-dontwarn com.google.**

当我签入生成的 mapping.txt 时,我仍然看到 imo 应该保留"的类中重命名的成员.例如:

When I check in the generated mapping.txt I still see renamed members in classes that imo shoudl have been "kept". For example:

com.google.api.client.auth.oauth.OAuthParameters -> com.google.api.client.auth.oauth.OAuthParameters:java.security.SecureRandom 随机-> lcom.google.api.client.auth.oauth.OAuthSigner 签名者 -> 一个java.lang.String 回调 -> bjava.lang.String consumerKey -> cjava.lang.String nonce -> djava.lang.String 领域 -> e

com.google.api.client.auth.oauth.OAuthParameters -> com.google.api.client.auth.oauth.OAuthParameters: java.security.SecureRandom RANDOM -> l com.google.api.client.auth.oauth.OAuthSigner signer -> a java.lang.String callback -> b java.lang.String consumerKey -> c java.lang.String nonce -> d java.lang.String realm -> e

我会认为-keep class com.google.**"会避免这种情况?

I would have thought "-keep class com.google.** " would have avoided this?

知道如何解决这个问题吗?

Any idea how to fix this?

提前致谢,

推荐答案

你需要

-keep class com.google.** { *;} 

-keep class com.fasterxml.** { *;}

您也可以尝试减少 SDK 的使用量.这些规则非常广泛.

Also you might try to keep less from the SDK. These rules are very wide.

宽规则意味着它可能会在您的项目中保留更多未使用的类,因此 apk 大小和方法数会更大.

Wide rules means that it probably will keep more unused classes in your project hence the apk size and method count will be bigger.

这篇关于如何使用 Google Drive REST API 修复 Proguard 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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