How do I compile against Google APIs with gradle? - android

Unfortunately I have an app stuck using the maps v1 APIs and need to compile the app against the Google APIs. I am using a newer version of the android gradle plugin (com.android.tools.build:gradle:0.9.+) as well as gradle 1.10. I am attempting to compile against Google APIs 16 and getting this error:
Could not determine the dependencies of task ':compileReleaseJava'.
> failed to find target Google Inc.:Google APIs:16
In older versions (i.e. gradle 1.8 with gradle plugin com.android.tools.build:gradle:0.6.+) I could do this in my build.gradle file:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
android {
compileSdkVersion "Google Inc.:Google APIs:16"
// rest of gradle file here
}
and it worked fine. However, if I set my compileSdkVersion to 16, I get compile errors because of all the v1 map apis my app is using. Is there a way to compile against the google apis with the newer gradle plugin like this?

The error just looks like you did not download the Google API add-on for API 16.

Run Android SDK Manager then delete all content from API 16 and redownload it.

Related

With upgrade to Android Studio 3.5 now get error: package com.google.android.maps does not exist

I have a project using the long since deprecated Maps V1 API, on which I have put in a lot of work and I need it.
I have just upgraded Studio to 3.5 and my current version for which I accepted the recommendations to upgrade the gradle plugin and gradle to versions 3.5.0 and 5.4.1 can't find the maps package on line such as:
import com.google.android.maps.GeoPoint;
Fortunately I have a previous version which barely differs and I didn't accept the upgrade recommendations for the plugin and gradle. The versions are 3.4..2 and 5.1.1. It builds successfully.
The relevant parts of my build.gradle (which is the same for both projects) are:
apply plugin: 'com.android.application'
android {
signingConfigs {
...
}
compileSdkVersion 'Google Inc.:Google APIs:15'
//compileSdkVersion 15
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "uk.co.secret.gridmaps"
minSdkVersion 8
targetSdkVersion 10
}
}
dependencies {
implementation 'org.osmdroid:osmdroid-android:5.2#aar'
// NBT TRY 26 AUGUST 2019
//implementation 'com.google.android.gms:play-services.maps:15.0.0'
}
Uncommenting the last line (as suggested in similar questions) doesn't help either:
ERROR: Failed to resolve: com.google.android.gms:play-services.maps:15.0.0
All suggestions will be gratefully received.
UPDATE 19:00 GMT
I can fix this in a very dirty hard-coded way by adding the line
implementation files ('libs/googleapi21maps.jar')
to the dependencies section of build.gradle. That jar file is just a renamed version of C:\dev\tools\android-sdk-windows5.0\add-ons\addon-google_apis-google-21\lib\maps.jar from my old Windows eclipse project
Given that maps API V1 is dead, it does no harm but it's not elegant at all.
Also given that gradle 5.1.1 can find the package without resorting to this inelegant method, why can't gradle 5.4.1?
Update 2
It builds OK but when I invoke an activity that uses the android.maps, it crashes with an IncompatibleClassChangeError. I changed the version of the libs.jar to 15 with no improvement.
I need to make the latest gradle have backward compatibility with legacy code, even if I have to give an explicit reference to the library that gradle 5.1.1 retrieved.
The compileSdkVersion looks stange, that should be eg. 28 (or 29).
And the current play-services-maps version is 17.0.0:
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation "com.google.android.gms:play-services-maps:17.0.0"
mavenCentral() also has a newer version of osmdroid-android:
// https://mvnrepository.com/artifact/org.osmdroid/osmdroid-android
implementation "org.osmdroid:osmdroid-android:6.1.0"

Failed to resolve: com.google.firebase:firebase-core:9.0.0

I get the following error while upgrading a firebase project from old domain to new google firebase domain.
Failed to resolve: com.google.firebase:firebase-core:9.0.0
I followed the steps mentioned on the Firebase documentation, in the section Add Firebase to your Android Project, topic Available libraries.
What are my options to resolve this error?
Update Aug 2017
As of version 11.2.0 Firebase and Google Play services dependencies are available via Google's Maven Repo. You no longer need to use the Android SDK manager to import these dependencies.
In your root build.gradle file add the repo:
allprojects {
repositories {
// ...
maven { url "https://maven.google.com" }
}
}
If you are using gradle 4.0 or higher you can replace maven { url "https://maven.google.com" } with just google().
The 9.0.0 version of Firebase was built using Google Play services 9.0 and is now available under the new packaging com.google.firebase:*
See Release Notes for Google Play services 9.0
https://developers.google.com/android/guides/releases#may_2016_-_v90
New versions of packages Google Play Services (rev 30) and Google Repository (rev 26) were just released in the SDK manager so it's likely you just need to update.
Downloading Google Play Services and Google Repository
From Android Studio:
Click Tools > Android > SDK Manager.
Click into the SDK Tools tab.
Select and install Google Play Services (rev 30) and Google Repository (rev 26). See the image below.
Sync and Build your project.
From IntelliJ IDEA:
As of April 2017, the latest versions of Google Play Services and Repository are listed below.
Click Tools > Android > SDK Manager.
Under the Packages panel, Look for the Extras.
Select and install Google Play Services (rev 39) and Google Repository (rev 46). See the image below.
Perform a gradle project sync and Build your project.
Go to Android SDK Manager and install the latest version of below two libraries
Google Play Services
Google Repository
Error:(30, 13) Failed to resolve: com.google.firebase:firebase-auth:9.6.1
If you ever get this error and you are using Android studio 2.2 that comes with firebase component integrated in it which has libraries version 9.6.0 by default and you are adding the latest dependencies like 9.6.1 . You might need to downgrade com.google.firebase:firebase-auth:9.6.1 to com.google.firebase:firebase-auth:9.6.0
Or check the library version of your pre-installed firebase and make sure it is of the same version with the new library you are trying to add or added to your project.
Tried all the above, use the Firebase Assistant! It is the simplest way to solve this. First remove all the dependencies you added to the build.gradle (using the manual method) and then in Android Studio:
Click Tools > Firebase to open the Assistant window.
It really is as easy as that.
Faced myself and seen several times in comments for similar questions - that even after installing "latest" Google Play Services and Google Repository still having the same issue.
The thing is that they may be latest for your current revision of Android SDK Tools, but not that latest your app build requires.
In such case make sure to install latest version of Android SDK Tools first, and probably Android SDK Platform-tools (both under Tools branch). Also please note you may need to go through this several times if you haven't updated for a long time (i.e. install latest Android SDK Tools and Android SDK Platform-tools, then restart Android SDK Manager, then repeat), since the updates seem to be going through some critical mandatory milestones and you cannot install the very latest if you currently have the revision which is pretty "old".
dependencies {
compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.android.gms:play-services-auth:11.8.0'
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile 'com.google.firebase:firebase-storage:11.8.0'
}
apply plugin: 'com.google.gms.google-services'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
Following are the prerequisites if you want to add firebase to your project.
For working with Firebase you should install Android Studio 1.5 or higher.
Download the latest Google Play services SDK from through Android SDK Manager.
The device should be running Android 2.3 (Gingerbread) or newer, and Google Play services 9.2.0 or newer.
I could only find out all this after hours of struggle.
Source: Adding Firebase to your Android App
If using command line tools, do
sdkmanager 'extras;google;m2repository'
sdkmanager 'extras;android;m2repository'
Need to Update
Android SDK : SDK Tools -> Support Repository -> Google Repository
After updating the Android SDK need to sync gradle build in Android studio.
In my case, on top of adding google() in repositories for the project level gradle file, I had to also include it in the app level gradle file.
repositories {
mavenLocal()
google()
flatDir {
dirs 'libs'
}
}
If all the above methods are not working then change implementation 'com.google.firebase:firebase-core:12.0.0' to implementation 'com.google.firebase:firebase-core:10.0.0' in your app level build.gradle file.
This would surely work.
I tried all the solutions and nothing worked for me. Changing gradle version worked for me.
I changed following inside gradle-wrapper.properties
from
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
Update October 2022
com.google.firebase-core has been deprecated in October 2022. Instead of firebase-core, use firebase-analytics or firebase-analytics-ktx.
The firebase-core library is deprecated and no further versions will
be released. This SDK included the Firebase SDK for Google Analytics.
Now, to use Google Analytics or a product that recommends adding
Google Analytics, you need to explicitly declare the Analytics
dependency: com.google.firebase:firebase-analytics or
com.google.firebase:firebase-analytics-ktx.
Release notes

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.

Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed

I just updated Google play services to the latest release - 23 - in the Android SDK Manager. Next I updated dependency in my project to:
com.google.android.gms:play-services-gcm:8.3.0
But I got:
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
:app:processDebugGoogleServices FAILED
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict.
What is wrong? Do you have this problem also?
In your top-level build.gradle file you need to update the dependencies to use
classpath 'com.google.gms:google-services:1.5.0-beta2'
Extra Info:
The latest version of this can be found by looking at the entry on JFrog Bintray
Further Update:
Yes this has been updated since I answered the question. The latest version is:
classpath 'com.google.gms:google-services:3.0.0'
However, it's always worth following the provided link to find the latest version.
Working solution for 8.4.0 (maybe same for previous versions too with this crazy issue)
project build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:2.1.2'
}
app/mobile build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'
android {
...
...
...
}
dependencies {
// Google Play Services
compile 'com.google.android.gms:play-services-analytics:8.4.0'
// another play services in v8.4.0
}
apply plugin: 'com.google.gms.google-services' // why here on end? Because GOOGLE...
WARNING:
When you move apply plugin: 'com.google.gms.google-services' on top of build gradle, it can not compile...
The Google Play Services guides saved me from this problem
According to the guide,
In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.
From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:8.4.0'
with these lines:
compile 'com.google.android.gms:play-services-fitness:8.4.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'
I encountered this issue as well, although mine was
Found com.google.android.gms:play-services-gcm:8.4.0, but version
8.3.0 is needed
To fix, I combined Jeff Sutton and mtrakal's answers. I had to make sure I was using the latest Gradle plugin and Google Services versions in the project-level Gradle file (I had Gradle 1.5 and it didn't work):
classpath 'com.google.gms:google-services:2.0.0-beta6'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
Then I put the apply plugin: 'com.google.gms.google-services' line in the last line of the app Gradle file.
In your top-level build.gradle file you need to change the dependencies to
classpath 'com.google.gms:google-services:+'
I am also getting the same of conflict com.google.android.gms:play-services-gcm:8.3.0 then
I have updated the google playservice tool then it has been resolved
From the SDK manager selected the tool and update now it resolve

Android Gradle project sync failed due to target version

Since a new API of Android 6.0 is available in SDK Manager a hint was appeared in application level build.gradle file to update
FROM
androidTestCompile 'com.android.support:support-annotations:22.0.1'
compile 'com.android.support:appcompat-v7:22.0.1'
TO
androidTestCompile 'com.android.support:support-annotations:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
I haven't downloaded new update from sdk manager for Android 6(API 23) yet but still changed the following details as shown below,
BEFORE
compileSdkVersion 22
buildToolsVersion "22.0.1"
targetSdkVersion 22
androidTestCompile 'com.android.support:support-annotations:22.0.1'
compile 'com.android.support:appcompat-v7:22.0.1'
AFTER
compileSdkVersion 23
buildToolsVersion "23.0.0"
targetSdkVersion 23
androidTestCompile 'com.android.support:support-annotations:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
As I haven't downloaded new API 6.0 yet, following error occurred
Error:Cause: failed to find target with hash string 'android-23' in: C:\Users\DRONE\AppData\Local\Android\sdk
So now again I changed the setting in application level build.gradle file as what it was before, but the error is not being resolved.
Same error is occurring.
How do I solve this now?
Normally it is caused by not having API 23.
After updating the SDK to the newer version, it often rewrites build.gradle to the highest API version SDK provided even if you didn't upload it.
The easiest way - download API 23.
I think it may caused by you don't have 23 API, Go to Tools > Android > SDK Manager and check to see if API-23 is installed.
Try to add a "+" for example:
compile 'com.android.support:appcompat-v7:23.+'
You have also to update your Android Studio APIs (as Kun said).
Yes as others have mentioned you need to install API-23 through the SDK Manager but it's a long list of downloads and if you don't want to install all of them right away, you can just install the one named "SDK Platform" under API-23

Categories

Resources