I apologize if I am missing something obvious, but I recently converted my project from Eclipse to Android Studio (and Gradle) and am trying to add support for Floating Action Buttons using Melnykov's library, but Gradle cannot resolve it. I thought it was a simple matter of adding compile 'com.melnykov:floatingactionbutton:1.3.0' to my app's build.gradle file. Am I missing something or is the source not available to download or what? Thanks ahead of time.
My app's build.gradle file:
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:22.1.0'
compile files('libs/opencsv-3.1.jar')
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
}
android {
compileSdkVersion 22
buildToolsVersion "22"
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')
}
}
And the error I get is
Error:(6, 13) Failed to resolve:
com.makovkastar:floatingactionbutton:1.3.0
You have to add the repository from which gradle should download the aar.
repositories {
jcenter()
}
Without this part, gradle doesn't know where to find the dependencies.
The other libraries don't need the repo because they are local jars (they can be found in the lib folder):
compile files('libs/opencsv-3.1.jar')
or a local maven (provided with the sdk manager)
compile 'com.android.support:support-v4:22.1.0'
compile 'com.android.support:appcompat-v7:22.1.0'
The error seems to have been resolved after adding the jcenter repository like this. I don't fully understand it, but everything compiles now.
...
dependencies {
compile 'com.android.support:support-v4:22.1.0'
compile files('libs/opencsv-3.1.jar')
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
}
repositories {
jcenter()
}
...
Related
I am working on an Android project, which used Gradle as mentioned below.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':workspace:darkmoon:darul-android:vitamio:vitamio')
compile project(':Dev:adt-bundle-mac-x86_64:sdk:extras:google:google_play_services:libproject:google-play-services_lib')
}
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
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')
}
}
But when I build it, keep receiving this error: "Gradle DSL method not found", and it pointed to the
following line:
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':workspace:epsilonmobile:darul-android:vitamio:vitamio')
compile project(':Dev:adt-bundle-mac-x86_64:sdk:extras:google:google_play_services:libproject:google-play-services_lib')
}
Apologize if this question is a bit noob, I'm new to both Gradle and Android Studio
A classpath configuration is only available for buildscript dependencies. You need to get rid of the line classpath 'com.android.tools.build:gradle:0.12.+' in the top-level dependencies block. (Gradle plugins need to be declared under buildscript { dependencies { ... } }.)
In a gradle script, the buildscript is a special section where you can declare dependencies of the build script itself (i.e. binaries required by the build process).
The gradle build process is nothing more than a java process and so it supports normal classpath dependencies.
com.android.tools.build:gradle:0.12.+ identify a binary required by the build process (it contains code able to understand/execute the android section of the build script).
The android apk that will be build by this script don't needs the binary com.android.tools.build:gradle:0.12.+ to run on your android device (i.e. the apk is of course already build when it run on the device) : there is no reason to declare it again in the top level dependencies
(those are the dependencies required by your app)
This is my first project using Android Studio so spare me if you find this question naive. I am trying to include the Cardslib library to my project in Android Studio (version 0.8.1). Initially I tried to include it by adding the following line in build.gradle:
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
But it returned the following error (upon sync)
Error:Failed to find: com.github.gabrielemariotti.cards:library:1.7.3
The I tried to include the jar file by,
Downloading it from maven repository
Adding jar file to libs folder.
Adding following line in build.gradle
compile files('libs/library-1.7.3-sources.jar')`
Though gradle project sync without any error but I am not able to create simple cards i.e still not working for me.
I wanted the first method to work since Android Studio would then handle everything but I guess I am doing something horribly wrong.
[Edit] - Adding the build.gradle code
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
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 this block in your script to tell gradle where it can find the repo with libs.
repositories {
mavenCentral()
}
So your script will be something like this:
.......
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.gabrielemariotti.cards:library:1.7.3'
}
.......
I have exported my Android project in Eclipse as gradle build files, and imported in Android Studio.
I have updated my Android Studio today to v0.6.0 which built on June 05, 2014.
As a remote dependency I have added AppCompat to the dependencies which works fine as expected.
compile 'com.android.support:appcompat-v7:19.+'
But when I try to add other libraries such as SmoothProgressBar, actionbarsherlock, nineoldandroids and etc, it fails. When I run the app it shows following in Gradle Build tab:
Error:A problem occurred configuring root project 'MyApp'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
> Could not find com.github.castorflex.smoothprogressbar:library:0.5.1.
Required by:
:MyApp:unspecified
And when I sync project with Gradle file, it shows following in Gradle Sync tab:
Error:com.github.castorflex.smoothprogressbar:library:0.5.1 (double-click here to find usages.)
I tried an empty new project and add remote dependency for mentioned libraries(Sherlock and etc) worked as expected. So I guess I missed something in build.gradle or any other solution?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.castorflex.smoothprogressbar:library:0.5.1'
compile 'com.android.support:appcompat-v7:19.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
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 this code to your build.gradle
repositories {
mavenCentral()
}
Update to explain the answer:
To resolve your dependencies, you have to indicate in the gradle script which are the repositories to be used. You can use more repositories...
With the support libs (support and support-compact) it is not necessary, because the android plugin searches in your androidRepository and googleRepository downloaded with your SDK Manager.
In my build.gradle, I define some 3rd party libs, all of which are available in Maven Central.
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.guava:guava:15.0'
compile 'com.netflix.rxjava:rxjava-core:0.14.2'
compile 'com.netflix.rxjava:rxjava-android:0.14.2'
}
(We also have manually managed jars under libs (for Eclipse users), and I used to use those
for Gradle builds too, with compile fileTree(dir: 'libs', include: '*.jar'), but I'm trying to move away from that towards simpler, automated dependency management.)
Anyway, for some reason fetching the deps fails:
* What went wrong:
A problem occurred configuring root project 'MyApp-Android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
> Could not find com.google.code.gson:gson:2.2.4.
Required by:
:MyApp-Android:unspecified
> Could not find com.google.guava:guava:15.0.
Required by:
:MyApp-Android:unspecified
> Could not find com.netflix.rxjava:rxjava-core:0.14.2.
Required by:
:MyApp-Android:unspecified
> Could not find com.netflix.rxjava:rxjava-android:0.14.2.
Required by:
:MyApp-Android:unspecified
What am I doing wrong?
I was wondering if I should have
repositories {
mavenCentral()
}
...also on the top level of the build file (not just inside buildscript), but adding that didn't help.
Resolution
I was too hasty; that did help with "Could not resolve dependencies". After that I got compilation errors, but that was due to in fact having some more dependendies in the code (and in libs) than the four entries in dependendies above.
So in my case I had to add the top-level repositories pointing to Maven Central plus some additional dependiencies that we actually had:
compile 'com.squareup.okhttp:okhttp:1.2.1'
compile 'com.android.support:support-v4:13.0.0'
compile 'com.android.support:support-v13:13.0.0'
The (original, broken) full build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.1'
}
}
apply plugin: 'android'
dependencies {
// compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.guava:guava:15.0'
compile 'com.netflix.rxjava:rxjava-core:0.14.2'
compile 'com.netflix.rxjava:rxjava-android:0.14.2'
}
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
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')
}
}
Indeed you need to add a
repositories {
mavenCentral()
}
at the top level of your build.gradle to specify where to search for your dependencies.
buildscript {
repositories {
google()
=> mavenCentral() <=
}
So I have bees stuck on this all day on android studio.
I have tried to follow this tutorial to add support for google maps API for my application
https://developers.google.com/maps/documentation/android/start#install_the_android_sdk
but when I try to build the application this error appears
Gradle: Execution failed for task ':dexDebug'.
Could not call IncrementalTask.taskAction() on task ':dexDebug'
here is my build.gradel
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.30'
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 16
buildToolsVersion "18.1.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')
}
}
When I remove remove this line for testing the said error doesn't appear.
compile 'com.google.android.gms:play-services:4.0.30'
Does anyone know what the error code be?
Do you have the Play Services installed? In Android Studio, go to the SDK Manager. Under Extras, make sure you have the latest revision of Google Play services. After you install, you may have to restart Android Studio.
To double-check that 4.0.30 was downloaded, you can check that the Android Studio's local Maven repository contains the folder. The path is something like:
/Applications/Android Studio.app/sdk/extras/google/m2repository/com/google/android/gms/4.0.30