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

后端 未结 6 852
渐次进展
渐次进展 2020-11-30 04:06

Currently, I\'m having experience that, a piece of code, which makes use of Google Drive API is running fine without introducing ProGuard.

However,

相关标签:
6条回答
  • 2020-11-30 04:29

    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

    0 讨论(0)
  • 2020-11-30 04:36

    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.

    0 讨论(0)
  • 2020-11-30 04:38

    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

    0 讨论(0)
  • 2020-11-30 04:38

    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

    0 讨论(0)
  • 2020-11-30 04:40

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

    0 讨论(0)
  • 2020-11-30 04:46

    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*
    
    0 讨论(0)
提交回复
热议问题