用proguard文件()缩小我的发布apk后,list()不返回文件(在调试模式下)。我使用快速入门示例进行登录。没有错误消息。登录似乎很成功。
这是我的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 *;
}
这是检索文件的代码:
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()返回有效的JSON结果,但文件为空。
这是我的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'
}
}
答案 0 :(得分:8)
只添加
-keep class * extends com.google.api.client.json.GenericJson {
*;
}
-keep class com.google.api.services.drive.** {
*;
}
到proguard.cfg工作!
答案 1 :(得分:1)
检查此相关issue。
Proguard在导出您签名的APK时会有什么机会?如果您依赖变量名称将JSON映射到POJO,则可能会在没有适当的Proguard排除/规则的情况下制动。查看
project.properties
文件并注明proguard.config=<file_name>
形式的任何行。之后,导出另一个已签名的APK并重新测试。
请确保将minifyEnabled true
添加到build.gradle
文件中的相应构建类型,以使用documentation中所述的ProGuard缩减代码。