gradle include library from another project

1.6k views Asked by At

I have this project setup (in Android AIDE):

|---Project1  
|     |---App  
|     |---Lib
|
|---Project2  
     |---App

I want add project 1 Lib as dependency (or linked source, because i only need to access 1 class from the library) to Project2.

Project2 settings.gradle:

include ':Lib'
project(':Lib').projectDir = new File(settingsDir, '../Project1/Lib')

Project2 build.gradle:

compile project(':Lib')

I am getting the following error:

Project dependency 'Lib' not found.

Is there anything wrong with the folder path? I didn't find any good solution for this problem and i am not very familiar with gradle.

If i would instead link the library source folder to Project2 i tried to add the following lines to the build.gradle (under android section):

 sourceSets {
    main.java.srcDirs += '/../Project1/Lib/src/main/'
}

I could access the source if i used the full path down to the folder with the class file but with the problem that when i instantiated the class from the Lib in Project2 it gave me the error that the class was not found inside the package.

Do both projects need to have the same package names? What would be the best solution to manage this without having the Library as an standalone library?

0

There are 0 answers