2

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.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Tony
  • 1,603
  • 3
  • 21
  • 40
  • Try this: http://stackoverflow.com/questions/22743582/error-configuration-with-name-default-not-found-in-android-studio – Amy Dec 10 '15 at 10:30
  • I can't try that because my objective is to reference a library without copying it. – Tony Dec 10 '15 at 10:39
  • project(':LibraryA').projectDir = new File('../LibraryA'). In this path you have to refer the module inside the LibraryA project, not the root folder of this project, – Gabriele Mariotti Dec 10 '15 at 12:41
  • LibraryA is a Project and there is no module inside. Here is a [screenshot](http://i.imgur.com/Dgkiusm.png) that shows the inside of LibraryA folder. – Tony Dec 10 '15 at 13:07
  • 1
    The app folder is a module inside LibraryA. Check the answer below. – Gabriele Mariotti Dec 10 '15 at 13:47
  • @GabrieleMariotti thank you for your answer, it solved my problem. – Tony Dec 10 '15 at 14:02

3 Answers3

3

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)

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

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.

savepopulation
  • 11,736
  • 4
  • 55
  • 80
-1

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

project(':LibraryA').projectDir = new File('../ProjectA')
eVolaXx
  • 1
  • 4