13

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'
}
Community
  • 1
  • 1
owe
  • 4,890
  • 7
  • 36
  • 47
  • Is your question different from this one http://stackoverflow.com/questions/17033556/android-studio-fails-to-build? – Josh Gagnon Jun 21 '13 at 13:35
  • Hi, I edited my question and add the stacktrace. I don't think it's the same problem, because I can't build my project from command line. – owe Jun 23 '13 at 07:27
  • Would it be possible to also post your grade file? It is different that you can't build from the command line, but the only thing we can really see (no default configuration) doesn't provide much to go on as a single fact. – Josh Gagnon Jun 23 '13 at 12:46
  • I edit my post and add the gradle files. – owe Jun 23 '13 at 19:09

2 Answers2

19

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.

Josh Gagnon
  • 5,342
  • 3
  • 26
  • 36
  • Josh, Thank you very much! First I had some other problems, but after solving this it works. I will answer my question, perhaps it will help some other people. – owe Jun 24 '13 at 08:24
4

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
owe
  • 4,890
  • 7
  • 36
  • 47
  • Why should gradle version be set to 0.4.2? Everyone is using com.android.tools.build:gradle:0.7.+ these days. – IgorGanapolsky Jan 15 '14 at 21:01
  • 1
    As you can see the post was written in June last year and at this time I used AS 0.1.6. This release had to use the Android Gradle Plugin 0.4.+. This week already AS 0.4.2 was released and since AS 0.4.0 you have to use the Android Gradle Plugin 0.7.+. – owe Jan 16 '14 at 08:09