build.gradle and project libs
I have a project in android studio that uses a project library. My problem is the configuartion of the gradle files.
I really tried a lot of solution that were posted here (define modul in project lib in settings as modul, sherlock example, setting right sourcesets ...), but I always get the same error (as soon as I add the lib debendency to my apps build.gradle file):
A problem occurred configuring project ':MyApp'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
I already did a clean and build from command line, but this has no effect. Is it possible that this is just a bug in the early version of Android Studio (like the comment in this post)? Or do I miss something?
My current Android Studio Version: 0.1.6 and my OS: Windows 7, 64bit
Please help me, I'm new to gradle and I never used maven or ant before.
EDIT 1:
gardelw compileDebug --stacktrace
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring pro
ject ':MyApp'.
at org.gradle.configuration.LifecycleProjectEvaluator.addConfigurationFa
ilure(LifecycleProjectEvaluator.java:79)
at org.gradle.configuration.LifecycleProjectEvaluator.notifyAfterEvaluat
e(LifecycleProjectEvaluator.java:74)
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(Lifecycle
ProjectEvaluator.java:61)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:465)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:76)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuil
dConfigurer.java:31)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:142)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions
.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.ja
va:33)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: org.gradle.listener.ListenerNotificationException: Failed to notify p
roject evaluation listener.
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java
:90)
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java
:30)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocat
ionHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy8.afterEvaluate(Unknown Source)
at org.gradle.configuration.LifecycleProjectEvaluator.notifyAfterEvaluat
e(LifecycleProjectEvaluator.java:67)
... 29 more
Caused by: org.gradle.api.artifacts.UnknownConfigurationException: Configuration
with name 'default' not found.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration
Container.createNotFoundException(DefaultConfigurationContainer.java:94)
at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(
DefaultNamedDomainObjectCollection.java:184)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration
Container.getByName(DefaultConfigurationContainer.java:84)
at org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependen
cy.getProjectConfiguration(DefaultProjectDependency.java:72)
at org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependen
cy_Decorated.getProjectConfiguration(Unknown Source)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.getPropert
y(BeanDynamicObject.java:146)
at org.gradle.api.internal.BeanDynamicObject.getProperty(BeanDynamicObje
ct.java:102)
at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeD
ynamicObject.java:78)
at org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependen
cy_Decorated.getProperty(Unknown Source)
at com.android.build.gradle.BasePlugin$_ensureConfigured_closure92.doCal
l(BasePlugin.groovy:1252)
at com.android.build.gradle.BasePlugin.ensureConfigured(BasePlugin.groov
y:1250)
at com.android.build.gradle.BasePlugin$ensureConfigured.callCurrent(Unkn
own Source)
at com.android.build.gradle.BasePlugin.resolveDependencyForConfig(BasePl
ugin.groovy:1214)
at com.android.build.gradle.BasePlugin$resolveDependencyForConfig.callCu
rrent(Unknown Source)
at com.android.build.gradle.BasePlugin.resolveDependencies(BasePlugin.gr
oovy:1164)
at com.android.build.gradle.BasePlugin$resolveDependencies.callCurrent(U
nknown Source)
at com.android.build.gradle.AppPlugin.doCreateAndroidTasks(AppPlugin.gro
ovy:196)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.gro
ovy:242)
at com.android.build.gradle.BasePlugin$_apply_closure1.doCall(BasePlugin
.groovy:190)
at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(Cl
osureBackedMethodInvocationDispatch.java:40)
at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(Cl
osureBackedMethodInvocationDispatch.java:25)
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java
:81)
... 33 more
BUILD FAILED
Total time: 2.947 secs
EDIT 2:
project structure:
MyProject
- MyApp
-- build.gradle
-- libraries
--- projectLib
--- build.gradle
- build.gradle
- settings
settings.gradle
include ':MyApp'
include ':libraries:projectLib'
// also tried to define projectLib as modul:
// project(':projectLib').projectDir = new File('MyApp/libraries/projectLib')
build.gradle of MyApp:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':libraries:projectLib') // adding this line
// --> build failed
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets{
main{
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['src/main/res']
aidl.srcDirs = ['res']
assets.srcDirs = ['assets']
renderscript.srcDirs = ['src']
}
}
}
build.gradle of projectLib:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets{
main{
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['res']
assets.srcDirs = ['assets']
renderscript.srcDirs = ['src']
}
}
}
EDIT 3:
settings.gradle
include ':MyApp'
include ':MyApp:libraries:projectLib'
build.gradle of MyApp:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile project(':MyApp:libraries:projectLib')
}
build.gradle of projectLib:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
I think you are specifying the path to your library project incorrectly. If I'm interpreting your project layout correctly the line should be the following:
compile project(':MyApp:libraries:projectLib')
When you start a project path with ':' you are making an absolute path from the root project and then basically just writing a path with ':' instead of '/'. In this case your projectLib module is in the directory MyProject/MyApp/libraries/projectLib, and MyProject is where your settings.gradle is, making it your root project. So swapping in colons for slashes gets you the line I wrote above.
You'll need to modify your settings.gradle to include the full path as well:
include 'MyApp:libraries:projectLib'
Finally, if you want to save some typing for stuff like your repository configuration you can put it in an allproject
block in your root project.
allprojects {
repositories {
mavenCentral()
}
}
A lot of nice little tips like that covered in the multi-module docs.
After long researches, several settings and the help of Josh, I solved my problem that is describes in the question above.
Now here my solution:
- set gradle version in your build.gradle files to 0.4.2
- use for support-library (e.g.: v4) "com.android.support:support-v4:13.0.0" (like its described here)
- in my case I had to install the "Android Support Repository" and "Google Repository" with the SDK Manager
- with the last edited gradle files (Edit 3) in my question --> my build was successful