Google Drive API doesn't play well with ProGuard (NPE)

二次信任 提交于 2019-11-27 03:57:51

A combination of the following has worked for me:

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

-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-keepattributes *Annotation*,Signature
-keep class * extends com.google.api.client.json.GenericJson {
*;
}
-keep class com.google.api.services.drive.** {
*;
}

This provided a working proguard compatible solution for a recent Google Drive project.

Cannot take all credit for this solution though, originally found at this link here

lanx

Proper combination is :

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault

There's proguard configuration prepared by Google for project google-api-java-client

https://github.com/google/google-api-java-client/blob/57fe35766cbba0a0d5a9a296be81468d730a29f8/google-api-client-assembly/proguard-google-api-client.txt

Jeff Palmer

First -keeping a class does not mean to not touch it. It means do not change its name, and use it as a basis for determining if other classes are not referenced & can be deleted.

Optimization still occurs, which is likely your problem. Next step I would do is try with: -dontoptimize

This should cause your other optimizations to be ignored.

BTW, not sure what version of SDK you are using. Am using 15, 20 is latest, and a proguard-project.txt file is create with the project. The optimization options it uses is:

-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*

If turning off optimization gets it running, maybe turning off all the optimizations (that's what ! does) the SDK does, will allow you to do optimization as well.

The method Types.getSuperParameterizedType relies on information about generics. Generics are erased in Java. The compiler only adds them as annotation attributes, the JVM ignores them, and ProGuard discards them unless you tell it not to. So this might help:

-keepattributes *Annotation*

does your code use any thing that implement Serializable? All of those need to be excluded too.

There have been few update to GooglePlayServices lately. I don't like the new API. I had the same problems.

I couldn't compile signed app with proguard. Proguard template from Google didn't work for me.

I add these four lines to my proguard config and it is working:

-dontwarn com.google.android.gms.**
-keep interface com.google.** { *; }
-keep class * extends com.google.api.client.json.GenericJson {*;}
-keep class com.google.api.services.drive.** {*;}

This is strange. Previous version of google-api-services-drive-v2 compiled without any problems.

I'm using the latest version at the moment: google-api-services-drive-v2-rev47-1.12.0-beta.jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!