Gradle build fails looking for Google Play Services in Android Studio - android

I'm trying to run my project in Android Studio 0.3.6, but I always get this error :
Gradle: A problem occurred configuring root project 'myapp_android'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not resolve com.google.android.gms:play-services:3.1.36.
Required by:
:myapp_android:unspecified
> Could not GET 'http://maven.hq.couchbase.com/nexus/content/repositories/releases/com/google/android/gms/play-services/3.1.36/play-services-3.1.36.pom'. Received status code 503 from server: Service Temporarily Unavailable
Here is my complete build.gradle file :
home = System.getenv("ANDROID_HOME")
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url "http://maven.hq.couchbase.com/nexus/content/repositories/releases/"
}
maven {
url "http://files.couchbase.com/maven2/"
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.couchbase.cblite:CBLite:1.0.0-beta'
compile 'com.couchbase.cblite:CBLiteEktorp:1.0.0-beta'
compile 'com.couchbase.cblite:CBLiteJavascript:1.0.0-beta'
compile fileTree(dir: 'libs', include: '*.jar')
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3'
}
android {
compileSdkVersion 18
buildToolsVersion "18.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
tasks.withType(Compile) {
options.encoding = 'UTF-8'
}
And finally, my SDK Manager :
I tried with many versions of Android Studio (0.2.8, 0.2.9, 0.2.13, 0.3.2, 0.3.6) and it's always the same. I tried changing the Play Services version, I tried changing the order of the dependencies, nothing did the trick.
Is there something not correct with my setup? I looked for answers and pretty much everything I found (build.gradle structure, SDK missing items) was already fine...

I finally found what was the problem. #gnuf pointed me in the right direction. But the problem was that Android Studio, in Project Structure | Platform Settings | Android SDK, showed the wrong SDK. It showed the SDK it used was C:/Program Files (x86)/Android/android-studio/sdk, but in fact, I discovered it tried to build with another SDK located in C:\Users\my_username\AppData\Local\Android\android-studio\sdk.
Needless to say, it didn't work. There was nothing installed in this SDK. So I copied the contents of C:/Program Files (x86)/Android/android-studio/sdk to C:\Users\my_username\AppData\Local\Android\android-studio\sdk and it worked! My first build in three weeks.
So I think it's a bug of Android Studio. If anyone runs into this problem, make sure you only have one SDK on your computer. If you have more than one, make sure they all have the required dependencies. If you can, just copy the content of the most up to date to the others.

It may be the case that the location where you've installed the SDK components is different than the one that Android Studio is using.
Can you verify that the local Maven repositories (installed by the Google Repository and Android Support Repository) are under the Android SDK that you're using in your Android Studio project?
In Android Studio, go to Project Structure | Platform Settings | Android SDK. (On my machine, the path for Android SDK Location is /opt/boxen/homebrew/Cellar/android-sdk/22.2.1 ) In that directory, ensure that the subdirectory extras/google/m2repository/com/google/android/gms/play-services/ exists.

It looks for Google dependencies like Google Play Services in your SDK extras, not in Maven repositories over the network. Install the "Google Repository" in your SDK manager and you should be good to go.

Related

Android Studio "cannot resolve symbol String"

I have a small project that was started in Eclipse. I then exported it to a gradle file, and imported it to AS (0.5.7).
At first, not much seemed to work as it should, but after a "build => make project", I didn't seem to get any highlighted errors or so.
So I tried to run the app to an emulated device. Well, the device never launched, and now I get red squiggly lines under mentions of "String", "ArrayList" etc, saying it "cannot resolve the symbol".
What the f?
I have tried cleaning and rebuilding, as well as "sync project with gradle files".
Where do I go from here? I want to get going with developing in AS so bad!
edit: Screenshot of project setup: http://i.imgur.com/ycNyPaT.png
Contents of build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
There is simpler and I think more correct way:
Just select menu item 'File/Invalidate Caches/Restart...'
For me this successfully resolved the issue (was caused by surprising power off of PC)
So project arrangement should be as follows:
create app folder within your project.
within app folder make following folders: libs and src
inside src create main folder
inside main create java and assets
move contents of old src to java
move contents of old libs to libs
move res folder to src
move AndroidManifest.xml to src
move assets folder into src
create build.gradle inside app folder with following content:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
}
create settings.gradle in project root with following content:
include 'app'
build.gradle in root should have following structure:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
Android Studio 4.2.1 with Gradle 7.0.2.
Just had this problem with a module in my project. Basically many fundamental symbols like String, #Override there are not resolved. Non of the syncing or deleting cache etc helped me. The project builds without problem though, and after a successful build, the problem remained.
It turns out the issue relates to the line in the build.gradle file of the module:
apply plugin: 'java-library'
I had it there for ages and I haven't opened the module in a long time, so probably since some newer version of Gradle it's not accepted.
So the solution for me is to change the line to:
apply plugin: 'com.android.library'
Just writing this for people like me, who also landed here through googling this error.
What actually solved it for current Android Studio 3.1.+ was this
You just need to sync the project as you have opened an external project from a zip file in the android studio.
After you sync the project, you will see folders like Java,res folder,etc, instead of these not useful folders. And also, all the errors will be gone too.
When you open the external project, it will show like this.
https://photos.app.goo.gl/BFa113X9DWH8eNDt7
Then you click on the install, it will install the required components required for the project and then it will sync the project. After syncing, the Gradle will be build and your project is ready to run.
Remove the following line from the file that reported with the error if there is.
import static com.google.android.gms.internal.a.R;
try deleting [project]/[module]/build folder.
and then rebuild the project from menu->build->rebuild project
thats what worked for me.

What gradle task pulls dependencies from remote repositories?

I am making the switch to Gradle for my Android project. I have imported the project into Android Studio from Eclipse and have wrapped it using Gradle 1.8.
My assumption was Gradle handled dependencies the way as Maven, that is if you specify a dependency that does not exist in your local repository it will pull it from the remote repository. Android Studio is not pulling in my dependencies. I attempted to run ./gradlew androidDependencies --debug but I do not see any downloading of the dependencies however they are being acknowledged they are there and no warnings/errors are thrown.
11:11:36.833 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleVersionRepository] Using cached module metadata for module 'com.nostra13.universalimageloader#parent;1.8.6' in 'MavenRepo'
11:11:36.834 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain] Using module 'com.nostra13.universalimageloader:parent:1.8.6' from repository 'MavenRepo'
11:11:36.855 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Visiting configuration com.nostra13.universalimageloader:parent:1.8.6(default).
11:11:36.857 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder] Attaching com.nostra13.universalimageloader:parent:1.8.6(default) to its parents.
Gradle does take the dependency and create metadata from it in this location
/home/wil/.gradle/caches/artifacts-26/filestore/com.nostra13.universalimageloader/parent/1.8.6/pom/41669498c2bec505b61772b083cab341653cb86b
Interestingly I have found that if I have the maven dependencies locally it will pull it into Android Studio as an External Library and it will also add the jar to the gradle cache filestore it will just not do this for remote dependencies I specifiy.
Here is my build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.3'
}
}
repositories{
mavenCentral()
}
apply plugin: 'android'
dependencies {
compile 'com.nostra13.universalimageloader:parent:1.8.6'
}
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
I am running Android Studio 0.3.6, Ubuntu 13.04, Gradle 1.8, JDK 6
What gradle command should I run that should pull down remote dependencies from a maven repository? Am I missing a configuration setting somewhere that allows downloading of dependencies?
By using gradle dependencies command line, you can pull down all everything specified in your build.gradle
Remote dependencies are downloaded automatically as soon as a task needs them. If you, for example, compile your project's code, compile dependencies will be downloaded, unless they already exist in Gradle's dependency cache. Out of the box, Gradle doesn't come with a task that merely downloads all dependencies without doing anything with them, but it would be easy to write one.

IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;

I'm using Android Studio + gradle on MyProject + Facebook api as a library. See below settings.
I've tried removing all references of support-v4 (either r7 or 18.0.0) and replace them with support-v13, but the message with v4 was still present. I've also noticed that support-v4-r7 appears in External libraries, even though it's not referenced at all, anywhere. Would that be the problem ?
MyProject build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url "https://raw.github.com/ark/ark/master/releases/"
}
}
dependencies {
compile 'com.andreabaccega:android-form-edittext:1.0.3'
compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
compile 'com.google.android.gms:play-services:3.1.36'
compile files('libs/imageloader-core-1.5.8.jar')
compile project(':libs:Facebook')
}
android {
compileSdkVersion 17
buildToolsVersion "18.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['res']
res.srcDirs = ['res']
}
debug {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'libs/Facebook/src', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
resources.srcDirs = ['build', 'libs/Facebook/build/source/r/debug', 'libs/Facebook/build/source/buildConfig/debug']
res.srcDirs = ['res']
}
}
}
MyProject settings.gradle:
include ':MyProject'
include ':libs:Facebook'
Facebook build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion '18.1'
defaultConfig {
minSdkVersion 8
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['res']
res.srcDirs = ['res']
}
debug {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'build/source/r/debug', 'build/source/buildConfig/debug']
resources.srcDirs = ['build/source/r/debug', 'build/source/buildConfig/debug']
res.srcDirs = ['res']
}
}
}
Edit: I've tried adding the libs that I use in this project, in another project, one by one, to see what fails. Apparently these 2 are the culprits. If I include any or both of them, I get the above error.
compile 'com.astuetz:pagerslidingtabstrip:1.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
Any ideas on how to manage this ?
Edit2: Apparently another project presents the same issue. See build.gradle dependencies below. StickyListHeaders project doesn't contain anymore dependencies. So I presume it's because of ActionBarSherlock ?
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.7'
compile project(':Project Base:libs:StickyListHeaders')
}
Apparently there were 2 reasons for this issue.
1) PagerSlidingTabStrip library depends on a local support lib v4 jar. Remove the dependency and add the project as a library project in your app and inside it add the maven dependency for support v4. So it should look exactly like the Facebook library project from above.
2) RoboSpice library depends on LRUCache from support lib v4 (https://github.com/octo-online/robospice/issues/195). Just exclude it from your main build.gradle file and you should be good to go.
compile ('com.octo.android.robospice:robospice-spring-android:1.4.7')
{
exclude module: 'support-v4'
}
Hopefully this will help somebody and not spend an entire week with this problem like I did. Oh, and trillion of thanks to #Snicolas. Couldn't have solved it without his help.
Edit: As of RoboSpice v1.4.8, there is no more local support lib dependency, so this issue is fixed.
For anyone who happens to hit this error while using Visual Studio with Xamarin, like I did;
I solved it by simply removing the reference to "Xamarin.Android.Support.v4" from the References folder within the project, then cleaned and built project as normal.
When this is for Xamarin.Android, this error occurs for version mismatching between depended packages. You've got to remove this Xamarin.Android.Support.v4 package from the project along with other mismatching packages. (What does mismatching means here is, if your target Android version is Android 6, all packages listed in the packages.config file should have targetFramework="monoandroid60" packages. If any package won't abide this, it's a mismatching version). If you have messed with versions, then removing the reference and cleaning stuff alone won't work. You've got to remove all the mismatching packages from the Nuget Package Manager (Tools > NuGet Package Manager > Manage NuGet Packages for Solution...). Note that when you're to remove these packages, you'll also need to remove the depended packages. No harm go ahead and remove them all and you can re-install them with the correct version.
Once you've removed the package along with the dependent packages, try building the project. After a successful build, re-install the packages from the Nuget Package Manager with the correct version. (Package versions are listed according to the API levels, Ex: Android 6 which is API 23, would support packages of version 23.x.x)
Cleanup the project and build it, hopefully it'll succeed building!
Hope this'll help cleanup the mess!
Run "gradle androidDependencies" and check your dependencie tree. Add an exclude for the modules that are overlapped.
For example i had to do the following:
dependencies {
compile 'com.google.android:support-v4:r7'
compile project(':libraries:actionbarsherlock')
compile ('com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+') {
// Need to specifically exclude this as it is specified in our own project
exclude module: 'actionbarsherlock'
exclude module: 'support-v4'
}
}
The page slider library also have support library dependency. Thus you are getting this error. In case of maven all you need to do is change your main project pom file dependency entry of the support library to scope as provided.
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v4</artifactId>
<version>13</version>
<scope>provided</scope>
</dependency>
In case of gradle i think you need to change the dependency configuration to match maven provided scope
Please refer the following link for more details Convert Maven to Gradle
I just got this same issue. I simply updated all Xamarin.Android.Support… nuget packages to the same version.
Note: this app was older so I did not go to the Latest stable version as there were other dependencies that would have needed to be updated. I simply moved them all to the highest common version.
Good luck!
Tom
Remove all old reference .dlls and relevant to that and add again from NuGet.

Can't build project, problems with gradle?

I'm trying to switch from eclipse to android studio for my android development.
However, I still haven't found the right way to import my existing project.
I don't know if it is important: but I'm using a mac
I did the export step in eclipse, imported this gradle build in Android Studio, but when I try to build my project, it gives me this error:
Gradle:
FAILURE: Could not determine which tasks to execute.
* What went wrong:
Task 'assembleDebug' not found in project ':ProjectName'.
* Try:
Run gradle tasks to get a list of available tasks.
Could not execute build using Gradle installation '/Users/<username>/Development/Build/gradle-1.6'.
This is the build.gradle file that eclipse gave me:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.+'
}
}
apply plugin: 'android'
dependencies {
compile project(':ProjectName:library:ActionBarSherlock')
compile project(':ProjectName:library:facebook')
compile files('../../../../../../../ProjectName/libs/gcm.jar')
compile files('../../../../../../../ProjectName/libs/libGoogleAnalyticsV2.jar')
compile files('../../../../../../../ProjectName/libs/commons-lang3-3.1.jar')
compile files('../../../../../../../ProjectName/libs/actionbarsherlock-plugin-maps-4.2.0.jar')
compile files('../../../../../../../NiteOwl/libs/volley.jar')
compile project(':ProjectName:library:PullToRefresh')
compile project(':ProjectName:library:google-play-services_lib')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I've seen a lot of possible solutions, but none of them worked for me, any idea what I'm doing wrong?
The path to the project has no spaces in it
jar libraries => ProjectName/libs
android libraries => ProjectName/library
all of this was working in eclipse
We recently moved our project to gradle as well. We ran into issues due to the library projects.
To solve it we added a settings.gradle file in the root of your project with
include ':libs:actionbarsherlock'
include ':yourprojectname'
Add all your library projects from eclipse into the settings.gradle
We also made a build.gradle file for each of the library Projects.
AFAIK the export from eclipse doesn't deal well with library projects.
In the build.gradle at the root of your project (the one that's probably mostly empty), add the following line:
task assemble{}
Found at https://code.google.com/p/android/issues/detail?id=57531
I've had this error appear when I had a stray empty flavors stanza in my build.gradle:
productFlavors {
}

Gradle can't find dependency (Android support library)

I have a problem that Gradle can't find my dependency (Android support library).
My build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/FlurryAgent.jar')
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
compile files('libs/YouTubeAndroidPlayerApi.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
When I build (on commandline, no IDE) I get the following message:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'AndroidCalculator'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':compile'.
> Could not find com.google.android:support-v4:r7.
Required by:
:AndroidCalculator:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Why am I not allowed to add the Android Support library like this?
You have declared a repository dependency, but haven't declared a repository. Hence the dependency cannot be resolved. (Repositories/dependencies in the buildscript block are strictly separated from repositories/dependencies in the main build script.)
http://pastebin.com/FmcCZwA5
This paste is elaborate project with AndroidAnnotations, Dagger, Jackson and Robolectric.
all you need is add
repositories {
mavenCentral()
}
replace
compile group: 'com.google.android', name: 'support-v4', version: 'r7'
with (line 44 of the code linked above)
compile 'com.android.support:support-v4:18.0.+'
Gotchas: Last bit will works on Android Studio 0.2+ only if you had a fresh install. Since 0.2 Studio is shipped with its internal m2 repo to provide support and google api libraries so if you upgraded from previous versions your SDK doesn't have it.
also make sure local.properties file is present in root folder and sdk.dir points to SDK
You need to add additional dependency in dependencies tag. If you have android-support-v4.jar library in your libs folder, try to add code listed below:
dependencies {
compile files('libs/android-support-v4.jar')
}

Categories

Resources