Android Studio的settings.gradle文件

I'm migrated from Eclipse to android studio 0.5.8, after importing my project to android studio i was getting the error Project with path ':progressfragment' could not be found in root project 'project_name'.

Project Struture :

Libs

enter image description here

Complete Structure (edit 2) :

enter image description here

Gradle.build:

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':progressfragment')
    compile project(':viewpagerindicatorlibrary')
    compile project(':ZBarScannerActivity')
    compile project(':google-play-services_lib')
    compile project(':SwitchCompatLibrary')
    compile project(':actionbarsherlock')
    compile project(':librarymultichoice')
}



buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

android {
    compileSdkVersion 14
    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')
    }
}
  • 6
    Don't you have any settings.gradle file? –  Salem  May 13 '14 at 19:54
  • @Salem no i don't have it –  Abdellah  May 13 '14 at 22:13
  • 2
    Question is not clear please include the comple project structure, where this gradle file is and how the project directory structure looks like because what you have given doesn;t even look like a gradle project. –  pyus13  May 14 '14 at 5:53
  • @pyus13 question edited –  Abdellah  May 14 '14 at 8:00
  • except the build.gradle nothing seems like a gradle project. Open Message Window from botton panel in AS and make sure it is not showing the warning message like "Not a Gradle Project" . –  pyus13 May 14 '14 at 8:45

2 Answers

up vote 90 down vote accepted

It's not enough to have just compile project("xy") dependency. You need to configure root project to include all modules (or to call them subprojects but that might not be correct word here).

Create a settings.gradle file in the root of your project and add this:

include ':progressfragment'

to that file. Then sync Gradle and it should work.

Also one interesting side note: If you add ':unexistingProject' in settings.gradle (project that you haven't created yet), Gradle will create folder for this project after sync (at least in Android studio this is how it behaves). So, to avoid errors with settings.gradle when you create project from existing files, first add that line to file, sync and then put existing code in created folder. Unwanted behavior arising from this might be that if you delete the project folder and then sync folder will come back empty because Gradle sync recreated it since it is still listed in settings.gradle.

  • 1
    module was not there in settings.gradle . I checked and included. It worked for me. –  Harish Gyanani Nov 29 '16 at 7:18
  • 1
    Thanks you, this should be the accepted answer. –  draksia  Jan 20 '17 at 20:17
  • Worked for me! Although I still find it very weird that Gradle works this way. Like why would I declare a "project("project-name"){//settings...}" in my build file, if I didn't want to include it? Why do I have to have a separate file where the only thing it contains is a list of all the projects I have defined in my actual build file. All those projects I defined in my build file? Yeah, I actually want them in my build! I'm curious if anyone knows the design reason behind settings.gradle? –  Steven Byks  Jun 27 '17 at 15:06
  • There are certain cases where you would want to include a module as part of your project but not use it as a dependency. For example on project I am working on we have 2 android apps, one is the UI part and the other is a content provider app. We do not want to be dependent on Content provider app during build time but would like to be able to easily change and look at it's code in the same project. –  PSIXO  Jun 28 '17 at 9:48

May be this answer helps for similar error I got similar error after deleting a subproject, removed "compile project(path: ':MySubProject', configuration: 'android-endpoints')" in build.gradle (dependencies) under Gradle Scripts

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值