Configuration with name 'default' not found error on Android Studio

跟風遠走 提交于 2019-12-02 06:28:31

问题


I am trying to test to reference without copying a library Project. So I created two projects one is ProjectA and one is LibraryA. Both projects are located inside the \StudioProjects folder. I am trying to reference LibraryA from ProjectA and I get the error at the title.

Here is settings.gradle from ProjectA

include ':app'
include ':LibraryA'
project(':LibraryA').projectDir = new File('../LibraryA')

Here is dependincies from app build.gradle of ProjectA

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile project(':LibraryA')
}

I am using Android Studio 1.5.1

If I remove compile project(':LibraryA') from dependencies it builds normally, however then I can't referance classes from LibraryA inside ProjectA.


回答1:


In your settings.gradle (ProjectA) you are referring the wrong folder.

include ':LibraryA'
project(':LibraryA').projectDir = new File('../LibraryA')

Checking your image, the LibraryA folder is a root folder.
Gradle is searching for a "module" build.gradle while in this folder there is a top-level file configuration.

You have to refer to the module inside the LibraryA

project(':LibraryA').projectDir = new File('../LibraryA/app')

Of course you have to pay attention if some tasks or variable are defined in the top-level file (LibraryA). In this case you have to clone them inside your top-level file (ProjectA)




回答2:


One of your projects does not have a valid gradle file. If your library is not a gradle project convert it to gradle project.

If you add your library as a module and select "gradle" when you are importing i think you'll solve your problem.




回答3:


I just do not understand what you want to do. But try changing the following line:

project(':LibraryA').projectDir = new File('../ProjectA')


来源:https://stackoverflow.com/questions/34199387/configuration-with-name-default-not-found-error-on-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!