Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Setup external project as module

I need to use an external project(ResuableProject) as module in multiple projects(one of which is ProjectOne). What I've done here so far is:

Added following in settings.gradle of ProjectOne

include ':ProjectOne', ':ResuableProject'
project(':ResuableProject').projectDir = new File(settingsDir, '../ResuableProject/module')

Added following in build.gradle

dependencies {
    compile project(':ResuableProject')
}

After that gradle sync without any error and in Project Explorer the module is included but when I use any class from ResuableProject it gives me an error that class cannot be found until I click on class name and it give me an option to add dependency on ResuableProject. When I select the option the class is accessible and it seems all working fine. But when I Build the project and try to run it gives me this:

Error:Execution failed for task ':ProjectOne:compileDevDebugJava'.
> Compilation failed; see the compiler error output for details.
Error:(10, 30) error: package <packagename of ResuableProject> does not exist

Am I missing something or do I have to include source directory of ResuableProject in ProjectOne, if yes the how?

Also is there a better way to use one common project across multiple apps? (not jar or maven cause I need to include source with every project and common project will be hosted in a separate git repo)

Previously I was using this approach with Eclipse (one common Library project) and including it in multiple apps.

UPDATE: Adding file system structure

workspace
----ResuableProject (Android Common stuff)
--------.git
--------module
----ProjectOne (Android App One)
--------.git
--------ProjectOne (module)
------------build.gradle
--------settings.gradle
----ProjectOne (Android App Two)
--------.git
--------ProjectOne (module)
like image 779
adnanyousafch Avatar asked Feb 02 '26 07:02

adnanyousafch


1 Answers

It turned out that you can add ResuableProject but cannot use its source if build.gradle has value apply plugin: 'android' i.e. the type of the project is application.

I changed that to apply plugin: 'android-library' i.e. it must be a library and now everything is working fine.

like image 194
adnanyousafch Avatar answered Feb 04 '26 21:02

adnanyousafch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!