16

I'm trying out Android Studio. I want to use Drive API in my project. In eclipse, there is a Google Plugin for Eclipse, but how about Android Studio? Does anyone tried it so far?

Ali Afshar
  • 40,967
  • 12
  • 95
  • 109
bianca
  • 7,004
  • 12
  • 43
  • 58

7 Answers7

7

Bellow you can find last versions for Google Drive (2014.12.28):

//Google Drive API
compile 'com.google.android.gms:play-services:6.5.+'
compile 'com.google.api-client:google-api-client-xml:1.18.0-rc'         
compile 'com.google.http-client:google-http-client-gson:1.18.0-rc'
compile 'com.google.api-client:google-api-client-android:1.18.0-rc'
compile 'com.google.apis:google-api-services-drive:v2-rev155-1.19.0'

To check last version try following links:

https://developer.android.com/google/play-services/setup.html

https://code.google.com/p/google-api-java-client

https://developers.google.com/api-client-library/java/apis/drive/v2

http://mvnrepository.com/artifact/com.google.apis/google-api-services-drive

Michal
  • 2,071
  • 19
  • 30
4

I was in the same situation and had to find here an there information on how Gradle works to find the right set of dependencies and exclude needed. Here the lines needed in the dependencies of your build.gradle file

// Replace 'dependencies' in your build.gradle file with the following 
// or add these to whatever other dependencies you have.

dependencies {
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.google.android.gms:play-services:4.0.30'
    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-rev105-1.17.0-rc'
}

As they keep changing in time, I've made a gist that I'll keep updated as things changes.

I've wrote an article to modify the Google Drive Quick Start to make it work with Android Studio; if interested you can find it here

EDIT: This Gradle Imports are to use the Google Drive API for Java, not the Developer Preview Google Drive API integrated with the Google Play Services.

smokybob
  • 663
  • 6
  • 13
3

The Java client library supports Android, as well. You can download it here: https://code.google.com/p/google-api-java-client/wiki/APIs#Drive_API

Then, unzip the Drive SDK download and move the folder into the libs section of your Project. For example: /Users/-username-/AndroidStudioProjects/MyProject/MyProjectActivity/libs/

At this point, you can add the library to your project by clicking File -> Project Structure, and then clicking the Libraries tab, and the + sign to add the SDK into your project.

You can read the Android-specific development instructions for the Google API Client Library for Java here: https://code.google.com/p/google-api-java-client/wiki/Android

Joanna
  • 2,176
  • 11
  • 16
  • This the answer! Do not copy google api jars into your project!! Manage your sdk seperatly from your app, that way you can update the sdk and point to a new api level without having to copy a jar into your libs folder. – speedynomads Jul 24 '13 at 10:57
2

Did you try

  1. Go to Project Structure > Global Libraries / Libraries > Link to the jar of the API you need in the SDK folder
  2. Link the library with your module
Ethan
  • 1,616
  • 14
  • 8
1

I haven't tried google driver, but I tried google usb accessory api. In my case Open MyProject/MyProject/build.gradle

add

compile files("libs/usb.jar")

to the dependencies block

Of course, copy the google driver libs from

   android-studio\sdk\add-ons\addon-google_apis-google-10\libs\usb.jar

to MyProject/MyProject/libs

Good luck to you.

Alex Chan
  • 1,116
  • 3
  • 15
  • 33
0

smokybob's answer worked but then I did some experiments and this also worked for me.

dependencies { 
    compile files ('libs/libGoogleAnalyticsServices.jar')
    compile ('joda-time:joda-time:2.3')
    compile ('com.google.code.gson:gson:2.2.4')
    compile 'com.google.android.gms:play-services:4.1.+'
}

I am guessing the joda-time and Gson have nothing to do with the drive API.

Note when I do a

gradle dependancies

I get

+--- joda-time:joda-time:2.3
+--- com.google.code.gson:gson:2.2.4
\--- com.google.android.gms:play-services:4.1.+ -> 4.1.32
     \--- com.android.support:support-v4:19.0.1
Marc
  • 1,159
  • 17
  • 31
0

From the Extra's under the SDK manager, I downloaded Google Play Services, Google Repository and Android Support Library. Thereafter, I included dependency as below, sync'd with Gradle and was able to access the APIs.

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) // Pls. install or update the Google Repository through the SDK manager to use this dependency. compile 'com.google.android.gms:play-services:5.0.+' }