Hi I have following android project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
repositories {
mavenCentral()
}
android {
buildToolsVersion "17.0"
compileSdkVersion 17
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Now I would like to add another dependency: https://github.com/bauerca/drag-sort-listview.
I tried adding
compile 'com.mobeta.android.dslv:drag-sort-listview:0.6.1-SNAPSHOT'
but it doesn't work. How can I add this project as a Gradle dependency?
I saw that there is an option to copy this library as a subdirectory in my project dir. How should I include such a project?
The author of the library has to upload #aar bundle to maven central repository to make it work. As you can see drag sort listview is no longer mainted by author. You can use repo from the community as temporal solution.
repositories {
mavenCentral()
maven {
url 'https://github.com/Goddchen/mvn-repo/raw/master/'
}
}
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.mobeta.android.dslv:drag-sort-listview:0.6.1'
}
In general case you have to download sources and add them as library to your project.
I like to recommend you to use this library instead.
I thinks https://github.com/ened is thanksfully made the library for gradle and maintained it for a while.
compile 'asia.ivity.android:drag-sort-listview:1.0'
<dependency>
<groupId>asia.ivity.android</groupId>
<artifactId>drag-sort-listview</artifactId>
<version>1.0</version>
</dependency>
http://mvnrepository.com/artifact/asia.ivity.android/drag-sort-listview/1.0
https://github.com/ened/drag-sort-listview
Related
I have been trying to switch my project from Intellij to Android Studio, which has required me to create a build.gradle file. I know I can add each of these as a library dependency, but I ideally want to be able to get the maven repository dependency working.
Every time I sync, my support libraries are synced fine, but for each third-party library, I get something like
"Error:(30, 13) Failed to resolve:
com.facebook.android:facebook-android-sdk:3.23.1"
for each library.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Google Play Services
compile 'com.google.android.gms:play-services:6.5.87'
// Support Libraries
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:gridlayout-v7:21.0.3'
compile 'com.android.support:mediarouter-v7:21.0.3'
compile 'com.android.support:palette-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.android.support:support-annotations:21.0.3'
compile 'com.android.support:support-v13:21.0.3'
compile 'com.android.support:support-v4:22.0.0'
// third-party libraries
compile 'com.amazonaws:aws-java-sdk:1.9.24'
compile 'com.facebook.android:facebook-android-sdk:3.23.1'
compile 'com.github.markushi:android-ui:1.2'
compile 'de.hdodenhof:circleimageview:1.2.2'
compile 'it.neokree:MaterialNavigationDrawer:1.3.2'
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
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')
}
}
Add:
repositories {
mavenCentral()
}
to the build.gradle. Now you have repositories defined only in build script which resolves dependencies only for the buildscript itself not for the project.
Just to share infomation, I got same problem and the solution was different.
In my case, proxy server was used and it causes the problem. I needed to configure https proxy settings, as discussed in gradle behind proxy in Android Studio 1.3.
If you use VPN | Proxy on your system then use your proxy info in the gradle.properties file in your project like the following lines of code:
# HTTP Proxy
systemProp.http.proxyHost={Host Address}
systemProp.http.proxyPort={Port Number}
systemProp.http.proxyUser={Proxy Username}
systemProp.http.proxyPassword={Proxy Password}
systemProp.http.nonProxyHosts={NonProxy Hosts Address} # like: 127.0.0.1,localhost
# HTTPS Proxy
systemProp.https.proxyHost={Host Address}
systemProp.https.proxyPort={Port Number}
systemProp.https.proxyUser={Proxy Username}
systemProp.https.proxyPassword={Proxy Password}
systemProp.https.nonProxyHosts={NonProxy Hosts Address} # like: 127.0.0.1,localhost
Now just replace {.....} in the above code with appropriate data
Also you can set Android studio proxies like the following image by your proxy info in File>Settings:
Now test again...!
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
// mavenCentral()
}
this helps
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
in projects's gradle
Maybe this help
allprojects {
repositories {
jcenter()
}
}
well , if your network connection is fine(wheter using proxy | VPNs or not), simply just try turn off'offline mode' and sync when using android studio with gradle 2.3,this worked for me :)
Most of the settings do not currently work with new Android updates, so the solution currently is to add this section to buuild.Gradle(Project:)
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
}
}
******************************************
// Add this section if it does not exist
repositories {
mavenCentral()
}
******************************************
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
**********************************************
// Add this section if it does not exist
gradlePluginPortal()
**********************************************
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I am trying to implement ActionBar-PullToRefresh from https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-ABC. I just made the switch from Eclipse to Android Studio so I am totally new to AS and Gradle.
chrisbanes writes on the site:
The easiest way to add ActionBar-PullToRefresh to your project is via
Gradle, you just need to add the following dependency to your
build.gradle:
dependencies {
mavenCentral()
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}
Does this mean that I don't have to download the library and Gradle takes care of it so that I always have the latest version? I just don't know where to put the above line. I have two gradle.build files one in my root that looks like:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
and the one in my project which looks like:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
}
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')
}
}
Do I have to add a repository somewhere?
It will work when you put this line in your project build.gradle, in the dependencies section:
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
Also, add:
repositories {
mavenCentral()
}
So:
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}
Gradle will download the needed resources automatically for you.
Use https://jitpack.io/
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
dependencies {
compile 'com.github.User:Repo:Tag'
}
This is for Kotlin DSL (build.gradle.kts):
repositories {
// Other repositories...
maven("https://jitpack.io")
// OR maven { url = uri("https://jitpack.io") }
}
There are two places inside which you can insert the above code block:
The traditional way: inside top-level build.gradle.kts file
New way: inside a dependencyResolutionManagement { block in settings.gradle.kts file;
read more about this new feature at Gradle user guide: Centralized Repository Declaration
In the 3rd answer here:
How do I add a library project to Android Studio?
I found informations about how we can add ABSherlock library to project using gradle in Android Studio. But in this way we use "import module" option which doesn't exist any more in Android Studio 0.4.0. So how should I add ABSherlock or other library now ? (using gradle)
You can add this part to your build.gradle script
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
EDIT:
If you are using also the support library you can use it:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile ('com.actionbarsherlock:actionbarsherlock:4.4.0#aar'){
// Need to specifically exclude this as it is specified in ActionBarSherlock pom
exclude group: 'com.google.android', module: 'support-v4'
}
}
EDIT2:
If you would like to work with abs with a local copy ( I suggest you to use the maven dependency ) you can do this:
-root
-lib
-abs
build.gradle
src
res
-myModule
build.gradle
settings.gradle
In settings.gradle:
include ':myModule', ':lib:abs'
In lib/abs/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion XX
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
Remove the supportV4.jar from your local abs library.
In myModule/build.gradle you should add:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion XX
targetSdkVersion 19
}
}
dependencies {
// Libraries
compile project(':lib:abs')
}
If in myModule/build.gradle you need to use the support library, you should add:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
// Libraries
compile project(':lib:abs')
}
Working with gradle you should prefer to use dependencies in Maven.
However you can use local libraries with this structure above, editing your gradle files.
I'm switching my project over to using Gradle and an internal SonaType Nexus for hosting my dependencies. My core project depends on library project A and library project A has a dependency on library project B.
My issue is that as soon as I add LibA to my main project I get this error:
"Module version com.example:LibA:1.1 depends on libraries but is not a library itself"
I have no issues adding library projects with jar dependencies with the same build script. I have seen people doing this successfully with LOCAL (in the project) android libraries but no one doing it with maven repos.
Is this a bug in gradle or did I misconfigure the library builds?
Core Project Build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
maven {
url "http://localhost:8081/nexus/content/repositories/releases/"
}
maven {
url "http://localhost:8081/nexus/content/repositories/central/"
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile('com.example:LibA:1.+')
}
LibA Build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
versionCode = "3"
versionName = "1.2"
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile ('com.example:LibB:1.+')
} ...
LibB Build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
versionCode = "1"
versionName = "1.0"
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
repositories {
mavenCentral()
}
dependencies {
} ...
Edit: Adding -info output for the error.
* What went wrong:
A problem occurred configuring project ':GradleTest'.
> Failed to notify project evaluation listener.
> Module version com.example:LibA:1.+ depends on libraries but is not a library itself
Edit 2: Adding my local maven upload script for LibA
apply plugin: 'maven'
apply plugin: 'signing'
group = "com.example"
version = defaultConfig.versionName
configurations {
archives {
extendsFrom configurations.default
}
}
signing {
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: sonatypeRepo) {
authentication(userName: sonatypeUsername,
password: sonatypePassword)
}
pom.project {
name 'com-example'
packaging 'aar'
description 'none'
url 'https://internal github link'
scm {
url 'scm:git#https://internal github link'
connection 'git#https://internal github link'
developerConnection 'git#https://internal github link'
}
licenses {
license {
name 'example'
url 'example'
distribution 'example'
}
}
developers {
developer {
id 'example'
name 'example'
email 'example'
}
}
groupId "com.example"
artifactId rootProject.name //LibA
version defaultConfig.versionName
}
}
}
Your line in the dependencies to include LibA is wrong. To include a library project, use this:
compile project(':LibA')
If the library's directory isn't at the root of your project directory, you'll need to specify a colon-delimited path. For example, if your directory structure is:
projectFolder
|
+--coreProject
|
+--libraries
|
+--LibA
|
+--LibB
your dependency will be:
compile project(':libraries:LibA')
This is the same as the notation you use in your settings.gradle file.
Maybe problem is that you use mavenCentral as your repository for library projects
repositories {
mavenCentral()
}
and not yours nexus repository where actual dependencies exists
repositories {
maven {
url "http://localhost:8081/nexus/content/repositories/releases/"
}
maven {
url "http://localhost:8081/nexus/content/repositories/central/"
}
}
If you uploaded library artifact for both jar and aar, try this.
compile 'com.example:LibA:1.1.1#aar'
In my work, I have used compile project(':google-play-services_lib') instead of compile ('google-play-services_lib') when I declare dependent projects in my build.gradle file. I think that is the right way to do this with Gradle: http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:project_dependencies
if you don't want to have it as sub-module in the first build.gradle file you can add your local maven repository
mavenLocal()
//repositories
repositories {
mavenCentral()
mavenLocal()
}
but you need to run install on libA first.
I had a similar error message after introducing by mistake a cyclic dependency between libraries:
build.gradle in commons-utils
dependencies {
...
instrumentTestCompile project(':test-utils')
}
build.gradle in test-utils
dependencies {
...
compile project(':commons-utils')
}
Fixing this solved the problem. The error message is not very explicit.
Don't know for sure, just a couple of thoughts:
Have you tried running gradle assemble instead gradle build? This should skip tests, as I see error is related to test task.
Maybe stupid, but try to remove dependcy on 2nd lib from the first and put it to your main build file listing before the first. I have a memory of something related. This way the second lib may be added to classpath allowing the first to compile.
Try to create .aar files by hand and upload it to repo also by hand.
It's a hack, but maybe it'll work: have you considered to exclude this :GradleTest module? See section 50.4.7
This issue has gone away with the later versions of Gradle and the Android Gradle Plugin. Seems to have just been an early release bug.
I've never used Gradle before so I'm completely lost!
I've added SlidingMenu as a library and I have access from my project to all the SlindingMenu stuff, but trying to compile will give me this error:
Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist
I'm using Android Studio (so IntelliJ) and this is my gradle.build
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
Thanks in advance
Assuming you have added SlidingMenu.jar into libs folder, right click on it -> Add as library. Then change in gradle.build:
Before:
dependencies {
compile files('libs/android-support-v4.jar')
}
After:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will include all your jar files.
I had the same problem. Adding sliding-menu-lib from with gradle-build as android library did help me.
My project structure is as:
-MyDemoProject
-build.gradle
-settings.gradle
--MyDemo
--build.gradle
--libs
---sliding-menu-lib
----res
----src
----AndroidManifest.xml
----build.gradle
--src
To make all the stuff working your settings.bundle should have this contents:
include ':MyDemo' ':MyDemo:libs:sliding-menu-lib'
There is a trick here, which allows you avoid errors while building project with gradle using Android Studio, as according to Android Tools Manual you should use ':libs:sliding-menu-lib' but that does not work due to issue with relative projectDir paths.
Your MyDemo/build.gradle should contain dependencies like:
dependencies {
compile 'com.android.support:support-v4:18.0.0'
...
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':MyDemo:libs:sliding-menu-lib')
}
And your sliding-menu-lib/build.gradle should be like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 14
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
Most important part deals with sourceSets section as you may not want change sliding-menu-lib file structure (non-default for current gradle)
I added all of my previous libraries using the default import from source tool. For SlidingMenu I used the import with Maven then deleted all of the Maven dependancies from the Project Settings for SlidingMenu and reimported the Support libraries. This seemed to clear most issues up for me.
If the module is just a library and not a stand-alone app, it's gradle should contain
apply plugin: 'android-library'
instead of
apply plugin: 'android'
You can Sync Project with Gradle Files:
Tools -> Android -> Sync Project with Gradle Files
Recently found better solution for SlidingMenu separately:
You can add SlidingMenu as generated #aar file if you do not need to make any changes to it. Just use https://github.com/jzaccone/SlidingMenu-aar and make changes as in Readme file there.
Be careful with order of repos. This one should be above mavenCentral()