我正在尝试从Google云端硬盘中的SpreadSheet读取数据;在Debug模式(minifyEnable为false)下可以正常工作,但对于Release版本(minifyEnable为true),响应主体为null(尽管两者的响应代码均为200)。
我已经检查了以下问题,但对我而言仍然没有任何帮助:
-How to fix Proguard issue with Google Drive REST API。
-Google Drive API is not working after Proguard obfucation。
-How to make R8 + proguard-android-optimize.txt + Google Drive API works seamlessly?。
-Obfuscation (minifyEnabled true) not working in Debug and Release。
-GMail API not working properly when minifyEnabled=true
我的gradle像这样:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-.txt'), 'proguard-rules.pro'
debuggable false
}
debug {
minifyEnabled false
debuggable true
versionNameSuffix "_debug"
}
}
保护者包含:
-keep class com.google.** { *;}
-keep class com.google.api.services.drive.** { *;}
-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}
API调用是对https://sheets.googleapis.com/v4/spreadsheets/ {spreadsheetId} / values / Sheet1!A1:Z1000?key = {myKey}的GET请求
混淆混淆为假时,Sheets API的主体响应为:
{
"range": "Sheet1!A1:Z1000",
"majorDimension": "ROWS",
"values": [
array
]
}
当混淆为真时:
{
"range": null,
"majorDimension": null,
"values": null
}
您能看到我所缺少的吗?谢谢。
[编辑] 响应的类:
public class SpreadsheetResponse {
private String range;
private String majorDimension;
private List<List<Object>> values;
public String getRange() {
return range;
}
public void setRange(String range) {
this.range = range;
}
public String getMajorDimension() {
return majorDimension;
}
public void setMajorDimension(String majorDimension) {
this.majorDimension = majorDimension;
}
public List<List<Object>> getCitiesList() {
return values;
}
public void setCitiesList(List<List<Object>> values) {
this.values = values;
}
}
API调用:
public static void GoogleSheetAPI(final ResponseListener responseListener) {
String spreadSheet = SPREADSHEET_ID;
String range = "Sheet1";
String key = GOOGLE_PLACE_API_KEY;
mResponseListener = responseListener;
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://sheets.googleapis.com/v4/")
.addConverterFactory(GsonConverterFactory.create(getGsonInstance()))
.build();
APIservice requestInterface = retrofit.create(APIservice.class);
Call<SpreadsheetResponse> call = requestInterface.getSpreadSheet(spreadSheet, range, key);
APIH.enqueueWithRetry(call, new Callback<SpreadsheetResponse>() {
@Override
public void onResponse(Call<SpreadsheetResponse> call, Response<SpreadsheetResponse> response) {
SpreadsheetResponse jsonResponse = response.body();
if (jsonResponse != null)
mResponseListener.responseListener(SUCCESS, jsonResponse);
else
mResponseListener.responseListener(FAILURE, null);
}
@Override
public void onFailure(Call<SpreadsheetResponse> call, Throwable t) {
mResponseListener.responseListener(FAILURE, null);
}
});
}