1

I am experiencing an infuriating bug with the Google Drive API for Android. Specifically, in presenting an "Open File from Google Drive" UI to the user, I am querying for the files in a folder using the following code:

String query = "'" + folderId + "' in parents and trashed = false";

Files.List request = service.files().list().setQ(query);

FileList files = request.execute();

java.util.List<File> items = files.getItems();  // Returns null!

When I run this code directly from Eclipse (i.e. signed with the debug certificate), there is no problem. However, when I build and run a signed APK using our release certificate, the call to files.getItems() returns null.

Oddly, while getItems() returns null, there is definitely data returned from the Drive server, because calling files.toString() shows a mess of Json, amongst which I have identified the filenames of a few of my files, so I don't think the problem is an authentication issue.

Also, using different folderIds in the query string does not seem to make any difference to the Json returned by toString(). Based on aggressive GC activity in logcat, it looks like the server might be returning ALL files in my drive, especially odd considering getItems() returns null.

Note that the code works absolutely fine when signed with the debug certificate, as I am able to browse my Google Drive perfectly from within my app.

Joel Malone
  • 1,214
  • 1
  • 12
  • 20
  • 1
    Any chance Proguard kicks in when exporting your signed APK? If you rely on i.e. variable names to map the JSON onto POJOs, this is likely to brake without the appropriate Proguard exclusions/rules. Have a look in your `project.properties` file and comment out any line in the form of `proguard.config=`. After that, export another signed APK and retest. – MH. Oct 08 '13 at 07:03
  • Is your scope drive.file? If you have created the files with your debug app, they cant be accessed from the prod because ownership belongs the the debug one. – Burcu Dogan Oct 08 '13 at 12:24
  • can you paste the "mess of Json" – pinoyyid Oct 08 '13 at 17:25
  • @BurcuDogan Scope is https://www.googleapis.com/auth/drive to allow full browsing; the files were inserted into Drive using the web interface, our app doesn't upload files. – Joel Malone Oct 09 '13 at 04:13
  • @MH it definitely seems to be a Proguard thing! I added some lines to proguard.config and now the release build works fine. Thank you very much - please post your comment as an answer and I'll accept it. For reference, the lines added are those outlined here: http://stackoverflow.com/a/14504602/246901 – Joel Malone Oct 09 '13 at 04:39
  • Also note that the fix is broad, and I'm not experienced enough with Proguard to understand it. I will do some reading, and if I can be any more precise, will report back to this thread. – Joel Malone Oct 09 '13 at 04:40
  • @JoelMalone: Glad to hear to worked for you. It's a common problem, and easily overlooked because the default settings enable Proguard for signed applications (only). Anyways, please find my earlier comment as answer below. :) – MH. Oct 09 '13 at 06:20

1 Answers1

0

As per earlier comment:

Any chance Proguard kicks in when exporting your signed APK? If you rely on i.e. variable names to map the JSON onto POJOs, this is likely to brake without the appropriate Proguard exclusions/rules. Have a look in your project.properties file and comment out any lines in the form of proguard.config=<file_name>. After that, export another signed APK and retest.

MH.
  • 45,303
  • 10
  • 103
  • 116
  • Proguard was indeed the culprit. I resolved the issue by applying the fix outlined here: http://stackoverflow.com/a/14504602/246901. – Joel Malone Oct 09 '13 at 06:52