Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google drive file.getId() is null only on release build

I am using Google Drive API V2 version to create a folder and upload a file into the folder. It works perfectly fine on a debug build, but on a release build, the file.getId() is null for the folder.

Here is the image of the untitled folder that it creates: https://ibb.co/fJMyAK

You can find complete documentation at: https://developers.google.com/drive/api/v2/folder

File fileMetadata = new File();
fileMetadata.setTitle("Invoices");
fileMetadata.setMimeType("application/vnd.google-apps.folder");

File file = driveService.files().insert(fileMetadata)
    .setFields("id")
    .execute();
System.out.println("Folder ID: " + file.getId());

I can see that the folder is being created on google drive, but it shows up as untitled.

I have gone into Google Api console, ensured that the release build keystore SHA1 key is entered correctly into api console and the package name is correct.

Any help on this would be appreciated!

like image 993
kash Avatar asked Sep 17 '25 21:09

kash


1 Answers

I ran into this problem as well. This happens due to proguard rules. It strips a class that is actually required. In order to fix it, add the following link to your proguard-rules.pro file.

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

Hope this helps!

like image 196
spectre10 Avatar answered Sep 20 '25 12:09

spectre10