Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive Api v3 and proguard

After shrinking my release apk with proguard files().list() returns no files (in debug mode it does). I used the quickstart sample for login. There are no error messages. Login seems to be successful.

Here is my proguard.cfg:

-optimizationpasses 1
#-dontoptimize
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!class/unboxing/enum
-dontwarn android.support.v4.**
-dontwarn com.google.**
#-keep public class com.google.**
#-keep public class android.**
#-keep class com.google.android.gms.** { *; }
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault

#-keep public class * extends android.app.Activity
#-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService


#-keep public class pub.devrel.easypermissions.**


-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}


-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

This is the Code for retrieving the files:

private List<String> getDataFromApi() throws Exception {
            // Get a list of up to 10 files.
            lib.setgstatus("getDataFromApi Start");
            List<String> fileInfo = new ArrayList<String>();
            FileList result = mService.files().list()
                    .setPageSize(10)
                    .setFields("nextPageToken, files(id, name)")
                    .execute();
            lib.setgstatus(result.toString());
            List<File> files = result.getFiles();

            if (files != null) {
                lib.setgstatus("getDataFromApi files.size:" + files.size());
                for (File file : files) {
                    fileInfo.add(String.format("%s (%s)\n",
                            file.getName(), file.getId()));
                }
            }
            else
            {
                lib.setgstatus("getDataFromApi files is null");
            }

            lib.setgstatus("getDataFromApi Finish");
            return fileInfo;
        }

result.toString() Returns a valid JSON result, but files is null.

This is my build.gradle:

apply plugin: 'com.android.application'

    android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"

    defaultConfig {
        applicationId "org.de.jmg.jmgphotouploader"
        minSdkVersion 11
        targetSdkVersion 24
    }
    signingConfigs {
        release {
            keyAlias 'jmgphotouploader'
            keyPassword '****'
            storeFile file('/pub/keystore')
            storePassword '****'
        }
        debug {
            keyAlias 'jmgphotouploader'
            keyPassword '****'
            storeFile file('/pub/keystore')
            storePassword '****'
        }
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            //shrinkResources true
            //proguardFile 'proguard.cfg'
        }
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFile 'proguard.cfg'
            //proguardFile getDefaultProguardFile('proguard-android.txt')
            //proguardFiles getDefaultProguardFile('proguard-android.txt') ,'proguard.cfg'
        }
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile project(':src')
    compile project(':utilities')
    compile 'com.google.android.gms:play-services-auth:9.6.1'
    compile 'pub.devrel:easypermissions:0.1.5'
    compile('com.google.api-client:google-api-client-android:1.22.0') {
        exclude group: 'org.apache.httpcomponents'
        }
    compile('com.google.apis:google-api-services-drive:v3-rev47-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
        }

}
like image 732
Hans-Martin Goebel Avatar asked Oct 27 '16 16:10

Hans-Martin Goebel


1 Answers

Adding just

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

to proguard.cfg works!

like image 148
Hans-Martin Goebel Avatar answered Oct 20 '22 10:10

Hans-Martin Goebel