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 {
}
Related
I'm trying to build my android library project, which contains sub test project. Command to build: gradle clean connectedCheck
After task :dexTest I got error:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/json/simple/ItemList;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/apache/commons/lang3/CharRange$1;
Command gradle clean build ends successful. So my problem is that i can't run my tests. When i change plugin, in my build.gradle file, from 'android-library' to 'android' everything works fine.
Also, i'm added --info param and got this, before error
command: /home/username/adt-bundle/sdk/build-tools/18.1.1/dx --dex --output /home/username/android/build/libs/android-test.dex /home/username/android/build/classes/test /home/username/android/build/dependency-cache/test /home/username/android/libs/json_simple.jar /home/username/android/build/bundles/debug/classes.jar /home/username/android/build/bundles/debug/libs/json_simple.jar /home/username/android/libs/android-support-v4.jar /home/username/android/build/bundles/debug/libs/commons-lang3-3.1.jar /home/username/android/build/bundles/debug/libs/android-support-v4.jar /home/username/android/libs/commons-lang3-3.1.jar
What was that? Why it uses libraries from folder build/bundles/debug/libs/? This is the reason why I had error java.lang.IllegalArgumentException but why gradle takes libraries from that dir i don't understand.
Here my build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.3'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
testPackageName "ua.cooperok.stringcalc.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
sourceSets {
main {
manifest.srcFile file('AndroidManifest.xml')
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest {
manifest.srcFile file('tests/AndroidManifest.xml')
java.srcDirs = ['tests/src']
resources.srcDirs = ['tests/src']
res.srcDirs = ['tests/res']
assets.srcDirs = ['tests/assets']
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
}
Maybe it's a bug in android-library plugin?
While I do not know exact answer to the question, my colleagues from JetBrains supporting gradle in IntelliJ IDEA advised to ask the question at https://code.google.com/p/android/ because it's clearly an issue (and may be a bug) in Google Android Gradle Plugin for Eclipse, given that you work in Eclipse, as far as I recall from our conversation.
Now problem is no longer relevant. In build tools from version 0.7.2 it is fixed.
Piece of updates from tech doc
- Solve issue with local jar when testing library projects.
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.
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.
I'm using new Android studio, based on IDEA, and trying to build project with ABS library in dependencies for the main module.
And I'm getting errors:
Gradle: package com.actionbarsherlock.app does not exist
Gradle: cannot find symbol class SherlockActivity
Gradle: package com.actionbarsherlock.view does not exist
Gradle: cannot find symbol variable super
Gradle: cannot find symbol method setContentView(int)
....
Why and how to fix it?
I used build ok.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 7
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 was putting this as a comment because I wasn't sure if its your exact issue but it looks like abs isn't added as a module correctly. So I added as an answer
Try download abs fresh, extract it then in Android Studio - file > import module... and import the actionbarsherlock directory. After this however I had a error relating to junit so check the last steps in below post
Follow the steps here: Problems importing project into Android Studio regarding ActionBarSherlock
That post isn't your exact issue but the steps got abs working for me. so try that within your existing project
I did the import module, but i still had to add ActionBarSherlock as a dependency and then that got it working.
(actually i had the toplevel exception for mismatched support libs too, but then i got it working)
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')
}