I am trying to move my Android project form IDEA to Android Studio with Gradle.
However, I am having difficulties with the dependencies. I removed my "lib" dir, so the jars would be retrieved from maven. But how do I correctly add them?
E.g. org.apache.commons.lang3
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android.gms:play-services:4.1.+'
compile 'org.apache.commons:commons-lang3:2.6.+'
}
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')
}
}
This results in:
Failed to refresh Gradle project 'idoms-android'
Could not find commons:commons-lang3:3.0.
It seems to be in the Maven Repository though.
You are missing this at the top level (i.e., a peer of android and dependencies):
repositories {
mavenCentral()
}
The buildscript block has repositories and dependencies for the build process. You also need repositories and dependencies at the top level for the dependencies for your project itself.
dependencies {
compile 'org.apache.commons:commons-lang3:3.4'
}
Add above line in your build.gradle file, this is the latest version.
Also you can check it from here:
mvnrepository, Apache Commons Lang ยป 3.4
Related
I solved this problem a long time. Who encountered this problem.thanks!
Check what compileSdkVersion version you have already in your build.gradlefile. Chenge to 23, if you have another one.
Try also File -> Invalidate Caches/Restart as well Build -> Clean and Build -> Rebuild project to solve doubled dependencies.
Hope it help
Here's my build.gradle
apply plugin: 'com.android.application'
buildscript {
repositories {`enter code here`
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:+'
}
android {
compileSdkVersion 23
buildToolsVersion '23.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')
}
}
I am getting an error like this when I am trying to import build.gradle file which I exported from Eclipse
build.gradle code:
// 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.+'
}
}
app module build.gradle which has been generated by Eclipse looks like this
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':android-crop-master:lib:src:main')
compile project(':sharebubbles_menu')
compile project(':braintree-1.2.5-project')
compile project(':facebook')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
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')
}
}
The following is screenshot.
You should update the version of gradle/gradle-plugin/AS that you are using.
Use these versions:
- AS 1.1.0
- Gradle 2.2.1
- Gradle plugin 1.1.0
Then change your build script:
// 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:1.1.0'
}
}
And your module script:
apply plugin: 'com.android.application'
dependencies {
// The same
}
android {
//Rename your instrumentTest folders to androidTest, e.g. git mv app/src/instrumentTest app/src/androidTest.
// Move the tests to tests/java, tests/res, etc...
androidTestCompile.setRoot('tests')
}
}
All info about the Instrumentation Tests migration is here
I was following the instructions from the Android Developer's page for Instrumented Unit Tests.
https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
I was getting the same error. The errors went away when I moved my edits from the gradle.build (Project: xxx) file to the gradle.build (Module: App).
Thankfully I noticed that there are two gradle.build files or I would still be trying to compile now.
I have problem with Android Studio in build.gradle after I converted Eclipse project to Android Studio project.
I spent more than 2 hours finding a solution, with no results!!
build.gradle code:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "17.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')
}
}
It gives: Error:(1, 0) Plugin with id 'com.android.application' not found.
Screen Shot
Any help will be appreciated ...
This error message means that it can't find the plugin at all. In Gradle, you need to tell it where to go to look for plugins, which is different from telling it where to go to resolve module dependencies. Add this block to the beginning of your build file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In projects that Android Studio creates, the New Project wizard will put this in the top-level build file in your project, but based on the screenshot it looks like your project only has a single build file, so there's only one place to put it.
Using this guide I want to build an existing project in Eclipse with Gradle.
build.grale contains:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.0'
}
}
apply plugin: 'android'
android {
buildToolsVersion "19.1.0"
compileSdkVersion 16
}
repositories {
mavenCentral()
}
dependencies {
compile files('libs/android-support-v4.jar')
}
But I get:
How to resolve this issue? I tried for several hours different approaches but nothing seemed to work.
The default project structure has changed, so unless you either tell the Gradle plugin where to find your manifest (and the rest of your code) or switch to the new structure, the Gradle plugin will look in the wrong place.
In your case, it is looking for the manifest at\src\main\AndroidManifest.xml, which is the default for new Gradle projects. The old project structure (used by Eclipse + ADT) puts the manifest in the root of your project at \AndroidManifest.xml.
You can specify an alternate location in your build.gradle using a sourceSets closure like so:
android {
// ...
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
This will configure the Android Gradle plugin to use the old project structure for your manifest, Java sources, and resources.
If you use Android Studio's import tool, it should take care of all of this for you.
That guide has nothing to do with building an existing Eclipse project with Gradle. The word "Eclipse" appears nowhere in the guide.
If you are trying to move to Android Studio, use the Android Studio project import wizard.
If you are trying to use Eclipse, but also offer Gradle builds, you can run the Eclipse export wizard to generate a build.gradle file, though it will require some additional tweaking, as that wizard has not been updated in ages.
Or, start with this build.gradle file and adjust to suit:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:support-v4:21.0.0'
}
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')
}
}
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'
}
.......