I'm trying to read data from my SpreadSheet in the Google Drive; under Debug mode (with minifyEnable false) is working, but for the Release version (with minifyEnable true) the response body is null (although the response code for both is 200).
I've already checked these questions but nothing have worked on my side yet:
- 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
My gradle looks like this:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-.txt'), 'proguard-rules.pro'
debuggable false
}
debug {
minifyEnabled false
debuggable true
versionNameSuffix "_debug"
}
}
The proguard contains:
-keep class com.google.** { *;}
-keep class com.google.api.services.drive.** { *;}
-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}
The API Call is a GET request to https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/Sheet1!A1:Z1000?key={myKey}
When obfuscation is false the body response from Sheets API is:
{
"range": "Sheet1!A1:Z1000",
"majorDimension": "ROWS",
"values": [
array
]
}
When obfuscation is true:
{
"range": null,
"majorDimension": null,
"values": null
}
Can you see what I'm missing? Thanks.
[EDITED] The class for the response:
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;
}
}
The API call:
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);
}
});
}