Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio with Google Play Services

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.

like image 808
androidtester Avatar asked May 18 '13 13:05

androidtester


People also ask

What is Google services in Android Studio?

By integrating your Android apps with the Google Play Services, you can access Google services, such as Maps, Drive, and Google+. Once you have your apps set up to use these services, accessing them is typically straightforward. The setup process does require a few steps, but you only need to carry them out once.

Does Android Studio have Play Store?

5 Answers. Show activity on this post. Starting with Android Studio 3.0 Canary 1, you have now some options of devices that come with the Play Store app built-in(Nexus 5X and Nexus 5 on image below).


2 Answers

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

like image 52
Imanol Avatar answered Oct 04 '22 10:10

Imanol


  1. Go to File -> Project Structure
  2. Select 'Project Settings'
  3. Select 'Dependencies' Tab
  4. Click '+' and select '1.Library Dependencies'
  5. Search for : com.google.android.gms:play-services
  6. Select the latest version and click 'OK'

Voila! No need to fight with Gradle :)

like image 33
Ivo Stoyanov Avatar answered Oct 04 '22 10:10

Ivo Stoyanov