4

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!

kash
  • 830
  • 2
  • 7
  • 19
  • you need to check SHA1 Key for release and debug build , fetch the release SHA1 Key and update it on project info – Quick learner Sep 07 '18 at 04:44
  • 1
    you've tagged your question "google-api-java-client *and* "google-drive-android-api". These are not the same thing, so which are you using? – pinoyyid Sep 07 '18 at 07:02
  • @quicklearner I ensured that the SHA1 key is entered correctly for both debug and release builds. I added both keys. Are you allowed to use only one SHA1 key? – kash Sep 07 '18 at 10:03
  • 1
    you should delete the debug key and try again , make sure the key is correct for release build with project details – Quick learner Sep 07 '18 at 10:07

1 Answers1

4

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!

spectre10
  • 434
  • 1
  • 6
  • 13