Android Studio with Google Play Services - android

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".

Related

Imported module in Android Studio can't find imported class

I recently downloaded the ViewPagerIndicator library and imported it into android studio. After adding it to my project I get a rendering error "The following classes could not be found:" and points to com.viewpagerindicator.IconPageIndicator.
The steps I took were Files->Import Module->'library name', Project Structure -> Dependencies -> + the imported module. Then to my layout xml file I added the <com.viewpagerindicator.IconPageIndicator />, after that I got the missing class problem.
It compiles just fine and I went through all of the build.gradle and settings.gradle files and compared them to what they should be online.
MyApp->build.gradle has compile project(':library') under dependencies
settings.gradle has include ':library' with no build errors.
First of all, you must import your library project by following that path:
File --> New --> Import Module
After you have imported the library project successfully, you must check your build.gradle file inside your project's folder if the following line is present at the "dependencies" section:
implementation project(':NameOfTheLibProject')
Then your project must be built successfully.
I found that my issue was the Android Plugin Version under Project Structure --> Project was different to the version my plugins all used. Once I aligned them to the same version, I could see all my classes from my imported module.
Took me hours :(
I had the same problem. I just did: Invalidate / Restart ..
I too had trouble importing module as it was not appearing in list of modules. And way it worked for me is manually entering it in settings.gradle this way:
include ':app', 'module_name'
And in build.gradle
compile project(':module_name')
In my case, I did add in app gradle:
// Nearly deprecated.
compile project(':NameOfTheLibProject')
// Or
implementation project(':NameOfTheLibProject')
but it only works when I change
compileSdkVersion
minSdkVersion
targetSdkVersion
in app and the other modules are the same.
The following solution worked for me,just two steps.
Go to your project structure on android studio, select project from left side.Change Android plugin version to Gradle version press ok.
If error occurs after synchronization again go to project structure and select project.undo the android plugin version like before.Gradle will align the library and make the class visible to XML files.
The issue in my case was different compile and target SDK version,
mentioned in my main app module and your added lib module.
Once I matched both of them it worked perfectly.
So just open build.gradle file of app-level and lib module-level check for the SDK version.
settings.gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(':wheel') // "Wheel" - you're project path name
}
In case you just changed the name of your project in the pubspec.yaml File, make sure to change the import names as well, because they will stay the same and therefore wont find the new named directory.
Ex. change this to :
import 'package:previousName/backend/connector/userConnector.dart';
to this:
import 'package:newName/backend/connector/userConnector.dart';
As far as i know, there is no terminal command for that, only find-in-files-replace :(

Cannot resolve symbol 'google' [duplicate]

I am new to Android development. By following this tutorial I got errors The import com.google.android.gms cannot be resolved when I wrote the code into the MainActivity.java:
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
By searching for various fixes I made sure to try these out:
I have downloaded Google API's for a particular API level through
Android SDK manager.
I checked off Google API as project build target.
I have added <uses-library android:name="com.google.android.maps" />
line into the AndroidManifest.xml as a child of <application> tag.
I cleaned the project by selecting Project->Clean... and built it
from scratch.
I included .jar file for maps by right-clicking on my project, went
to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
Unfortunately, none of the above have helped.
Another way is to let Eclipse do the import work for you. Hover your mouse over the com.google.android.gms import that can not be resolved and towards the bottom of the popup menu, select the Fix project setup... option as below. Then it'll prompt to import the google play services library. Select that and you should be good to go.
I checked off Google API as project build target.
That is irrelevant, as that is for Maps V1, and you are trying to use Maps V2.
I included .jar file for maps by right-clicking on my project, went to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
This is doubly wrong.
First, never manually modify the build path in an Android project. If you are doing that, at best, you will crash at runtime, because the JAR you think you put in your project (via the manual build path change) is not in your APK. For an ordinary third-party JAR, put it in the libs/ directory of your project, which will add it to your build path automatically and add its contents to your APK file.
However, Maps V2 is not a JAR. It is an Android library project that contains a JAR. You need the whole library project.
You need to import the android-sdk-windows\add-ons\addon_google_apis_google_inc_8 project into Eclipse, then add it to your app as a reference to an Android library project.
From my experience (Eclipse):
Added google-play-services_lib as a project and referenced it from my app.
Removed all jars added manually
Added google-play-services.jar in the "libs" folder of my project.
I had some big issues because I messed up with the Order and Export
tab, so the working solution is (in this order): src, gen, Google APIs, Android Dependencies, Android Private Libraries (only this one checked to be exported).
In my case or all using android studio
you can import google play service
place in your build.gradle
compile 'com.google.android.gms:play-services:7.8.0'
or latest version of play services depend in time you watch this answer
More Specific import
please review this individual gradle imports
https://developers.google.com/android/guides/setup
Google Maps
com.google.android.gms:play-services-maps:7.8.0
error may occurred
if you face error while you sync project with gradle files
make sure you install latest update
1- Android Support Repository.
2- Android Support Library.
3- Google Repository.
4-Google Play Services.
You may need restart your android studio to response
Note that once you have imported the google-play-services_lib project into your IDE, you will also need to add google-play-services.jar to:
Project=>Properties=>Java build path=>Libraries=>Add JARs
Above solutions should solve your problem. If these do not, make sure you update your Android sdk using SDK manager and install the latest lib project and then repeat the above steps again.
once again Make sure these 2 things happen correctly nothing more than that.
(FOR ECLIPSE USERS)
1) copy the jar file from --> C:\Users(your-username)\android-sdks\extras\google\google_play_services\libproject\google-play-services_lib\libs\ google-play-services.jar
2) Right Click Project--> Build Path -> Add External Archive-> google-play-services.jar
In Android Studio goto:
File -> Project Structure... -> Notifications (last entry) -> check Google Cloud Messaging
Wait a few seconds and you're done :)
import com.google.android.gms.gcm.GcmListenerService should be resolved properly
I too had the same issue. Got it resolved by compiling with the latest sdk tool versions.(Play services,build tools etc). Sample build.gradle is shown below for reference.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.abc.bcd"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.0.1'
}
Supposing that you are using ECLIPSE:
Right click PROJECT
PROPERTIES
ANDROID
If you have a version of ANDROID checked, you must change it to a GOOGLE API.
Choose a version of GOOGLE APIS compatible with your project's target version.
In my case just add the below code to the build.gradle(:app)
implementation 'com.google.android.gms:play-services-location:16.0.0'
In my case only after I added gcm.jar to lib folder, it started to work.
It was here: C:\adt-bundle-windows-x86_64-20131030\sdk\extras\google\gcm\gcm-client\dist
So the google-play-services.jar didn't work...
I had the same problem so that the dumb API I decided as follows
changing the import line
import com.google.android.gms.maps.model.LatLng;

How to add Android Support Repository to Android Studio?

I'm using Android Studio with an external Android SDK. I have installed the support library and the support repository. The support repository is in:
~/Development/Tools/android/sdk/extras/android/m2repository
When I add a dependency to the support library in the build.gradle file, like:
...
repositories {
mavenCentral()
}
...
dependencies {
compile "com.android.support:support-v4:18.0.+"
}
Android Studio cannot find the support libraries (cannot resolve symbol etc) and Gradle also cannot find the libraries:
Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
> Could not find any version that matches com.android.support:support-v4:18.0.+.
Required by:
TestAndroidStudio:TestAndroidStudio:unspecified
How do I specify in Android Studio and/or the build.gradle file the location of the Android support repository?
You are probably hit by this bug which prevents the Android Gradle Plugin from automatically adding the "Android Support Repository" to the list of Gradle repositories. The work-around, as mentioned in the bug report, is to explicitly add the m2repository directory as a local Maven directory in the top-level build.gradle file as follows:
allprojects {
repositories {
// Work around https://code.google.com/p/android/issues/detail?id=69270.
def androidHome = System.getenv("ANDROID_HOME")
maven {
url "$androidHome/extras/android/m2repository/"
}
}
}
Gradle can work with the 18.0.+ notation, it however now depends on the new support repository which is now bundled with the SDK.
Open the SDK manager and immediately under Extras the first option is "Android Support Repository" and install it
Found a solution.
1) Go to where your SDK is located that android studio/eclipse is using.
If you are using Android studio, go to extras\android\m2repository\com\android\support\.
If you are using eclipse, go to \extras\android\support\
2) See what folders you have, for me I had gridlayout-v7, support-v4 and support-v13.
3) click into support-v4 and see what number the following folder is, mine was named 13.0
Since you are using "com.android.support:support-v4:18.0.+", change this to reflect what version you have, for example I have support-v4 so first part v4 stays the same. Since the next path is 13.0, change your 18.0 to:
"com.android.support:support-v4:13.0.+"
This worked for me, hope it helps!
Update:
I noticed I had android studio set up with the wrong SDK which is why originally had difficulty updating! The path should be C:\Users\Username\AppData\Local\Android\android-sdk\extras\
Also note, if your SDK is up to date, the code will be:
"com.android.support:support-v4:19.0.+"
Android Studio 3
Make sure you have the latest version of Android Studio. The support library is included by default when you create new projects. If you are adding the Support Library to a project that doesn't have it, then you just need to add a single line to your app module's build.gradle file, and then sync gradle.
build.gradle
dependencies {
...
implementation 'com.android.support:appcompat-v7:27.1.1'
}
It should just be that easy, though there may be some things to note:
Android Studio should give you a warning nowadays if the support library needs to be updated. Just update the 27.1.1 numbers that I have here to whatever it tells you to. You can also manually check what the latest revision is if you want to.
The implementation keyword replaces compile that was used in Android Studio 2.x. (What's the difference?)
There are other support library packages that you may need to include depending on what your app uses (like constraint-layout or recyclerview).
Make sure that you have the latest updates for everything in the SDK Manager. Go to Tools > SDK Manager.
Documentation
Support Library
Support Library Setup
Support Library Features
I used to get similar issues. Even after installing the support repository, the build used to fail.
Basically the issues is due to the way the version number of the jar files are specified in the gradle files are specified properly.
For example, in my case i had set it as "compile 'com.android.support:support-v4:21.0.3+'"
On removing "+" the build was sucessful!!
Instead of doing this:
compile "com.android.support:support-v4:18.0.+"
Do this:
compile 'com.android.support:support-v4:18.0.+'
Worked for me

How to import relative project with the Android Studio(not jar) [duplicate]

How do I add a library project (such as Sherlock ABS) to Android Studio?
(Not to the old ADT Eclipse-based bundle, but to the new Android Studio.)
Update for Android Studio 1.0
Since Android Studio 1.0 was released (and a lot of versions between v1.0 and one of the firsts from the time of my previous answer) some things has changed.
My description is focused on adding external library project by hand via Gradle files (for better understanding the process). If you want to add a library via Android Studio creator just check the answer below with visual guide (there are some differences between Android Studio 1.0 and those from screenshots, but the process is very similar).
Before you start adding a library to your project by hand, consider adding the external dependency. It won’t mess in your project structure. Almost every well-known Android library is available in a Maven repository and its installation takes only one line of code in the app/build.gradle file:
dependencies {
implementation 'com.jakewharton:butterknife:6.0.0'
}
Adding the library
Here is the full process of adding external Android library to our project:
Create a new project via Android Studio creator. I named it HelloWorld.
Here is the original project structure created by Android Studio:
HelloWorld/
app/
- build.gradle // local Gradle configuration (for app only)
...
- build.gradle // Global Gradle configuration (for whole project)
- settings.gradle
- gradle.properties
...
In the root directory (HelloWorld/), create new folder: /libs in which we’ll place our external libraries (this step is not required - only for keeping a cleaner project structure).
Paste your library in the newly created /libs folder. In this example I used PagerSlidingTabStrip library (just download ZIP from GitHub, rename library directory to „PagerSlidingTabStrip" and copy it). Here is the new structure of our project:
HelloWorld/
app/
- build.gradle // Local Gradle configuration (for app only)
...
libs/
PagerSlidingTabStrip/
- build.gradle // Local Gradle configuration (for library only)
- build.gradle // Global Gradle configuration (for whole project)
- settings.gradle
- gradle.properties
...
Edit settings.gradle by adding your library to include. If you use a custom path like I did, you have also to define the project directory for our library. A whole settings.gradle should look like below:
include ':app', ':PagerSlidingTabStrip'
project(':PagerSlidingTabStrip').projectDir = new File('libs/PagerSlidingTabStrip')
5.1 If you face "Default Configuration" error, then try this instead of step 5,
include ':app'
include ':libs:PagerSlidingTabStrip'
In app/build.gradle add our library project as an dependency:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation project(":PagerSlidingTabStrip")
}
6.1. If you followed step 5.1, then follow this instead of 6,
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation project(":libs:PagerSlidingTabStrip")
}
If your library project doesn’t have build.gradle file you have to create it manually. Here is example of that file:
apply plugin: 'com.android.library'
dependencies {
implementation 'com.android.support:support-v4:21.0.3'
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Additionally you can create a global configuration for your project which will contain SDK versions and build tools version for every module to keep consistency. Just edit gradle.properties file and add lines:
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.3
ANDROID_BUILD_SDK_VERSION=21
Now you can use it in your build.gradle files (in app and libraries modules) like below:
//...
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
}
//...
That’s all. Just click‚ synchronise the project with the Gradle’ icon . Your library should be available in your project.
Google I/O 2013 - The New Android SDK Build System is a great presentation about building Android apps with Gradle Build System: As Xavier Ducrohet said:
Android Studio is all about editing, and debugging and profiling.
It's not about building any more.
At the beginning it may be little bit confusing (especially for those, who works with Eclipse and have never seen the ant - like me ;) ), but at the end Gradle gives us some great opportunities and it worth to learn this build system.
Here is the visual guide:
Update for Android Studio 0.8.2:
In Android Studio 0.8.2, go to Project Structure -> under Modules just hit the plus button and select Import Existing Project and import actionbarsherlock. Then synchronise your Gradle files.
If you face the error
Error: The SDK Build Tools revision (xx.x.x) is too low. Minimum
required is yy.y.y
just open the build.gradle file in actionbarsherlock directory and update the buildToolsVersion to the suggested one.
android {
compileSdkVersion 19
buildToolsVersion 'yy.y.y'
Menu File -> Project Structure...:
Module -> Import Module
After importing the library module, select your project module and add the dependency:
And then select the imported module:
Use menu File -> Project Structure -> Modules.
I started using it today. It is a bit different.
For Sherlock, maybe you want to delete their test directory, or add the junit.jar file to the classpath.
To import the library using gradle, you can have to add it to the dependencies section of your build.gradle (the module's one).
E.g.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
Android Studio is changing.
There exist a section named "Open module settings" if you
right-click on a module folder in the project section of Android
Studio (I'm using the version 0.2.10).
I would consider Dependencies, Android Libraries and Multi-project setup necessary reading. Please take a few minutes to do so.
Particularly, in the case of a non-jar library project, read the following snippet from above source:
Gradle projects can also depend on other gradle projects by using a multi-project setup.
A multi-project setup usually works by having all the projects as sub folders of a given root project.
For instance, given to following structure:
MyProject/
+ app/
+ libraries/
+ lib1/
+ lib2/
We can identify 3 projects. Gradle will reference them with the following name:
:app
:libraries:lib1
:libraries:lib2
Each projects will have its own build.gradle declaring how it gets built.
Additionally, there will be a file called settings.gradle at the root declaring the projects.
This gives the following structure:
MyProject/
| settings.gradle
+ app/
| build.gradle
+ libraries/
+ lib1/
| build.gradle
+ lib2/
| build.gradle
The content of settings.gradle is very simple:
include ':app', ':libraries:lib1', ':libraries:lib2'
This defines which folder is actually a Gradle project.
The :app project is likely to depend on the libraries, and this is done by declaring the following dependencies:
dependencies {
compile project(':libraries:lib1')
}
Kindly note that there was little or no use of Android Studio GUI to make this happen.
I am currently using git submodules to link the nested library to the actual library git repo to avoid a dependency mess.
I have just found an easier way (rather than writing directly into the .gradle files).
This is for Android Studio 1.1.0.
Menu File -> New Module...:
Click on "Import Existing Project".
Select the desired library and the desired module.
Click finish.
Android Studio will import the library into your project. It will sync gradle files.
Add the imported module to your project's dependencies.
Right click on the app folder -> Open Module settings -> go to the dependencies tab -> Click on the '+' button -> click on Module Dependency.
The library module will be then added to the project's dependencies.
???
Profit
The easiest way I found to include external library project is (for example to include a Facebook library which is stored one directory up in the dependencies folder):
In settings.gradle add
include ':facebook'
project(':facebook').projectDir = new File(settingsDir, '../dependencies/FacebookSDK')
In build.gradle dependencies section, add
compile project ('facebook')
All left to do is synchronise the project with gradle files.
A simple way to add a JAR file as a library to your Android Studio project:
a) Copy your *.jar files
b) Paste into the libs directory under your projects:
c) Add to build.gradle:
dependencies {
...
compile files('libs/ScanAPIAndroid.jar', 'libs/ScanAPIFactoryAndroid.jar', .., ..)
}
b) If your project from example com.example.MYProject and libraries com.example.ScanAPI has the same namespace com.example, Android Studio will check your build and create all necessary changes in your project. After that you can review these settings in menu File -> Project Structure.
c) If your project and libraries have a different namespace you have to right click on the library and select option "Add as Library" and select the type what you need.
Remember the "Project structure" option is not doing any auto changes in "build.gradle" in the current version of Android Studio (0.2.3). Maybe this feature will be available in the next versions.
Option 1: Drop Files Into Project's libs/directory
The relevant build.gradle file will then update automatically.
Option 2: Modify build.gradle File Manually
Open your build.gradle file and add a new build rule to the dependencies closure. For example, if you wanted to add Google Play Services, your project's dependencies section would look something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.+'
}
Option 3: Use Android Studio's User Interface
In the Project panel, Control + click the module you want to add the dependency to and select Open Module Settings.
Select the Dependencies tab, followed by the + button in the bottom-left corner. You can choose from the following list of options:
Library Dependency
File Dependency
Module Dependency
You can then enter more information about the dependency you want to add to your project. For example, if you choose Library Dependency, Android Studio displays a list of libraries for you to choose from.
Once you've added your dependency, check your module-level build.gradle file. It should have automatically updated to include the new dependency.
Source
You can do this easily. Go to menu File -> New -> Import Module...:
Browse for the directory which contains the module. Click Finish:
Go to Project Structure and add Module Dependency:
Note: If you receive an SDK error, update that one.
This is how it works for me in Android Studio 1.5+
In the project where you want to add external library project,
go to menu File -> New -> *Import new Module**, navigate to the library project which you want to add to your project, select to add 'library' module in your project. You will get settings.gradle in your projects, beside app, included library, something like this:
include ':app', ':library'
Add in build.gradle(Module :app) in the dependencies section:
Compile project(':library')
Rebuild the project, and that's it.
*You can add as many libraries (modules) as you want. In that case in settings.gradle you will have:
include ':app', ':lib1', ':lib2', ...
And in build.gradle, you'll need to have:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Some other dependencies...
compile project(':lib1')
compile project(':lib2')
...
}
Press F4 to show Project Structure, click libraries or Global libraries, and click + to add the JAR file.
Click Modules what you want add jar, select the Dependencies tab, click +, and add Library.
If you need access to the resources of a library project (as you do with ABS) ensure that you add the library project/module as a "Module Dependency" instead of a "Library".
Editing library dependencies through the GUI is not advisable as that doesn't write those changes to your build.gradle file. So your project will not build from the command-line. We should edit the build.gradle file directly as follows.
For instance, given to following structure:
MyProject/
app/
libraries/
lib1/
lib2/
We can identify three projects. Gradle will reference them with the following names:
:app
:libraries:lib1
:libraries:lib2
The :app project is likely to depend on the libraries, and this is done by declaring the following dependencies:
dependencies {
compile project(':libraries:lib1')
}
Android Studio 3.0
Just add the library name to the dependencies block of your app's build.gradle file.
dependencies {
// ...
implementation 'com.example:some-library:1.0.0'
}
Note that you should use implementation rather than compile now. This is new with Android Studio 3.0. See this Q&A for an explanation of the difference.
To add to the answer: If the IDE doesn't show any error, but when you try to compile, you get something like:
No resource found that matches the given name 'Theme.Sherlock.Light'
Your library project is probably compiled as an application project. To change this, go to:
Menu File -> Project structure -> Facets -> [Library name] -> Check "Library module".
First Way This is working for MacBook.
First select your builder.gradle file as given screen:
Add dependencies like as on the selected screen:
Select sync project.
If you are getting an error like "Project with path':signature-pad' could not be found in project ':app'", then please use the second way:
Select menu File -> New -> Import Module...:
After clicking on Import Module,
give the path of library like as my MacBook path:
Click on Finish. Now your library are added.
After importing the ABS Module (from File > Project Structure) and making sure it has Android 2.2 and Support Library v4 as dependencies, I was still getting the following error as you #Alex
Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light.DarkActionBar'
I added the newly imported module as a dependency to my main app module and that fixed the problem.
To resolve this problem, you just need to add the abs resource path to your project build file, just like below:
sourceSets {
main {
res.srcDirs = ['src/main/res','../../ActionBarSherlock/actionbarsherlock/res']
}
}
So, I again compile without any errors.
If you have Android Studio .0.4.0, you can create a new folder in your build path, YourApp/libraries. Copy the JAR file. There in, right click on it and "Add As Library". Now you have a popup. Just select your directory and press OK, and that's it.
Simply import the Android library project as a module and in Build.gradle.
Apply plugin: 'com.android.library'
After that, follow these steps:
Right click on Module & select open Module settings
Select dependencies, click on +, select library dependencies, and add the previously imported module.
https://www.dropbox.com/s/1e3eteu3h0pmkf7/Android%20studio%20_doc.doc?dl=0 is the Dropbox link of how to add a JAR file and library project in the latest version of Android Studio 1.0.1.
Please see the documentation with screenshots. It's very easy for a new user.
I found the solution. It's so simple. Follow froger_mcs instructions.
Make sure that you make the src folder a Source folder in Project Structure -> Modules (Sources).
Basically, you can include your JAR files in three different ways. The last one is remote library that is using https://bintray.com/ jcenter online repository. But, if you do it in one of the two other ways, the JAR file will be included physically in your project. Please read this link https://stackoverflow.com/a/35369267/5475941 for more information. In this post I explained how to import your JAR file in Android studio and I explained all possible ways.
In summary, if it is like this (local address), they are downloaded and these JAR files are physically in the project:
But, if it is an internet address like this, they are remote libraries (bintray.com jcenter part) and they will be used remotely:
I hope it helps.
Open the build gradle module app file and add your dependency. If you download the library, just import and build as gradle.
Otherwise add repositories in side gradle module app:
repositories {
maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
}
The first repositories will download the library for you.
And compile the downloaded library:
compile ('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT#aar') {
transitive = true
}
If you are creating a library, you just need to import the project as import new module.
I had a different cause of the problem so for people:
repositories {
mavenCentral()
}
change mavenCentral() to jcenter() and add
allprojects {
repositories {
jcenter()
}
}
In Android Studio, go to inside app folder, and open build.gradle file. Here you will see dependencies{}. Inside it you can add the library project and synchronise. Now after synchronising the library it will be added to your project, and you can use its functions and classes in your project.
For Android Studio:
Click on Build.gradle (module: app).
And add for
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/commons-io-2.4.jar')
}
and in your directory "app", create a directory, "libs". Add the file yourfile.jar:
Finally, compile the Gradle Files:
I also encountered the same problem then I did following things.
I import the library project into my AndroidStudio IDE as a module using menu File -> Import module menus
Then I went to my main module in which I want the library project as a dependent project
Right click on the main module (in my case its name is app) -> open module setting -> go into dependencies tab -> click on + button (you will get it on right side of window) -> click on module dependency -> select your library project from list
Apply the changes and click the OK button.
It worked for me. I hope it will help others too.
You are able to use Gradle dependency configuration[About] to add some dependency into your project
<module_name>/build.gradle
dependencies {
//<gradle_dependency_configuration> '<dependency_name>:<dependency_version>'
//e.g.
implementation 'com.android.support:appcompat-v7:1.1.1'
}
Indeed as versions are changing, so is changing the user interface and options available on the menu. After reading most of the answers to these questions I had to guess what would work for Android Studio 1.1.0.
With your mouse, select the project at the main level (this is where it shows the name of your app).
Right click, and select the menu options New, Folder, Assets Folder.
After creating the assets folder, paste or copy in it, whatever JAR file you need for your library.
From Android Studio's main menu (top of the screen) select File -> Project Structure.
Then select your project name and go to the Dependencies tab.
Click on the plus sign (+) on the lower left of the dialog box and select file dependency.
Finally open the recently created assets folder, select the JAR files that you copied, and then click apply and OK.
Clean and rebuild your project.

The import com.google.android.gms cannot be resolved

I am new to Android development. By following this tutorial I got errors The import com.google.android.gms cannot be resolved when I wrote the code into the MainActivity.java:
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
By searching for various fixes I made sure to try these out:
I have downloaded Google API's for a particular API level through
Android SDK manager.
I checked off Google API as project build target.
I have added <uses-library android:name="com.google.android.maps" />
line into the AndroidManifest.xml as a child of <application> tag.
I cleaned the project by selecting Project->Clean... and built it
from scratch.
I included .jar file for maps by right-clicking on my project, went
to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
Unfortunately, none of the above have helped.
Another way is to let Eclipse do the import work for you. Hover your mouse over the com.google.android.gms import that can not be resolved and towards the bottom of the popup menu, select the Fix project setup... option as below. Then it'll prompt to import the google play services library. Select that and you should be good to go.
I checked off Google API as project build target.
That is irrelevant, as that is for Maps V1, and you are trying to use Maps V2.
I included .jar file for maps by right-clicking on my project, went to build path and added external archive locating it in my SDK: android-sdk-windows\add-ons\addon_google_apis_google_inc_8\libs\maps
This is doubly wrong.
First, never manually modify the build path in an Android project. If you are doing that, at best, you will crash at runtime, because the JAR you think you put in your project (via the manual build path change) is not in your APK. For an ordinary third-party JAR, put it in the libs/ directory of your project, which will add it to your build path automatically and add its contents to your APK file.
However, Maps V2 is not a JAR. It is an Android library project that contains a JAR. You need the whole library project.
You need to import the android-sdk-windows\add-ons\addon_google_apis_google_inc_8 project into Eclipse, then add it to your app as a reference to an Android library project.
From my experience (Eclipse):
Added google-play-services_lib as a project and referenced it from my app.
Removed all jars added manually
Added google-play-services.jar in the "libs" folder of my project.
I had some big issues because I messed up with the Order and Export
tab, so the working solution is (in this order): src, gen, Google APIs, Android Dependencies, Android Private Libraries (only this one checked to be exported).
In my case or all using android studio
you can import google play service
place in your build.gradle
compile 'com.google.android.gms:play-services:7.8.0'
or latest version of play services depend in time you watch this answer
More Specific import
please review this individual gradle imports
https://developers.google.com/android/guides/setup
Google Maps
com.google.android.gms:play-services-maps:7.8.0
error may occurred
if you face error while you sync project with gradle files
make sure you install latest update
1- Android Support Repository.
2- Android Support Library.
3- Google Repository.
4-Google Play Services.
You may need restart your android studio to response
Note that once you have imported the google-play-services_lib project into your IDE, you will also need to add google-play-services.jar to:
Project=>Properties=>Java build path=>Libraries=>Add JARs
Above solutions should solve your problem. If these do not, make sure you update your Android sdk using SDK manager and install the latest lib project and then repeat the above steps again.
once again Make sure these 2 things happen correctly nothing more than that.
(FOR ECLIPSE USERS)
1) copy the jar file from --> C:\Users(your-username)\android-sdks\extras\google\google_play_services\libproject\google-play-services_lib\libs\ google-play-services.jar
2) Right Click Project--> Build Path -> Add External Archive-> google-play-services.jar
In Android Studio goto:
File -> Project Structure... -> Notifications (last entry) -> check Google Cloud Messaging
Wait a few seconds and you're done :)
import com.google.android.gms.gcm.GcmListenerService should be resolved properly
I too had the same issue. Got it resolved by compiling with the latest sdk tool versions.(Play services,build tools etc). Sample build.gradle is shown below for reference.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.abc.bcd"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.0.1'
}
Supposing that you are using ECLIPSE:
Right click PROJECT
PROPERTIES
ANDROID
If you have a version of ANDROID checked, you must change it to a GOOGLE API.
Choose a version of GOOGLE APIS compatible with your project's target version.
In my case just add the below code to the build.gradle(:app)
implementation 'com.google.android.gms:play-services-location:16.0.0'
In my case only after I added gcm.jar to lib folder, it started to work.
It was here: C:\adt-bundle-windows-x86_64-20131030\sdk\extras\google\gcm\gcm-client\dist
So the google-play-services.jar didn't work...
I had the same problem so that the dumb API I decided as follows
changing the import line
import com.google.android.gms.maps.model.LatLng;

Categories

Resources