Release apk not working after enabling proguard, n

2019-08-13 16:42发布

问题:

This question already has an answer here:

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

I am able to install the app in the device, but the app is not connecting to server . I am unable to debug the release apk too. When I disable proguard, the app gets connected to the server and I am able to debug the release apk too. I tried using proguard versions 4.7,4.9 and 5.2.1 . My Android version is 19 and my tools version is 20. I am using eclipse.

I have successfully used proguard 4.9 in my previous release to production.After my previous release to production, I had made two major changes to my code . I upgraded google-play-services and used jarjar to trim it and I upgraded the sdk tools to version 21 and then downgraded to version 20 due to some issues.

I would like to know what all I can try to figure out what is going wrong when I enable proguard . Something that seemed relevant that I picked from LogCat is below :

07-29 14:31:05.835: W/System.err(17696): java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.reflect.Type[]   java.lang.reflect.ParameterizedType.getActualTypeArguments()' on a null object reference
07-29 14:31:05.835: W/System.err(17696):    at com.google.api.client.util.Types.java.lang.reflect.ParameterizedType getSuperParameterizedType(java.lang.reflect.Type,   java.lang.Class)(Types.java)
     boolean isAssignableToOrFrom(java.lang.Class,java.lang.Class)(Types.java)
     java.lang.Object newInstance(java.lang.Class)(Types.java)
    IllegalArgumentException handleExceptionForNewInstance(java.lang.Exception,java.lang.Class)(Types.java)
    boolean isArray(java.lang.reflect.Type)(Types.java)
    java.lang.Class getRawClass(java.lang.reflect.ParameterizedType)(Types.java)
    reflect.Type getBound(java.lang.reflect.WildcardType)(Types.java)
    resolveTypeVariable(java.util.List,java.lang.reflect.TypeVariable)(Types.java)
    Class getRawArrayComponentType(java.util.List,java.lang.reflect.Type)(Types.java)
    reflect.Type getActualParameterAtPosition(java.lang.reflect.Type,java.lang.Class,int)(Types.java)
    Iterable iterableOf(java.lang.Object)(Types.java)
    Object toArray(java.util.Collection,java.lang.Class)(Types.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.util.Types.java.lang.reflect.Type getIterableParameter(java.lang.reflect.Type)(Types.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.http.HttpHeaders.com.google.api.client.http.HttpHeaders clone()(HttpHeaders.java)
    set(java.lang.String,java.lang.Object)(HttpHeaders.java)
    setAcceptEncoding(java.lang.String)(HttpHeaders.java)
    setAuthorization(java.util.List)(HttpHeaders.java)
    setContentLength(java.lang.Long)(HttpHeaders.java)
    void addHeader(java.util.logging.Logger,java.lang.StringBuilder,java.lang.StringBuilder,com.google.api.client.http.LowLevelHttpRequest,java.lang.String,java.lang.Object,java.io.Writer)(HttpHeaders.java)
    java.lang.String toStringValue(java.lang.Object)(HttpHeaders.java)
    void serializeHeaders(com.google.api.client.http.HttpHeaders,java.lang.StringBuilder,java.lang.StringBuilder,java.util.logging.Logger,com.google.api.client.http.LowLevelHttpRequest)(HttpHeaders.java)
    serializeHeadersForMultipartRequests(com.google.api.client.http.HttpHeaders,java.lang.StringBuilder,java.util.logging.Logger,java.io.Writer)(HttpHeaders.java)
    com.google.api.client.http.HttpHeaders,java.lang.StringBuilder,java.lang.StringBuilder,java.util.logging.Logger,com.google.api.client.http.LowLevelHttpRequest,java.io.Writer)(HttpHeaders.java)
    fromHttpResponse(com.google.api.client.http.LowLevelHttpResponse,java.lang.StringBuilder)(HttpHeaders.java)
    fromHttpHeaders(com.google.api.client.http.HttpHeaders)(HttpHeaders.java)
    parseHeader(java.lang.String,java.lang.String,com.google.api.client.http.HttpHeaders$ParseHeaderState)(HttpHeaders.java)
    java.lang.Object parseValue(java.lang.reflect.Type,java.util.List,java.lang.String)(HttpHeaders.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.http.HttpHeaders.com.google.api.client.http.HttpHeaders clone()(HttpHeaders.java)
    set(java.lang.String,java.lang.Object)(HttpHeaders.java)
    setAcceptEncoding(java.lang.String)(HttpHeaders.java)
    setAuthorization(java.util.List)(HttpHeaders.java)
    setContentLength(java.lang.Long)(HttpHeaders.java)
    void addHeader(java.util.logging.Logger,java.lang.StringBuilder,java.lang.StringBuilder,com.google.api.client.http.LowLevelHttpRequest,java.lang.String,java.lang.Object,java.io.Writer)(HttpHeaders.java)
    java.lang.String toStringValue(java.lang.Object)(HttpHeaders.java)
    void serializeHeaders(com.google.api.client.http.HttpHeaders,java.lang.StringBuilder,java.lang.StringBuilder,java.util.logging.Logger,com.google.api.client.http.LowLevelHttpRequest)(HttpHeaders.java)
    serializeHeadersForMultipartRequests(com.google.api.client.http.HttpHeaders,java.lang.StringBuilder,java.util.logging.Logger,java.io.Writer)(HttpHeaders.java)
    com.google.api.client.http.HttpHeaders,java.lang.StringBuilder,java.lang.StringBuilder,java.util.logging.Logger,com.google.api.client.http.LowLevelHttpRequest,java.io.Writer)(HttpHeaders.java)
    fromHttpResponse(com.google.api.client.http.LowLevelHttpResponse,java.lang.StringBuilder)(HttpHeaders.java)
    fromHttpHeaders(com.google.api.client.http.HttpHeaders)(HttpHeaders.java)
    parseHeader(java.lang.String,java.lang.String,com.google.api.client.http.HttpHeaders$ParseHeaderState)(HttpHeaders.java)
    java.lang.Object parseValue(java.lang.reflect.Type,java.util.List,java.lang.String)(HttpHeaders.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.http.HttpResponse.void <init>(com.google.api.client.http.HttpRequest,com.google.api.client.http.       LowLevelHttpResponse)(HttpResponse.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.http.HttpRequest.com.google.api.client.http.HttpResponse execute()(HttpRequest.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.com.google.api.client.http.HttpResponse                executeUnparsed(boolean)(AbstractGoogleClientRequest.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.com.google.api.client.http.HttpResponse            executeUnparsed()(AbstractGoogleClientRequest.java)
07-29 14:31:05.836: W/System.err(17696):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.java.lang.Object execute()(    AbstractGoogleClientRequest.java)
07-29 14:31:05.836: W/System.err(17696):    

回答1:

Your Proguard configuration is incorrect for one of the two things you just changed. Google Play Services details are here. They state you need to add the following ProGuard configs:

-keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); }

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; }

-keepnames @com.google.android.gms.common.annotation.KeepName class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; }

-keepnames class * implements android.os.Parcelable { public static final ** CREATOR; }