Android studio build gradle sync failed - android

I am trying to add google play service to my project but it gives me error when I try to edit build (Gradle).
How can I fix it?

In your configuration there some issues.
You are using the wrong build.gradle file.
It is your top-level file.
You should add this line in your app/build.gradle
There is a typo. You are missing the ' at the end of the line compile.
Use an updated version.
For example use:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.google.android.gms:play-services:8.1.0'
}
Finally refer this official doc for more info.
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.
For example if you need to make only your app aware of location updates add
compile 'com.google.android.gms:play-services-location:8.1.0' only in gradle or if you need only map choose compile 'com.google.android.gms:play-services-maps:8.1.0'.

Please replace
compile 'com.google.android.gms:play-services:3.1.36
with
compile 'com.google.android.gms:play-services:3.1.36'

One thing you can try is Right Click on app open module settings on Dependencies Tab click '+' icon and add there 'com.google.android.gms:play-services:8.1.0' and click search icon and add that dependency,

So i don't want to elaborate what you had done wrong as my colleagues figured it out.I like to say, while playing with Google Play Service
Selectively compile APIs into your executable
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.
For example if you need to make only your app aware of location
updates add compile
'com.google.android.gms:play-services-location:8.1.0' only in gradle
or if you need only map choose compile
'com.google.android.gms:play-services-maps:8.1.0'.
Thank you.
Visit for more.

Related

Android studio automatically tries to update libraries?

In my project I have many libraries defined in dependencies section in gradle. Problem is once in a while (once/twice a day)Android Studio gives me errors like this when opening the project or trying to get a release output:
Error:Unable to resolve dependency for ':TMessagesProj#armv7Debug/compileClasspath': Could not resolve com.google.android.gms:play-services-gcm:11.2.+.
My guess is it is because build tools is trying to check if there is an update for each library and when it doesn't find an Internet connection, it shows this error. If so, how can I change the setting in a way it doesn't have to check for updates? In other words in my project I don't need to update my libraries.
I know there is an offline mode that will probably do the trick! But I don't want to use this feature because it will probably disable some other useful features too. I just want to prevent it from automatically checking for library updates(If that's the problem shown above).
I included some part of my dependencies in gradle here:
dependencies {
compile 'com.google.android.gms:play-services-gcm:11.2.+'
compile 'com.google.android.gms:play-services-maps:11.2.+'
compile 'com.google.android.gms:play-services-vision:11.2.+'
compile 'com.google.android.gms:play-services-wallet:11.2.+'
}
Dependencies with a plus like 11.2.+' will always lead to repeated builds.
You have to specify the full version like:
com.google.android.gms:play-services-gcm:11.2.0
If you do not specify gradle will always be building because its looking for the latest version online of 11.2.+ may be 11.2.4, 11.2.6 etc

Android Studio Google Maps dependencies

Android Studio and Google Maps dependencies have finally defeated me. I did have it working but had to change some things to get my app to use the correct API Key.
Now I click on run and it say's build successful, but it doesn't actually run the project on the simulator and it puts a whole load of red circles with white exclamation marks in the messages window. Nothing happens if you click on those circles and there's no explanation as to what they mean.
I've a feeling it's saying there are dependencies of the dependencies I've included but I've moved away from individual Play service includes and included the whole lot, with the whole support library and still nothing happens.
Can anyone tell me what's going on, or how I can fix this, or even where I look next to find out why this won't run.
These are my dependencies in my build.gradle.
dependencies {
compile files('libs/jackson-annotations-2.9.0.jar')
compile files('libs/jackson-databind-2.9.0.jar')
compile files('libs/jackson-core-2.9.0.jar')
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.android.support:appcompat-v7:25.2.0'
}
apply plugin: 'com.google.gms.google-services'
This is the error
This is where it says the build was successful
Thanks
Change compile 'com.google.android.gms:play-services:11.0.4' to compile 'com.google.android.gms:play-services-maps:11.8.0' // you dont need use all play-services
And try again!
I think that you have a dependency conflict, i suggest in this case to use the version 11.0.2:
compile 'com.google.android.gms:play-services:11.0.2'
btw, loading all the Play Services Library is not necessary to use Google Maps,
use only this dependency:
compile 'com.google.android.gms:play-services-maps:11.0.2'

What is the best way to add Google Play Service dependencies on Android Studio?

I have added Google Play Service dependencies to Android Studio.
I want something that works today and in the near future, something that keeps my app code up to date, without having to worry about every new Play service release, if possible.
Currently, I have this:
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
}
Is this the best way to add Google Play Service dependencies on Android?
You can use the following to always build against the latest available Google Play Services version:
compile 'com.google.android.gms:play-services:+'
However you will get a warning from Android Studio indicating that your builds are potentially non-repeatable and your code may break at any time (and you may not know why) due to changing versions behind the scenes. It's a trade-off. For a little more control you can use one of these:
compile 'com.google.android.gms:play-services:7.+'
compile 'com.google.android.gms:play-services:7.5.+'

Execution failed for task ':packageAllDebugClassesForMultiDex'

I am try to use the new android multidex support for a project. I have some problem with this exception:
Error:Execution failed for task ':shineV3:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/google/android/gms/analytics/internal/Command$1.class
about the problem. I use 2 different jar package as dependency, and some class will be duplicated in classes.dex because both jars contains they. any idea?
thanks in Advance
For those that are coming into this, I figured out why this was happening. For me it was that I was compiling the Google Analytics V2 jar as well as the full play services. Google allows you to break down what play services you really need for you app and compile those individual items. Check them out here. I excluded the Google Play Analytics which is on V4 right now and it worked
If you are integrating Google Analytics V2 and Google play services in your app, then you need to do the following in your gradle file:
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile files('libs/libGoogleAnalyticsServices.jar')
}
It worked for me. Hope it will work for others too. :)
adding this to your grdale compile "com.google.android.gms:play-services:7.5.+" means adding all play services including analytics, maps, vcm .. etc. you can add
as guides mentions:
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:7.5.0' with these lines:
compile 'com.google.android.gms:play-services-fitness:7.5.0' compile
'com.google.android.gms:play-services-wearable:7.5.0'
https://developers.google.com/android/guides/setup

How can I determine the version of Google Play services?

I am migrating from Eclipse to Android Studio. I have a project that I imported into Android Studio that uses Google Play Services, so I am following the documentation I found here: http://developer.android.com/google/play-services/setup.html
This documentation says that I need to edit my build.gradle file. They give the example:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Also the documentation mentions, "Be sure you update this version number each time Google Play services is updated.", which I assume is 6.5.87 in the above example. So how do I determine the "version" Google Play Services I have installed with my Android SDK manager. Here is a screen shot of my android sdk:
So my Android SDK Manager tells me I have installed "Revision" so what do I put in my build.gradle file?
compile 'com.google.android.gms:play-services:6.5.22'
... or maybe ...
compile 'com.google.android.gms:play-services:22'
Any help appreciated!
UPDATE: Thank you for all your answers.
I was able to find the version like so:
Leila001#win8 ~/Windows_Home/AppData/Local/Android/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/res/values
$ cat version.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="google_play_services_version">6587000</integer>
</resources>
You have the right idea by checking to make sure you do not have any updates.
The easiest way to check is simply when you have the latest downloaded in the Android SDK(locally).
I am using Mac OSX:
~/android-sdk/extras/google/m2repository/com/google/android/gms/play-services/
If you look where you have YOUR-ANDROID-SDK/extras/google/m2repository/com/google/android/gms/play-services/, you will see all the versions downloaded that you have.
The latest one being 6.5.87. (compile 'com.google.android.gms:play-services:6.5.87')
For you, the directory path on Windows would be:
C:\Users\Leila001\AppData\Local\Android\extras\google\m2repository\com\google\android\gms\play-services
You can see which version you have in project structure - dependecies - click on plus in right cornner - libary dependencies
and just add it to build.gradle with click or manually:
compile 'com.google.android.gms:play-services:6.5.87'

Categories

Resources