0

Can you please provide some guide how to create DriveQuickstart demo application (https://developers.google.com/drive/quickstart-android, steps 2-3) in Android Studio?

The problem is that Android Studio can't find com.google.api.* classes, like com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential. And I can't find it neither in google-play-services.jar, not in Android SDK folders.

I use "Compile with: Google APIs 17" in Android Studio, I downloaded all the latest updates in SDK manager (including Google APIs for API17, Google Play services, Google Repository).

According to http://developer.android.com/google/play-services/setup.html I added

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:4.1.+'
}

in build.gradle. What other actions should I perform to compile the sample source code, add some external library? You have provided great detailed steps for Eclipse, but said nothing about Android Studio with Gradle.

Zmiter
  • 298
  • 4
  • 15
  • Did you update Play Services to the latest version? The version you should require is 4.1.32. – Burcu Dogan Jan 20 '14 at 09:44
  • Sure, I did. It did not help, so I have to copy all necessary jars (the list is in my comment below) in the libs folder and use dependencies { compile fileTree(dir: 'libs', include: '*.jar') } – Zmiter Jan 20 '14 at 16:08
  • possible duplicate of [Android Studio 0.4.2 suddenly cannot resolve symbols](http://stackoverflow.com/questions/21100688/android-studio-0-4-2-suddenly-cannot-resolve-symbols) – Scott Barta Jan 24 '14 at 00:00

2 Answers2

3

Try adding this to project build.gradel,worked for me in android studio 0.4.3, sync and then optimize imports(Ctrl+Alt+O) in windows.

compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.1.32'
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'

Credits go to user @smokybob

bajo
  • 31
  • 2
2

In the Quickstart, did you follow all of the items in Step 2?

Specifically it looks like you missed out the last two (confusingly numbered 1 & 2 which install the Google Client Libs into your project. Open the "libs" folder in your project and check that you have a bunch of client libs such as "googleapi-client.jar".

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • Well, that step was for Eclipse plugin, and I am asking about Android Studio. I spent couple hours to figure out the necessary jars are: google-play-services.jar, google-api-client-1.17.0-rc.jar, google-api-client-android-1.17.0-rc.jar, google-api-services-drive-v2-rev111-1.17.0-rc.jar, google-http-client-1.17.0-rc.jar, google-http-client-android-1.17.0-rc.jar, google-http-client-gson-1.17.0-rc.jar. – Zmiter Jan 20 '14 at 16:00
  • Now the problem is that the execute() method cannot be resolved in File file = service.files().insert(body, mediaContent).execute(); The latest version of Drive.Files.Insert class does not have such method at all. What should I use instead? – Zmiter Jan 20 '14 at 16:06
  • The steps are required for all projects, so as you've found, you need to complete them, albeit differently for IntelliJ than for Eclipse. Adding the libraries by hand is error prone, so you'll need to carefully confirm you have the correct versions. You shouldn't add supplementary questions here in SO. Try asking your execute question as a new question. Nevertheless, the likely cause is that you have incorrect libraries in your project. – pinoyyid Jan 20 '14 at 16:20
  • Thanks for your help, I appreciate it. I'll ask about execute() in a separate question. Regarding the correct version of jar files, how can I figure it out? All I have is the latest version of Play Services and other packages in SDK Manager (no new updates available) and that sample application for Drive API v.2, that is it! Does it mean I should use #1.16#.jar file set? What syntax should I use with #1.17#.jar file set? What should I write in build.gradle if I don't want to manually grab the libraries? The documentation says nothing about these questions. – Zmiter Jan 20 '14 at 17:14
  • I really suggest asking this as a new question – pinoyyid Jan 21 '14 at 07:12