Search code examples
androidgoogle-drive-apigoogle-drive-android-api

Keep using the old Google Drive API on Android


I have an existing app which I have unfortunately haven't had time to update it in quite a long time. I am now trying to do some work on it but it won't compile.

It was originally an Eclipse project so I've now imported it into Android Studio, my build.gradle has the following:

dependencies {
    /*compile 'com.google.android.gms:play-services-ads:7.0.0'
    compile 'com.google.android.gms:play-services-drive:7.0.0'
    compile 'com.google.android.gms:play-services-identity:7.0.0'*/
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/android-support-v4.jar')
    compile files('libs/commons-codec-1.4-javadoc.jar')
    compile files('libs/commons-codec-1.4-sources.jar')
    compile files('libs/commons-codec-1.4.jar')
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.android.support:support-v4:21.0.0'
    compile 'com.BoardiesITSolutions:CritiMon:1.0'
    compile 'com.BoardiesITSolutions:Library:1.1'
    compile 'com.google.android.gms:play-services:4.1.+'
    compile('com.google.api-client:google-api-client-xml:1.17.0-rc') {
        exclude group: 'com.google.android.google-play-services'
    }
    compile 'com.google.http-client:google-http-client-gson:1.17.0-rc'
    compile('com.google.api-client:google-api-client-android:1.17.0-rc') {
        exclude group: 'com.google.android.google-play-services'
    }
    compile 'com.google.apis:google-api-services-drive:v2+'
}

I am trying to point it at the old versions of Google Play Services, the bit of code below which was originally working but now it no longer is.

Drive service = getDriveService(credential);

                    String fileId = null;
                    FileList file = service.files().list().execute();

The problem is services.files() cannot be resolved.

I am assuming this is because of the Drive API being updated so is there a way that I can use the previous version that supports the above code.

At the moment I don't have time to update the Drive API but I need to fix a bug that someone's reported.

Update

I've found the following https://developers.google.com/drive/web/migration page which says that there aren't any real changes apart from a variable name for the file id but everything is the same so I don't understand why the service.files() function wouldn't be found.


Solution

  • To consolidate the comments (esp @kroikie) into an answer, you have confused the Java library for the REST API (which can run on Java/Android and is represented by com.google.api.services.drive.Drive) with the Google Drive API for Android ("GDAA" - which simply reads and writes to the Drive storage area on Android and lets the Android Drive app do the syncing, and is represented by com.google.android.gms.drive.Drive).

    This guy The method permissions() is undefined for the type Drive has done the same thing, which suggests that the Google documentation is failing to make it clear that there are two different ways that Android-Drive integration can be achieved. I've seen people refer to the REST API as the "old api", which is a complete misnomer and suggests that some people have drawn the false conclusion that GDAA replaces the REST API which it most certainly doesn't.

    So in your case, expunge com.google.android.gms.* from your app and you'll be fine.