android - Gradle 同步错误 :Configuration with name 'default' not found

标签 android android-studio gradle dependencies build.gradle

我想添加一个外部库 GuillotineMenu-Android在我的申请中。我按照对现有问题 How do I add a library project to the Android Studio? 的最赞回答中给出的步骤进行操作 但是当我在第 6 步之后尝试构建项目时遇到错误,即当在 app/build.gradle 中添加依赖项作为 compile project(":guillotinemenu") 时。我尝试了与此错误相关的所有 stackoverflow 链接,但没有成功。我在我的应用程序目录中创建了一个名为 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(Project: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(Project: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

所以改变你projectRoot的settings.gradle。

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

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

关于android - Gradle 同步错误 :Configuration with name 'default' not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31353990/

相关文章:

android - Android 上的可下载主题

android - 通过android studio运行gradle与通过Terminal运行gradle吗?

java - 上传多个 jar 以 repo gradle

android - 失败 [INSTALL_FAILED_INVALID_APK]

android-studio - 我在使用 com.android.tools.build :gradle:2. 2.0-alpha2 构建应用程序时不断收到此错误

java - 如何通过 Kotlin Gradle 和 -D 为我的测试提供系统属性

java - 使用poi API读取XLSX文件不起作用

java - 反序列化Android Retrofit时Gson stackOverflown

java - 如何在 recyclerview 上添加 SetOnClicklistener

android - 如何在带有 Gradle 的 Android Studio 中使用 roboeletric?