Im working on simple map app, I added google-play-services.jar and its reference to gradle
dependencies {
compile files('libs/android-support-v4.jar', 'libs/google-play-services.jar')
}
The main activity:
setContentView(R.layout.activity_mapui);
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
layout file
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
But the app crashes on the device
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable at
com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown
Source) at com.google.android.gms.maps.MapFragment.onInflate(Unknown
Source)
I tried several ways, same issue, I just want to add google services to Android Studio 0.3 with Gradle 0.6+
Add this line in the dependencies section of your build.gradle file:
compile 'com.google.android.gms:play-services:3.2.+'
You don't need to add a .jar to your libs folder.
Edit
As Varun pointed out, you also need to update the SDK to contain the most recent version of the play services.
You can do this by opening up the Android SDK Manager (under the Window tab) from Eclipse+ADT, checking the box next to Google Play services in the Extras folder, and clicking install.
Hit check on all tools, to be safe
Hit check on API you are working with
Hit check on all extras to be safe
Go to file -> project structure
Finally go to build at the top of the screen and hit rebuild project
As #Matt said, it is correct, I am here covered also which I did not find in the answer.
To add the Google Play Service library in your application project, follow below steps :-
1) Open the build.gradle file of your application module directory. See screenshot
2) Add new in your dependecies, here you to update the version number whenever you update the Google Play Service.
dependencies {
...
compile 'com.google.android.gms:play-services:4.2.42'
compile files('src/main/libs/gson-2.2.4.jar')
}
3) Now Lastly important save your file and click on Sync with Gradle Files in the toolbar.
This didn't work for me, I had to download the Goople Repository in the Android SDK Manager - Extras, to fix it.
Try to avoid including entire google play services, when you use more library then you get Multidex exception:
The number of method references in a .dex file cannot exceed 64k
So best way to use:
compile 'com.google.android.gms:play-services-maps:9.8.0'
if you wish to include other services, please refer here:
https://developers.google.com/android/guides/setup (scroll down)
Go to Android SDK Manager, go to Extras, select Google Play Services and Google Repository and then click on 'Install Packages...' button.
Click on 'build.gradle' file, in the code window in editor, then click on 'try again' link button...
Wait until gradle build finish.
Go to the setting -> apps in your android testing phone and search for google play services and click on it, there you will find the version number installed on your device.
For me it was 9.6.83
then just add your version number to this command below :-
compile 'com.google.android.gms:play-services:9.6.83'
Add this to you build.gradle(app)
Gradle sync
Later you may get a gradle error saying that the particular repository needs to be installed, Go ahead and download it ! Voila your next gradle sync is successfull.
Add this line to your app gradle
in dependency block
implementation 'com.google.android.gms:play-services-maps:15.0.1'
Add Google Play Service ads and their feature in your android Project
Open your Android Studio build.gradle file
In Dependency add Google Play Service
implementation 'com.google.android.gms:play-services-ads:20.5.0'
sync your build.gradle file
Related
I am new to Android, and I was trying to Add GoogleSignin in my blank app.
I am following this tutorial from YouTube: https://www.youtube.com/watch?v=2PIaGpJMCNs, which says to add Gradle dependencies as shown in "Google's official documentation". But I don't see any such dependencies given in the official documentation.
I feel I am stuck in the process. Is it that the documents shown in the video are deprecated and now we don't need to add Gradle dependencies for Google SignIn?
I have performed the following steps:
1) Created a project in Android Studio
2) Added internet permission in manifest
3) Created a Project in Google Developer Console
4) Generated the SHA Key and added to the official documentation form
5) Generated the credential.json file and pasted it into the app folder of my Android Studio App
6) Installed Google play Services
7) Now the tutorial says to add Gradle dependencies in my project as provided in the "Official Google Documentation", but, as mentioned above, I could not find any such thing. I can't find anywhere in the page which tells me anything about adding Gradle Dependencies
To implement GoogleSignIn follow the following simple steps:
Add implementation 'com.google.android.gms:play-services-auth:15.0.1' in your app level build.gradle file.
Configure your project in Google console here
Follow further steps here
I am using google Maps in my android application. I have created the key and added necessary permissions in manifest file. But soon I start the application I get this message in debugger:
GoogleService failed to initialize, status: 10, Missing an expected
resource: 'R.string.google_app_id' for initializing Google services.
Possible causes are missing google-services.json or
com.google.gms.google-services gradle plugin.
I am not sure whats wrong. The Map is working fine and I can use it without any issues. My gradle file has this entry:
compile 'com.google.android.gms:play-services:8.4.0'
What is it complaining about and how do I alleviate it?
[From Product Manager # Google]
You can fix this issue by downloading and copying the google-services.json file for your Android app by following the steps below:
Select your app/project name and Android packagename from this link and click Continue to Choose and configure services.
Click Continue to Generate Configuration files.
Download google-services.json and copy the file to the app/ or mobile/ module directory in your Android project.
If you have previously imported your Google project into Firebase, you can
get the updated google-services.json from the Firebase console under Project Settings.
DO NOT COPY the PROJECT_NUMBER as suggested by one of the other answers since the google_app_id refers to your app within a Project and not the project itself.
You need to place the configuration file (google-services.json) generated by developer.google.com, as mentioned in the 2nd step of the official docs here
The process is simple
You can select your project or create a new one.
Then after selecting desired services (in this case the maps service), you can generate the configuration file.
For people who have migrated to the Firebase projects they can get the same by going to Firebase Console, selecting your project and under settings you will find the configuration file.
Then as quoted in step 3 of the official docs here
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android
P.S : For people downvoting this answer, please do leave a comment as to why you are down voting it.
In my case, the cause of this error was that the Google Services plugin for Gradle and the Play Services library were incompatible versions. Instructions for compatible versions:
1) Add the dependency to your project-level build.gradle:
classpath 'com.google.gms:google-services:1.5.0-beta2'
2) Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
3) If you're using Android Studio, this is the string to add to the dependency section of your application's build.gradle file:
dependencies {
compile "com.google.android.gms:play-services:8.3.0"
}
Source: https://developers.google.com/cloud-messaging/android/client
I met the same problem and solved it followed the official solution.
Here are the steps:
get the configuration file google-services.json from this link.
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project.
Add the dependency to your project-level build.gradle:
classpath 'com.google.gms:google-services:1.5.0-beta2'
Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
Add this dependency to your app-level build.gradle:
dependencies {
compile "com.google.android.gms:play-services:8.3.0"
}
For those who face this problem even after correctly setting up play services and placing google-services.json file in project/app folder, the actual solution is to
Build > Rebuild Project
Possibly due to the fact that strings from json file are not integrated into compiled resources until a full rebuild is performed.
For Xamarin/Visual Studio Mac I needed to add this to the bottom of my Droid.csproj
<Target Name="ProcessGoogleServicesJson" Condition=" '#(GoogleServicesJson)' != '' AND '$(AndroidApplication)' == 'True' AND '$(DesignTimeBuild)' != 'True'" BeforeTargets="$(ProcessGoogleServicesJsonBeforeTargets)" AfterTargets="$(ProcessGoogleServicesJsonAfterTargets)">
<Message Text="Using ProcessGoogleServicesJson override" Importance="high" />
<ProcessGoogleServicesJson GoogleServicesJsons="#(GoogleServicesJson)" IntermediateOutputPath="$(IntermediateOutputPath)" MonoAndroidResDirIntermediate="$(MonoAndroidResDirIntermediate)" AndroidPackageName="$(_AndroidPackage)">
<Output ItemName="_AndroidResourceDest" TaskParameter="GoogleServicesGeneratedResources" />
<Output ItemName="FileWrites" TaskParameter="GoogleServicesGeneratedResources" />
</ProcessGoogleServicesJson>
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)\ProcessGoogleServicesJson.stamp" />
</ItemGroup>
https://github.com/xamarin/GooglePlayServicesComponents/issues/64
This also happen to me. In my case, it is because Android studio tried to insert some code to my main activity. Removing the code fixes the error
Inserted code is about App Indexing:
https://developers.google.com/app-indexing/android/publish
I had the same issue back then. Was able to solve it by using only the necessary play services library, which in my case GCM.
Instead of com.google.android.gms:play-services:8.4.0, I use com.google.android.gms:play-services-gcm:8.4.0. See here for more info; this also solves multidex problem.
Then I applied both #Radix and #Alexander's approach to remove the message GCM has been output in the logcat regarding the google-services.json.
You can change the versionCode and versionName of your app in your Gradle file.
A quick fix I used is to disable signing. If you aren't wanting to create production code you can set your build variant to debug, localOldDebug or localDebug.
Click on Build Variants on the bottom left in Android Studio.
how-to-disable-generated-signed-apk-android-studio
Just have another solution i'm remove accidentally
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Add this and work, is for new solution
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.
referencing the play-services via gradle stopped working for me - boiled it down - even the sample I used as a reference in the first place stopped working:
https://plus.google.com/+AndroidDevelopers/posts/4Yhpn6p9icf
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':auth'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':auth:compile'.
> Could not find com.google.android.gms:play-services:3.1.36.
Required by:
gpsdemos:auth:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.577 secs
I fear that just the version increased but that raises 2 questions:
#1) what is the new one?
#2) why is the old version gone?
Check if you also installed the "Google Repository". If not, you also have to install the "Google Repository" in your SDK Manager.
Also be aware that there might be 2 SDK installations - one coming from AndroidStudio and one you might have installed. Better consolidate this to one installation - this is a common pitfall - that you have it installed in one installation but it fails when you build with the other installation.
Just install Google Repository form your sdk manager and than restart Android Studio.
In addition to installing the repository and the SDK packages one should be aware that the version number changes periodically. A simple solution at this point is to replace the specific version number with a plus (+) symbol.
compile 'com.google.android.gms:play-services:+'
Google instructions indicate that one should be sure to upgrade the version numbers, however adding the plus deals with the changes in versioning. Also note that when building in Android Studio a message will appear in the status line when a new version is available.
One can view the available versions of play services by drilling down on the correct repository path:
References
This site also has instructions for Eclipse, and other IDE's.
I've been strugglin with this problem for hours till found this post. Just like #ligi said, some people have two SDK folders (Android Studio, which is bundled and Eclipse). The problem is that it doesn't matter if you downloaded the Google Play Services library on both SDK folders, your ANDROID_HOME enviroment variable must be pointing to the SDK folder used by the Android Studio.
SDK Folder A (Used on Eclipse)
SDK Folder B (Used on AS)
ANDROID_HOME=<path to SDK Folder B>
After change the path of this variable the error was gone.
I had the same problem because I had:
compile 'com.google.android.gms:play-services:5.2.8'
and I solved changing the version numbers for a '+'. so the lines has to be:
compile 'com.google.android.gms:play-services:+'
Adding this as a second reference because I had a similar problem..
I had to explicitly add '.aar' as a registered file type under the 'Archives' category in AS settings.
If you already have Google Repository installed, make sure it's updated. I had to update my Google Repository and services. This was after I updated Android Studio.
I added a new environment variable ANDROID_HOME and pointed it to the SDK (C:\Program Files (x86)\Android\android-studio\sdk) that is inside the installation directory of Android Studio. (Environment variables are a part of windows; you access them through the advanced computer properties...google it for more info)
I have the same question.
You should add some dependencies in build.gradle, just looks like this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libcocos2dx')
compile 'com.google.firebase:firebase-ads:11.6.0'
// the key point line
compile 'com.google.android.gms:play-services-auth:11.6.0'
}
I too had the same problem and resolved.
As per the above-mentioned solutions by others, I tried all the things and it does not solve my problem.
Even if you have two SDK locations, no need to worry about it and check whether your android home is set to Android studio SDK (If you have the Android repository and everything in that SDK location).
Solution:
Go to Your project structure
Select your modules
Click the dependance tap on the right side
Add library dependency
"com.google.android.gms:play-service:+"
I hope it will solve your problem.
By mistake I added the compile com.google.android.gms:play-services:5.+ in dependencies in build script block. You should add it in the second dependency block. make changes->synch project with gradle.
Personally this post helped me to solve this issue by moving the google() to the top of the repositories.
I'm trying to test Google Play Services with the new Android Studio.
I have a project with a dependency to the google_play_services.jar.
But when I try to Rebuild the project I get the following errors:
Information:[TstGP3-TstGP3] Crunching PNG Files in source dir: C:\Users\ans\AndroidStudioProjects\TstGP3\TstGP3\src\main\res
Information:[TstGP3-TstGP3] To destination dir: C:\Users\ans\AndroidStudioProjects\TstGP3\build\classes\res-cache\TstGP3-TstGP3
Information:Compilation completed with 2 errors and 0 warnings in 2 sec
Information:2 errors
Information:0 warnings
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\Android_BuildConfig_Generator\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\BuildConfig.java
Error:Error:line (4)error: duplicate class: com.example.tstgp3.BuildConfig
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\aapt\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\R.java
Error:Error:line (10)error: duplicate class: com.example.tstgp3.R
It seems that it has two BuildConfig files and also two R classes. How can I resolve the issue?
EDIT:
I have noticed that the compiler compiles two R.java files: the one that is in my project folder and another one that is located in the folder %USERPROFILE%.AndroidStudioPreview
So, I tried to exclude this "Preview" folder in the compiler settings and now it's working.
This issue only occurs after I have started to use Google Play Services classes in my project.
I will appreciate if someone can explain the reason behind this problem.
All those answers are wrong, since the release of gradle plugin v0.4.2 the setup of google play services under android studio is straight forward. You don't need to import any jar or add any project library nor add any new module under android studio. What you have to do is to add the correct dependencies into the build.gradle file. Please take a look to those links: Gradle plugin v0.4.2 update, New Build System, and this sample
The Correct way to do so is as follows:
First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.
Restart android studio and open the build gradle file. You must modify your build.gradle file to look like this under dependencies:
dependencies {
compile 'com.google.android.gms:play-services:6.5.87'
}
And finally syncronise your project (the button to the left of the AVD manager).
Since version 6.5 you can include the complete library (very large) or just the modules that you need (Best Option). I.e if you only need Google Maps and Analytics you can replace the previous example with the following one:
dependencies {
compile 'com.google.android.gms:play-services-base:6.5.87'
compile 'com.google.android.gms:play-services-maps:6.5.87'
}
You can find the complete dependency list here
Some side notes:
Use the latest play services library version. If it's an old version, android studio will highlight it. As of today (February 5th is 6.5.87) but you can check the latest version at Gradle Please
After a major update of Android Studio, clean an rebuild your project by following the next instructions as suggested in the comments by #user123321
cd to your project folder
./gradlew clean
./gradlew build
Go to File -> Project Structure
Select 'Project Settings'
Select 'Dependencies' Tab
Click '+' and select '1.Library Dependencies'
Search for : com.google.android.gms:play-services
Select the latest version and click 'OK'
Voila! No need to fight with Gradle :)
EDITED: This guy really brought it home and has a good little tutorial
http://instantiatorgratification.blogspot.com/2013/05/google-play-services-with-android-studio.html
one side note: I had played around so much that I needed to do a gradlew clean to get it to run succesfully
If you have imported your project or are working from the Sample Maps application located in \extras\google\google_play_services\samples\maps check out this tutorial.
https://stackoverflow.com/a/16598478/2414698
If you are creating a new project from scratch then note Xav's comments on that same post. He describes that Android Studio uses a different compiler and that you have to modify the build.gradle file manually. I did this with success. I copied
google-play-services.jar
google-play-services.jar.properties
into my lib directory and added the following to my build.gradle file
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/google-play-services.jar')
}
Also, if this is a new project check out this post, too.
https://stackoverflow.com/a/16671865/2414698
Most of these answers only address compile-time dependencies, but you'll find a host of NoClassDef exceptions at runtime. That's because you need more than the google-play-services.jar. It references resources that are part of the library project, and those are not included correctly if you only have the jar.
What worked best for me was to first get the project setup correctly in eclipse. Have your project structured so that it includes both your app and the library, as described here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup
Then export your app project from eclipse, and import into Android Studio as described here: http://developer.android.com/sdk/installing/migrate.html. Make sure to export both your app project and the google play services library project. When importing it will detect the library project and import it as a module. I just accepted all defaults during the project import process.
Google Play services Integration in Android studio.
Step 1:
SDK manager->Tools Update this
1.Google play services
2.Android Support Repository
Step 2:
chance in build.gradle
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.+'
}
Step 3:
android.manifest.xml
<uses-sdk
android:minSdkVersion="8" />
Step 4:
Sync project file with grandle.
wait for few minute.
Step 5:
File->Project Structure find error with red bulb images,click on go to add dependencies select your app module.
Save
Please put comment if you have require help.
Happy coding.
None of the above solution worked for me. Not sure if it is specific to my setup or new release.
I am using Android Studio Beta 0.8.9 and I was not getting any com.google.android.gms:play-service in the library list on following this instruction:
Go to File -> Project Structure -> Select Project Settings -> Select 'Dependencies' Tab Click '+' -> 1.Library Dependencies -> Select com.google.android.gms:play-services:+
I had already done this:
First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.
What resolved it was to add from SDK Manager, "Google play services for Froyo" then repeating the first step.
Did not understand the reason properly but this worked.
PS: I just observed that even now when I search for play-services this does not come, but when I directly scroll and look through the list it is right there.
Follow this article -> http://developer.android.com/google/play-services/setup.html
You should to choose Using Android Studio
Example Gradle file:
Note: Open the build.gradle file inside your application module
directory.
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "{applicationId}"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:6.1.+'
}
You can find latest version of Google Play Services here: https://developer.android.com/google/play-services/index.html
I've got this working after doing the following:
Have the google-play-services-lib as a module (note difference between module and project), then add the google-play-services.jar to your models "libs" directory.
After that add the jar to your build path through making a library or add the jar to another library. I generally have a single IDEA library which I add all my /libs/*.jar files to.
Add the library to your modules build path through Module Settings (F4).
Add the google-play-services-lib as a module dependency to your project.
Done!
Note: This doesn't give me the runtime exceptions either, it works.
Open your project build.gradle file and add below line under dependencies module.
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
}
The below will be add Google Analytics and Maps if you don't want to integrate full library
dependencies {
compile 'com.google.android.gms:play-services-analytics:7.0.0'
compile 'com.google.android.gms:play-services-maps:7.0.0'
}
In my case google-play-services_lib are integrate as module (External Libs) for Google map & GCM in my project.
Now, these time require to implement Google Places Autocomplete API but problem is that's code are new and my libs are old so some class not found:
following these steps...
1> Update Google play service into SDK Manager
2> select new .jar file of google play service (Sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs) replace with old one
i got success...!!!
I copied the play libs files from the google-play-services_lib to my project libs directory:
google-play-services.jar
google-play-services.jar.properties.
Then selected them, right-click, "Add as libraries".