Gradle sync错误:找不到名称为“default”的配置

时间:2015-07-11 06:03:34

标签: 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链接,但它没有成功。我在我的app目录中创建了一个名为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'
}

如果您需要更多信息,请与我们联系。提前谢谢。

1 个答案:

答案 0 :(得分:1)

你应该有这样的结构:

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