错误:在 Android Studio 中找不到名称为“default”的配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22743582/
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
Error: Configuration with name 'default' not found in Android Studio
提问by Bot
I am using the volley library to perform network operation in android. So I am trying to add this library in my project which is created in Android Studio and gradle system.
我正在使用 volley 库在 android 中执行网络操作。所以我试图在我的项目中添加这个库,该项目是在 Android Studio 和 gradle 系统中创建的。
I added the volley library in my project but when I sync with gradle then I am getting error message. I tried all the answers which I see here but nothing worked for me.
我在我的项目中添加了 volley 库,但是当我与 gradle 同步时,我收到错误消息。我尝试了我在这里看到的所有答案,但没有任何效果对我有用。
Error message: Configuration with name 'default' not found in Android Studio
错误消息:在 Android Studio 中找不到名称为“default”的配置
Volley/build.gradle
凌空/build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
sourceSets {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
main {
assets.srcDirs = ['assets']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
java.srcDirs = ['src']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
app/build.gradle
应用程序/build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile project(':library:volley')
}
root/build.gradle
根/build.gradle
// 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.1'
}
}
allprojects {
repositories {
mavenCentral()
}
}
settings.gradle
设置.gradle
include ':app'
include ':library:volley'
采纳答案by Ajay S
Add your library folder in your root location of your project and copy all the library files there. For ex YourProject/library then sync it and rest things seems OK to me.
在项目的根位置添加库文件夹,并将所有库文件复制到那里。对于前 YourProject/library 然后同步它,其余的东西对我来说似乎没问题。
回答by ViliusK
Try:
尝试:
git submodule init
git submodule update
回答by alexgophermix
This is probably a rare case, but for me a library that was included in the settings.gradle was not there.
这可能是一种罕见的情况,但对我来说,settings.gradle 中包含的库并不存在。
E.g. I had: include ':libraries:Android-RateThisApp:library'
in my settings.gradle
例如我有:include ':libraries:Android-RateThisApp:library'
在我的 settings.gradle
but the folder Android-RateThisApp was empty. As soon as I checked out this submodule the gradle sync succeed.
但文件夹 Android-RateThisApp 是空的。一旦我检查了这个子模块,gradle 同步就成功了。
回答by Bj?rn Kechel
If you want to use the same library folder for several projects, you can reference it in gradle to an external location like this:
如果要为多个项目使用相同的库文件夹,可以在 gradle 中将其引用到外部位置,如下所示:
settings.gradle:
设置.gradle:
include 'app', ':volley'
project(':volley').projectDir = new File('../libraries/volley')
in your app build.gradle
在您的应用 build.gradle 中
dependencies {
...
compile project(':volley')
...}
回答by sharma_kunal
I also facing this issue but i follow the following steps:-- 1) I add module(Library) to a particular folder name ThirdPartyLib
我也面临这个问题,但我遵循以下步骤:-- 1)我将模块(库)添加到特定文件夹名称 ThirdPartyLib
To resolve this issue i go settings.gradlethan just add follwing:-
为了解决这个问题,我去settings.gradle而不仅仅是添加以下内容:-
project(':').projectDir = new File('ThirdPartyLib/')
project(':').projectDir = new File('ThirdPartyLib/')
:- is module name...
:- 是模块名称...
回答by PaulR
To diagnose this error quickly drop to a terminal or use the terminal built into Android Studio (accessible on in bottom status bar). Change to the main directory for your PROJECT (where settings.gradle
is located).
要诊断此错误,请快速转到终端或使用 Android Studio 内置的终端(可在底部状态栏中访问)。切换到您的项目的主目录(settings.gradle
位于何处)。
1.) Check to make sure your settings.gradle
includes the subproject. Something like this. This ensures your multi-project build knows about your library sub-project.
1.) 检查以确保您settings.gradle
包含子项目。像这样的东西。这可确保您的多项目构建了解您的库子项目。
include ':apps:App1', ':apps:App2', ':library:Lib1'
Where the text between the colons are sub-directories.
冒号之间的文本是子目录。
2.) Run the following gradle command just see if Gradle can give you a list of tasks for the library. Use the same qualifier in the settings.gradle
definition. This will uncover issues with the Library build script in isolation.
2.) 运行以下 gradle 命令,看看 Gradle 是否可以为您提供库的任务列表。在settings.gradle
定义中使用相同的限定符。这将单独发现库构建脚本的问题。
./gradlew :library:Lib1:tasks --info
3.) Make sure the output from the last step listed an "assembleDefault" task. If it didn't make sure the Library is including the Android Library plugin in build.gradle
. Like this at the very top.
3.) 确保上一步的输出列出了“assembleDefault”任务。如果它没有确保库在build.gradle
. 像这样在最顶端。
apply plugin: 'com.android.library'
I know the original poster's question was answered but I believe the answer has evolved over the past year and I think there are multiple reasons for the error. I think this resolution flow should assist those who run into the various issues.
我知道原发帖人的问题得到了回答,但我相信答案在过去一年中有所变化,我认为错误有多种原因。我认为这个解决流程应该可以帮助那些遇到各种问题的人。
回答by Devrim
Check the settings.gradle
file. The modules which are included may be missing or in another directory. For instance, with below line in settings.gradle
, gradle searches common-lib
module inside your project directory:
检查settings.gradle
文件。包含的模块可能丢失或位于另一个目录中。例如,在下面一行中settings.gradle
,gradlecommon-lib
在你的项目目录中搜索模块:
include ':common-lib'
If it is missing, you can find and copy this module into your project or reference its path in settings.gradle
file:
如果它丢失了,你可以找到这个模块并将其复制到你的项目中或在settings.gradle
文件中引用它的路径:
include ':common-lib'
project(':common-lib').projectDir = new File('<path to your module i.e. C://Libraries/common-lib>') //
回答by angryITguy
For me, (as per some comments I have seen), the issue was that gradle could not find the build.gradle for the imported library. This configuration is straight-forward but the error message is a bit cryptic. For instance I was using the android-map-utils project and had to include it in my settings.gradle by appending these 2 lines like this.
对我来说,(根据我看到的一些评论),问题是 gradle 找不到导入库的 build.gradle。此配置很简单,但错误消息有点神秘。例如,我正在使用 android-map-utils 项目,并且必须通过像这样附加这两行来将它包含在我的 settings.gradle 中。
include ':android-map-utils'
project(':android-map-utils').projectDir = new File(settingsDir, '..\..\modules\android-maps-utils-master\library')
Path of the library is relative to the my project's settings.gradle file. Then, I simply referenced it in my dependencies of my app's build.gradle file like this
库的路径是相对于我项目的 settings.gradle 文件的。然后,我只是在我的应用程序的 build.gradle 文件的依赖项中像这样引用它
...
dependencies {
....
compile project(':android-map-utils')
....
}
I recommend importing one module at a time, compiling and checking it.
我建议一次导入一个模块,编译并检查它。
回答by deva11
If suppose you spotted this error after removing certain node modules, ideally should not be present the library under build.gradle(Module:app) . It can be removed manually and sync the project again.
如果假设您在删除某些节点模块后发现此错误,则理想情况下不应出现 build.gradle(Module:app) 下的库。可以手动删除它并再次同步项目。
回答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() 。