Android 未找到名为“default”的配置。安卓工作室
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22547364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configuration with name 'default' not found. Android Studio
提问by colymore
I have an Android Studio app. It has a library dependency (Android-Bootstrap), when I try to sync gradle, it gives me an error:
我有一个 Android Studio 应用程序。它有一个库依赖项(Android-Bootstrap),当我尝试同步 gradle 时,它给了我一个错误:
Configuration with name 'default' not found.
未找到名为“default”的配置。
My structure is:
我的结构是:
-FTPBackup
-fotobackup
-build.gradle
-Libraries
-Android-Bootstrap
-Settings.gradle
-build.gradle
-Settings.gradle
-Build.gradle
The FTPBackup settings.gradle and build.gradle:
FTPBackup settings.gradle 和 build.gradle:
include ':fotobackup'
include ':libraries:Android-Bootstrap',':Android-Bootstrap'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And the build.gradle inside fotobackup is:
而 fotobackup 中的 build.gradle 是:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:+'
compile project (':libraries:Android-Bootstrap')
}
The library is downloaded from https://github.com/Bearded-Hen/Android-Bootstrapand it has build.gradle, settings etc.
该库是从https://github.com/Bearded-Hen/Android-Bootstrap下载的,它有 build.gradle、设置等。
whats wrong?
怎么了?
回答by Scott Barta
For one, it doesn't do good to have more than one settings.gradlefile -- it only looks at the top-level one.
一方面,拥有多个settings.gradle文件并不好——它只查看顶级文件。
When you get this "Configuration with name 'default' not found" error, it's really confusing, but what it means is that Gradle is looking for a module (or a build.gradle) file someplace, and it's not finding it. In your case, you have this in your settings.gradlefile:
当您收到此“未找到名称为‘默认’的配置”错误时,这确实令人困惑,但这意味着 Gradle 正在某处寻找模块(或 build.gradle)文件,但没有找到。在您的情况下,您的settings.gradle文件中有这个:
include ':libraries:Android-Bootstrap',':Android-Bootstrap'
which is making Gradle look for a library at FTPBackup/libraries/Android-Bootstrap. If you're on a case-sensitive filesystem (and you haven't mistyped Librariesin your question when you meant libraries), it may not find FTPBackup/Libraries/Android-Bootstrapbecause of the case difference. It's also looking for another library at FTPBackup/Android-Bootstrap, and it's definitely not going to find one because that directory isn't there.
这让 Gradle 在FTPBackup/libraries/Android-Bootstrap寻找一个库。如果您使用的是区分大小写的文件系统(并且您没有在问题中输入错误的Libraries当您指的是libraries),由于大小写不同,它可能找不到FTPBackup/Libraries/Android-Bootstrap。它还在FTPBackup/Android-Bootstrap寻找另一个库,它肯定不会找到,因为该目录不存在。
This should work:
这应该有效:
include ':Libraries:Android-Bootstrap'
You need the same case-sensitive spec in your dependencies
block:
您的块中需要相同的区分大小写的规范dependencies
:
compile project (':Libraries:Android-Bootstrap')
回答by lokesh kumar
compile fileTree(dir: 'libraries', include: ['Android-Bootstrap'])
Use above line in your app's gradle file instead of
在您的应用程序的 gradle 文件中使用上面的行而不是
compile project (':libraries:Android-Bootstrap')
回答by mahesh ren
In my setting.gradle, I included a module that does not exist. Once I removed it, it started working. This could be another way to fix this issue
在我的 setting.gradle 中,我包含了一个不存在的模块。一旦我删除它,它就开始工作。这可能是解决此问题的另一种方法
回答by Julian K
If you're getting this error with react native, it may be due to a link to an NPM package that you removed (as it was in my case). After removing references to it in the settings.gradle and build.gradle files, I cleaned and rebuilt and it's as good as new :)
如果您在使用 react native 时遇到此错误,则可能是由于指向您删除的 NPM 包的链接(就像我的情况一样)。在 settings.gradle 和 build.gradle 文件中删除对它的引用后,我进行了清理和重建,它和新的一样好:)
回答by Brandon Mowat
Just a note on this question:
关于这个问题的说明:
I had this exact error in my React Native app when trying to build to android. All you should have to do is $ npm i
.
尝试构建到 android 时,我在 React Native 应用程序中遇到了这个确切的错误。您所要做的就是$ npm i
。
回答by k3b
Case mattersI manually added a submodule :k3b-geohelper
to the
settings.gradle
file
案例事项我手动添加一个子模块:k3b-geohelper
的
settings.gradle
文件
include ':app', ':k3b-geohelper'
and everthing works fine on my mswindows build system
在我的 mswindows 构建系统上一切正常
When i pushed the update to github the fdroid build systemfailed with
当我将更新推送到 github 时,fdroid 构建系统失败了
Cannot evaluate module k3b-geohelper : Configuration with name 'default' not found
The final solution was that the submodule folder was named k3b-geoHelper
not k3b-geohelper
.
最终的解决方案是将子模块文件夹命名为k3b-geoHelper
not k3b-geohelper
。
Under MSWindows case doesn-t matter but on linux system it does
在 MSWindows 情况下无关紧要,但在 linux 系统上它确实如此
回答by Tom
I had this issue with Jenkins. The cause: I had renamed a module module
to Module
. I found out that git had gotten confused somehow and kept both module
and Module
directories, with the contents spread between both folders. The build.gradle
was kept in module
but the module's name was Module
so it was unable to find the default configuration.
我和詹金斯有这个问题。原因:我已将模块重命名module
为Module
. 我发现 git 不知何故弄糊涂了,并保留了module
和Module
目录,内容分布在两个文件夹之间。在build.gradle
被关在module
,但该模块的名字Module
,因此无法找到默认配置。
I fixed it by backing up the contents of Module
, manually deleting module
folder from the repo and restoring + pushing the lost files.
我通过备份 的内容Module
、module
从 repo 中手动删除文件夹并恢复 + 推送丢失的文件来修复它。
回答by gbhati
I also faced the same problem and the problem was that the libraries were missing in some of the following files.
我也遇到了同样的问题,问题是以下某些文件中缺少库。
settings.gradle, app/build.gradle, package.json, MainApplication.java
settings.gradle、app/build.gradle、package.json、MainApplication.java
Suppose the library is react-native-vector-icons then it should be mentioned in following files;
假设库是 react-native-vector-icons 那么它应该在以下文件中提到;
In app/build.gradle file under dependencies section add:
在依赖项部分下的 app/build.gradle 文件中添加:
compile project(':react-native-vector-icons')
编译项目(':react-native-vector-icons')
In settings.gradle file under android folder, add the following:
在 android 文件夹下的 settings.gradle 文件中,添加以下内容:
include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
包括 ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android' )
In MainApplication.java, add the following:
在 MainApplication.java 中,添加以下内容:
Import the dependency: import com.oblador.vectoricons.VectorIconsPackage;
导入依赖:import com.oblador.vectoricons.VectorIconsPackage;
and then add: new VectorIconsPackage() in getPackages() method.
然后在 getPackages() 方法中添加: new VectorIconsPackage() 。
回答by codenamezero
You are better off running the command in the console to get a better idea on what is wrong with the settings. In my case, when I ran gradlew check
it actually tells me which referenced project was missing.
您最好在控制台中运行该命令以更好地了解设置有什么问题。就我而言,当我运行gradlew check
它时,它实际上告诉我缺少哪个引用的项目。
* What went wrong:
Could not determine the dependencies of task ':test'.
Could not resolve all task dependencies for configuration ':testRuntimeClasspath'.
Could not resolve project :lib-blah.
Required by:
project :
> Unable to find a matching configuration of project :lib-blah: None of the consumable configurations have attributes.
The annoying thing was that, it would not show any meaningful error message during the import failure. And if I commented out all the project references, sure it let me import it, but then once I uncomment it out, it would only print that ambiguous message and not tell you what is wrong.
令人讨厌的是,在导入失败期间它不会显示任何有意义的错误消息。如果我注释掉所有的项目引用,确保它让我导入它,但是一旦我取消注释它,它只会打印那个模棱两可的消息,而不会告诉你出了什么问题。
回答by Gangnus
The message is a known Gradle bug. The reason of your error is that some of your gradle.build
files has no apply plugin: 'java'
in it. And due to the bug Gradle doesn't say you, where is the problem.
该消息是一个已知的Gradle 错误。您的错误的原因是您的某些gradle.build
文件中没有apply plugin: 'java'
。而且由于 Gradle 没有说你的错误,问题出在哪里。
But you can easily overcome it. Simply put apply plugin: 'java'
in every your 'gradle.build'
但是你可以很容易地克服它。只需放入apply plugin: 'java'
你的每一个 'gradle.build'