Gradle sync Error:Configuration with name 'default' not found

Gradle sync Error:Configuration with name 'default' not found

我想添加一个外部库GuillotineMenu-Android in my application. I followed the steps given in the most upvoted answer to an existing question How do I add a library project to the Android Studio? 但是当我在第 6 步之后尝试构建项目时遇到错误,即在 app/build.gradle 中添加依赖项作为 compile project(":guillotinemenu")。我尝试了与此错误相关的所有 Whosebug 链接,但没有成功。我在我的应用程序目录中创建了一个名为 libs 的文件夹,并将项目文件夹 guillotine menu 复制到那里。这是我的 build.gradle(Module:app) 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.sunshine.bbreaker.appet_i"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.github.navasmdc:MaterialDesign:1.+@aar'
    compile 'com.android.support:appcompat-v7:22.0.+'

    // GuillotineMenu
    compile project(":guillotinemenu")
}

settings.gradle(项目设置) 文件:

    include ':app', ':guillotinemenu'
project(':guillotinemenu').projectDir = new File('libs/guillotinemenu')

build.gradle(项目:guillotinemenu) 文件:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}} allprojects {
repositories {
    jcenter()
}}

settings.gradle(项目:guillotinemenu) 文件:

include ':app', ':library'

build.gradle(guillotinemenu) 文件:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.yalantis.guillotine.sample"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':library')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.jakewharton:butterknife:6.1.0'
}

如果您需要更多信息,请告诉我。提前致谢。

你应该有这样的结构:

projectRoot
  app
     build.gradle
  library
     build.gradle
  build.gradle
  settings.gradle

每个模块都有自己的 build.gradle 文件。 root/settings.gradle 还定义了项目中的所有模块。不要在你的模块中使用另一个 settings.gradle。

settings.gradle中:

include ':app', ':library'

build.gradle

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.2.3'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    allprojects {
        repositories {
            jcenter()
        }
    }

library/build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion ...
    buildToolsVersion ...

    defaultConfig {
        ....
    }

}

dependencies {
   //....
}

app/build.gradle 中使用您的文件,但更改:

dependencies {
    //...
    // GuillotineMenu
    compile project(":library")
}

更新:

根据您在下面的评论,我认为在您的情况下,库文件夹是另一个项目的根文件夹。 这意味着你应该参考这个项目里面的模块

    projectRoot
      app
         build.gradle
      libs
         guillotinemenu
           build.gradle //top level file of guillotinemenu project
    -->>   module       
              build.gradle  //build.gradle of the module

因此请更改您的项目根目录的 settings.gradle。

 include ':app', ':guillotinemenu'
 project(':guillotinemenu').projectDir = new File('libs/guillotinemenu/module')

模块 (libs/guillotinemenu/module) 应该有一个 build.gradle 作为上面描述的 library/build.gradle.