Skip to content

Commit 9f7e89d

Browse files
committed
add Android multi-module project example (hierarchical and flat project
layouts)
1 parent 716c40d commit 9f7e89d

File tree

7 files changed

+200
-0
lines changed

7 files changed

+200
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
This is an example of multi-module project gradle configuration.
3+
4+
### Hierarchical and Flat Project Layouts
5+
6+
In multi-module project `settting.gradle` is required to specify module location.
7+
( While for simple project you can play with build using `gradle -b` option
8+
to specify what `build.gradle` to use, e.g. `gradle -b second.gradle`,
9+
for multi-module project `settings.gradle` is the only way. )
10+
11+
hierarchical project layout
12+
13+
- app
14+
build.gradle
15+
- module
16+
build.gradle
17+
build.gradle
18+
settings.gradle
19+
20+
21+
flat project layout
22+
23+
- app
24+
build.gradle
25+
- module
26+
build.gradle
27+
- parent
28+
build.gradle
29+
settings.gradle
30+
31+
So with flat project layout you can achieve different composition for a build, e.g.
32+
33+
- app
34+
build.gradle
35+
- module
36+
build.gradle
37+
- parent
38+
build.gradle
39+
settings.gradle
40+
- second
41+
build.gradle
42+
settings.gradle
43+
44+
However when executing build from
45+
[command line](http://www.gradle.org/docs/current/userguide/gradle_command_line.html)
46+
for flat project layout, you may must to specify
47+
location of `settings.gradle` if it is not in current folder, e.g. when in `app` folder
48+
49+
gradle build -c ../parent/settings.gradle
50+
51+
_I think default file name should be `components.gradle` or other start with c._
52+
_Besides settings is t0o general word._
53+
54+
### Links
55+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apply plugin: 'android'
2+
3+
android {
4+
//{ for classic Android Eclipse project
5+
sourceSets {
6+
main {
7+
manifest.srcFile 'AndroidManifest.xml'
8+
java.srcDirs = ['src']
9+
resources.srcDirs = ['src']
10+
aidl.srcDirs = ['src']
11+
renderscript.srcDirs = ['src']
12+
res.srcDirs = ['res']
13+
assets.srcDirs = ['assets']
14+
}
15+
16+
// Move the tests to tests/java, tests/res, etc...
17+
androidTest.setRoot('tests')
18+
19+
// Move the build types to build-types/<type>
20+
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
21+
// This moves them out of them default location under src/<type>/... which would
22+
// conflict with src/ being used by the main source set.
23+
// Adding new build types or product flavors should be accompanied
24+
// by a similar customization.
25+
debug.setRoot('build-types/debug')
26+
release.setRoot('build-types/release')
27+
}
28+
//}
29+
compileSdkVersion 19
30+
buildToolsVersion "19.0.3"
31+
32+
defaultConfig {
33+
minSdkVersion 10
34+
targetSdkVersion 19
35+
versionCode 1
36+
versionName "1.0"
37+
}
38+
buildTypes {
39+
release {
40+
runProguard false
41+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
42+
}
43+
}
44+
}//android
45+
46+
dependencies {
47+
compile fileTree(dir: 'libs', include: ['*.jar'])
48+
compile project(':module')
49+
//// You must install or update the Support Repository through the SDK manager to use this dependency.
50+
//compile 'com.android.support:appcompat-v7:19.+'
51+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
mavenCentral()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:0.10.+'
9+
}
10+
}
11+
12+
/*
13+
allprojects {
14+
repositories {
15+
mavenCentral()
16+
}
17+
}
18+
*/
19+
20+
/*
21+
subprojects {
22+
23+
}
24+
*/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apply plugin: 'android-library'
2+
3+
android {
4+
//{ for classic Android Eclipse project
5+
sourceSets {
6+
main {
7+
manifest.srcFile 'AndroidManifest.xml'
8+
java.srcDirs = ['src']
9+
resources.srcDirs = ['src']
10+
aidl.srcDirs = ['src']
11+
renderscript.srcDirs = ['src']
12+
res.srcDirs = ['res']
13+
assets.srcDirs = ['assets']
14+
}
15+
16+
// Move the tests to tests/java, tests/res, etc...
17+
androidTest.setRoot('tests')
18+
19+
// Move the build types to build-types/<type>
20+
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
21+
// This moves them out of them default location under src/<type>/... which would
22+
// conflict with src/ being used by the main source set.
23+
// Adding new build types or product flavors should be accompanied
24+
// by a similar customization.
25+
debug.setRoot('build-types/debug')
26+
release.setRoot('build-types/release')
27+
}
28+
//}
29+
compileSdkVersion 19
30+
buildToolsVersion "19.0.3"
31+
32+
defaultConfig {
33+
minSdkVersion 1
34+
targetSdkVersion 19
35+
versionCode 1
36+
versionName "1.0"
37+
}
38+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
mavenCentral()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:0.10.+'
9+
}
10+
}
11+
12+
/*
13+
allprojects {
14+
repositories {
15+
mavenCentral()
16+
}
17+
}
18+
*/
19+
20+
/*
21+
subprojects {
22+
23+
}
24+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
includeFlat 'app'
2+
includeFlat 'module'
3+
4+
// see also settings.gradle in the root folder for hierarchical project layout
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include ':app'
2+
include ':module'
3+
4+
// see also settings.gradle in `parent` folder for flat project layout

0 commit comments

Comments
 (0)