Gmail API for Android SDK 21 - android

I am trying to develop using the Gmail API for Android for devices with API 21.
In this tutorial: https://developers.google.com/gmail/api/quickstart/android
It says I need to have:
Android SDK packages for API 23 or later, including the latest versions of Google Repository, Android Support Library and Google Play Services.
And the dependencies example there is:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'pub.devrel:easypermissions:0.1.5'
compile('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile('com.google.apis:google-api-services-gmail:v1-rev47-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
}
But I get an error when I use it saying I cant use:
com.android.support:appcompat-v7:23.4.0
When my compile SDK version is 21.
I've tried changing the appcompact version to v7:21.0.2 which worked for me before, but when I sync the gradle files I get the error:
Error:
Failed to resolve: com.android.support:appcompat-v7:23.1.1
Install Repository and sync project
Open File
Show in Project Structure dialog
But installing this repository will create the problem of the support library not matching the compile version.
Am I doing something wrong?

You can try to go to SDK manager and install three component: Google Repository, Android Support Library and Google Play Services.
like following picture:

Related

Android app not building with google services (Android Studio)

So I had a working version of an android app and I'm trying to add google sign in. I followed this:
https://developers.google.com/identity/sign-in/android/start-integrating
and after the "Add the Google Services Plugin" step:
Add the dependency to your project-level build.gradle: classpath 'com.google.gms:google-services:2.0.0-alpha5'
Add the plugin to your
app-level build.gradle: apply plugin: 'com.google.gms.google-services'
my app fails to build with the following error:
Failed to sync Gradle project '[my project name]' Error: Cause: failed
to find target with hash string 'Google Inc.:Google APIs:19' in:
C:\Users\SD\AppData\Local\Android\sdk
Any ideas/suggestions? I had a friend follow the same steps and had the same result.
Seems like you miss API 19.
I suggest you go to Tools - Android - SDK Manager or click on the SDK Manager icon and check if API 19 is installed.
I already had API 19 installed even though the error seems to indicate API19 is an issue. I switched to API 17 and that got rid of that error but caused some new ones.
These issues are probably related to the Sherlock library that is in my app conflicting with the GooglePlayer libraries. After switching to API 17 I resolved the other errors by removing the dependancy:
compile 'com.google.android.gms:play-services:7.0.0'
And adding the following:
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'
to the project's build.gradle.

Adding Google Play Services to gradle (Android Studio) does not work

I have the following problem:
I installed the Google Play Services library v27.0.0 to my SDK in Android Studio.
After that I added the compile dependencie to build.gradle (app folder):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.google.android.gms:play-services:27.0.0'
}
But when I try to sync the project with Gradle, i get this error message:
Error:(25, 13) Failed to resolve: com.google.android.gms:play-services:27.0.0
I don't know what to do...
I don't think version 27.0.0 exists the most recent version is 8.1.0
There is one trick you can use with any dependency.
You know the name of dependency, lets consider com.google.android.gms:play-services:
Firstly, you need to use this expression
compile 'com.google.android.gms:play-services:+'
Note the plus sign. Than you click Sync Now to sync gradle. After that you will see that IDE suggests you not to use + sign.
But now you can use combination Alt+Enter and select Replace with specific version.
Now + sign will be replaced with the latest available version of this library.
Profit.

The import com.google.android.gms.common.GooglePlayServicesClient [duplicate]

I am trying to migrate a project from Eclipse to Android Studio, the project can be build in Eclipse and was successful imported to Android Studio, however, I get Cannot resolve symbol 'GooglePlayServicesClient' error in Android Studio.
I followed the official tutorial to imported Google Play service in Android Studio, and an other package "com.google.android.gms.common.ConnectionResult" that used in my project does not have same issue. Only 'GooglePlayServicesClient' cannot be resolved.
I have also tried clean and rebuild my project, but the problem persists. What am I doing wrong?
Update:
My build.gradle
...
dependencies {
compile project(':libraryListViewAnimations')
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.android.gms:play-services:7.0.0'
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/commons-net-3.1-sources.jar')
compile files('libs/commons-net-3.1.jar')
compile files('libs/mail.jar')
}
GooglePlayServicesClient is obsolete and no longer included in the Google Play Services 7.x library. Google recommends using the GoogleApiClient instead.
See Accessing Google APIs in the Android developer docs:
"Note: If you have an existing app that connects to Google Play services with a subclass of GooglePlayServicesClient, you should migrate to GoogleApiClient as soon as possible."
Did you add compile 'com.google.android.gms:play-services:7.0.0' to build.gradle?
You can find more guide here . Hope this help.

Cannot resolve symbol 'GooglePlayServicesClient'

I am trying to migrate a project from Eclipse to Android Studio, the project can be build in Eclipse and was successful imported to Android Studio, however, I get Cannot resolve symbol 'GooglePlayServicesClient' error in Android Studio.
I followed the official tutorial to imported Google Play service in Android Studio, and an other package "com.google.android.gms.common.ConnectionResult" that used in my project does not have same issue. Only 'GooglePlayServicesClient' cannot be resolved.
I have also tried clean and rebuild my project, but the problem persists. What am I doing wrong?
Update:
My build.gradle
...
dependencies {
compile project(':libraryListViewAnimations')
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.android.gms:play-services:7.0.0'
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/commons-net-3.1-sources.jar')
compile files('libs/commons-net-3.1.jar')
compile files('libs/mail.jar')
}
GooglePlayServicesClient is obsolete and no longer included in the Google Play Services 7.x library. Google recommends using the GoogleApiClient instead.
See Accessing Google APIs in the Android developer docs:
"Note: If you have an existing app that connects to Google Play services with a subclass of GooglePlayServicesClient, you should migrate to GoogleApiClient as soon as possible."
Did you add compile 'com.google.android.gms:play-services:7.0.0' to build.gradle?
You can find more guide here . Hope this help.

How to import Google API in Android Studio

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?
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
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.
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
Did you try
Go to Project Structure > Global Libraries / Libraries > Link to the jar of the API you need in the SDK folder
Link the library with your module
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.
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
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.+'
}

Categories

Resources