gpt4 book ai didi

How to fix Proguard issue with Google Drive REST API(如何使用Google Drive REST API修复防护问题)

转载 作者:bug小助手 更新时间:2023-10-25 14:53:47 30 4
gpt4 key购买 nike



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:

我正在使用谷歌REST API v3将我的Android应用程序连接到Google Drive。当我在没有ProGuard的情况下运行(minifyEnabled=False)时,一切都很好。然而,当我启用保护时,调用了错误的REST API方法。当我在驱动器根别名“root”上调用Drive.Files.get().ecute时,我得到了Drive.Files.list().ecute的结果。当我禁用“minifyEnabled”时,我看到了正确的结果。以下是build.gradle中控制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'
}
}


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

默认的ProGuard文件是随Android Studio2.2分发的未经修改的文件(不是优化版本)



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

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



-keepattributes EnclosingMethod
-keepattributes InnerClasses
-dontoptimize

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


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

当我检查生成的mapping.txt时,我仍然看到在imo应该“保留”的类中重命名的成员。例如:



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

Com.google.api.client.auth.oauth.OAuthParameters->com.google.api.client.auth.oauth.OAuthParameters:java.security.SecureRandom->L com.google.api.client.auth.oauth.OAuthSigner签名者->a java.lang.StringCallback->b java.lang.StringConsumer erKey->c java.lang.Stringnonce->d java.lang.StringRealm->e



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

我会想,“--保持类com.google.**”会避免这种情况吗?



Any idea how to fix this?

你知道怎么解决这个问题吗?



THanks in advance,

提前谢谢你,


更多回答

you got it fixed? i am facing same problem. Please help if you know. Thanks

你修好了吗?我也面临着同样的问题。如果你知道,请帮忙。谢谢

Yes, see my last comment from 2 Nov 2016 "I was able to narrow it down...."

是的,请看我在2016年11月2日发表的最后一条评论:我能够缩小范围……

优秀答案推荐

This one worked for me:

这个办法对我很管用:



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


As seen in the official google sample:

正如谷歌官方样本所示:



https://github.com/google/google-api-java-client-samples/blob/master/tasks-android-sample/proguard-google-api-client.txt

Https://github.com/google/google-api-java-client-samples/blob/master/tasks-android-sample/proguard-google-api-client.txt



You need

你需要


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

and


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

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

此外,您可能会尝试对SDK保留较少的内容。这些规则非常宽泛。


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

编辑:宽规则意味着它可能会在您的项目中保留更多未使用的类,因此APK大小和方法计数将会更大。



In my case I had to put these keeps:

在我的案例中,我不得不把这些保留:



-keep class br.project.pine.** { *;}
-keep class com.google.api.services.drive.** { *;}


Tip: When enabling minify in debug mode, pay attention to the LogCat. It can help you to find out the real missing package/class/attribute.

提示:在调试模式下启用minify时,请注意logcat。它可以帮助您找出真正缺失的包/类/属性。



This worked for me. Thank you.

这对我很管用。谢谢。


-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}
-dontwarn com.google.api.client.extensions.android.**
-dontwarn com.google.api.client.googleapis.extensions.android.**
-dontwarn com.google.android.gms.**
-dontnote java.nio.file.Files, java.nio.file.Path
-dontnote **.ILicensingService
-dontnote sun.misc.Unsafe
-dontwarn sun.misc.Unsafe
-keep class * extends com.google.api.client.json.** { *; }
-keep class * extends com.google.api.client.util.** { *; }
-keep class com.google.api.services.drive.** { *; }

更多回答

Tested and works very well. I find this as the most efficient fix as this fix only keeps the original source code for the absolutely necessary class members rather than blanket keep. I encourage other developers to validate and up vote the most efficient answer.

经过测试,运行良好。我发现这是最有效的修复,因为这个修复只保留绝对必要的类成员的原始源代码,而不是全面保留。我鼓励其他开发人员验证并投票支持最有效的答案。

great solution for this

这方面的绝佳解决方案

This one worked after spending 2-3 hrs of research. Thank you so much.

在花了2-3个小时的研究后,这个方法奏效了。非常感谢。

Unfortunately this does not help. The Drive API calls still get mixed up and in the mapping.txt I still see renaming in the com.google class members

不幸的是,这没有帮助。驱动器API调用仍然混淆,在mapping.txt中,我仍然看到com.google类成员中的重命名

When I added this to the main module's proguard-rules.pro it still failed, however, when I alos added that to a module that the main module is depending on, (the module that actually uses the Drive API), it works!. Thanks a lot.

当我将它添加到主模块的proGuard-rules.Pro中时,它仍然失败,然而,当我也将它添加到主模块所依赖的模块(实际使用Drive API的模块)时,它工作了!非常感谢。

I was able to narrow it down to these keeps: -keep,allowshrinking class com.google.api.services.drive.model.** { ;} -keep,allowshrinking class com.google.api.services.drive. { *;}

我能够将范围缩小到这些Keep:-Keep,Allow收缩类com.google.api.services.drive.delam.**{;}-Keep,Allow收缩类com.google.api.services.Drive。{*;}

Worked like a charm. After 5 hours of trying to figure out what was going on, this post was a life saver. In my case, I was having issues uploading files to Google Drive once my signed APK was created. When in debug mode, the problem was not able to be reproduced. Somehow, the ProGuard processing was removing the affects of the setName on the MetaData. Net effect was that all files were uploaded with the name of the file being NULL. Thanks again for the post!

就像一个护身符。在花了5个小时试图弄清楚到底是怎么回事之后,这篇帖子成了救命稻草。在我的例子中,一旦我的签名APK被创建,我在向Google Drive上传文件时就遇到了问题。在调试模式下,问题无法重现。不知何故,ProGuard处理正在消除setName对元数据的影响。NET的效果是,所有文件都是上载的,文件名为空。再次感谢你的帖子!

hi Alex, your solution might work as well I have only down voted because Evgeni Roitburg fix exactly pinpoints the issue. As you have said its a blanket fix, the less we keep original source code safer it will be. Good work though, please keep up. If possible please improve your answer so developers know what that wide rule means.

嗨,亚历克斯,你的解决方案可能也行得通,我投了反对票,因为叶夫根尼·罗伊特伯格的解决方案准确地指出了这个问题。正如你所说,这是一个包罗万象的解决方案,我们越少保持原始源代码的安全性,就会越安全。尽管做得很好,但请跟上。如果可能,请改进您的答案,以便开发人员知道这条宽泛的规则是什么意思。

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