What gradle task pulls dependencies from remote repositories? - android

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.

Related

Gradle build fails looking for Google Play Services in Android Studio

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.

Gradle import issues - Android

I am currently attempting to switch my project over to using gradle builds. While using the old build system I linked to the private/internal/hidden android API's by compiling the source and linking the classes.jar files before the Android libraries. I am currently trying to do the same thing in gradle with no luck at all.
With my current build.gradle file I receive the following error:
Gradle: A problem occurred evaluating project ':Launcher2'.
> Could not find method external() for arguments [file collection] on project ':Launcher2'.
If I remove these lines before "apply plugin: android"
dependencies {
compile files('libraries/classes.jar')
}
I receive errors about missing com.android.internal and com.android.common packages which are located in my classes.jar file.
Here's my build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
dependencies {
compile files('libraries/classes.jar')
}
plugin: 'android'
android {
buildToolsVersion "17.0"
compileSdkVersion 10
dependencies {
compile fileTree(dir: 'libraries', include: '*.jar')
compile project(':ActiveAndroid')
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Edit: After reading the gradle documentation a bit more I was able to successfully link the libraries into the project but the order of dependencies is wrong. The equivalent to what I am trying to do is adding both .jar files to the top of the classpath so that they are declared before the android SDK jar files.
I was digging through the source for the android gradle plugin, it seems that this may not be possible. The code seems incomplete and will not build. If anyone has any insight I would really appreciate it. Otherwise it looks like I will have to switch back to using Ant for now.

Building Android project with Gradle failed

I'm trying from yesterday to configure gradle to build Android project. I've got same error since then:
Failed to notify project evaluation listener.
Could not resolve all dependencies for configuration ':_DebugCompile'.
Could not find any version that matches com.android.support:support-v4:13.0.+.
The official fix on many sites is to install Android Support Repository. I have it installed already, but problem still occurs. I've run out of ideas what can be wrong here...
Here is full code:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
See http://tools.android.com/knownissues section Bundled Maven Repository
To fix this, open the SDK manager, and make sure that the "Android
Support Repository" (not just Android Support Library) is installed:
You need an additional block at the top level after your apply plugin line:
repositories {
mavenCentral()
}
In general, you need a repositories block at the same level as any dependencies block (hence why you also need one in the buildscript block).
Most of the time, you'd move your buildscript block to the top level build.gradle (so that all your modules use the same gradle build) rather than have them both at the module level.
com.android.support:support-v4:13.0.+ - this dependency isn't in Maven Central.
Try to use https://github.com/mosabua/maven-android-sdk-deployer
I got the same error when trying to build the Android samples. My problem appeared because the ANDROID_HOME was not set correctly.

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