Quillion
Quillion

Reputation: 6476

Gradle custom library in an android app

I have the following project.

The project itself is me trying to experiment with me writing a library.

And this is what I would like to do

\project
|
--\android (android framework library)
|
--\androidExamples (this is where I fail)
| |
| --\game one (I would like this to be an android app)
| |
| --\game two (I would like this to be an android app)
| |
| --\game three (I would like this to be an android app)
|
--\androidUtils (android utilities library)
|
--\engine (physics engine library)
|
--\swing (swing framework library)
|
--\swingExamples
|
--\swingUtils (swing utilities library)

The problem I have run into is in androidExample subproject.
I would like it to have multiple subprojects where each subproject is an android app. However I do not seem to be able to posses the skills nor the knowledge to make it happen. Any pointer to an example or explanation will be greatly appreciated.

Upvotes: 0

Views: 108

Answers (1)

Elodie E2
Elodie E2

Reputation: 580

To achieve it, I thing you should read this doc: http://tools.android.com/tech-docs/new-build-system/user-guide Specially the "Multi project setup" section.

But basically you define in your build.gradle what you want your projects to be.

An app: apply plugin: 'com.android.application'

or an android library

apply plugin: 'com.android.library'

or a java project

apply plugin: 'java'

All your projects has its own build.gradle

Your main project will have a file called settings.gradle where you include all the "library/sub-project" you need + itself

include ':app','lib1','lib2'

Then you will have to include all the dependencies in your main build.gradle

dependencies {
    compile project(':lib1')
    compile project(':lib2')
}

So I think your project will be more something like

\project
|
--\android (android framework library)
|
--\androidExamples (MAIN PROJECT)
|
--\game one (android-library)
|
--\game two (android-library)
|
--\game three (android-library)
|
--\androidUtils (java)
|
--\engine (java)
|
--\swing (java)
|
--\swingExamples (do you really need it ?)
|
--\swingUtils (java)

Edit-

Here an example https://github.com/elodieferrais/MultiProjectSample

Upvotes: 1

Related Questions