Project 目錄的build.gradle內容:java
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
//把相應的module下面的class文件打包成jar包
task buildPluginLib (type: Jar, dependsOn:'compileDebugJavaWithJavac') {
from (project.buildDir.toString()+'/intermediates/classes/debug')
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
主工程裏面的Gradleandroid
apply plugin: 'com.android.application'
//apply plugin: 'android-library'
buildscript {
repositories {
jcenter()
}
// dependencies {
// classpath 'com.android.tools.build:gradle:1.3.0'
// }
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
//compile 'com.android.support:multidex:1.0.0'
}
/*afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
// optional
// dx.additionalParameters += "--main-dex-list=$projectDir/<filename>".toString() // enable the main-dex-list
}
}*/
android {
dexOptions {
jumboMode true
//preDexLibraries = false
//javaMaxHeapSize "2g"
}
signingConfigs {
config {
keyAlias 'smarthome'
keyPassword 'xxxx'
storeFile file('E:/StudioWork/MyApplication4/SmartHome2.0/key/smarthome.keystore')
storePassword 'xxxxx'
}
}
defaultConfig {
applicationId "com.suning.smarthome"
minSdkVersion 14
targetSdkVersion 19
versionCode 218
versionName "2.1.8"
// dex突破65535的限制
//multiDexEnabled true
// AndroidManifest.xml 裏面UMENG_CHANNEL的value爲 ${APP_CHANNEL_VALUE}
// manifestPlaceholders = [APP_CHANNEL_VALUE: "channel_name"]
}
compileSdkVersion 19
buildToolsVersion "23.0.2"
/*defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}*/
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
debug {
signingConfig signingConfigs.config
debuggable true
}
release {
// 移除無用的resource文件
// shrinkResources true
debuggable true
signingConfig signingConfigs.config
debuggable false
proguardFile 'E:/StudioWork/MyApplication4/SmartHome2.0/proguard.cfg'
minifyEnabled true
zipAlignEnabled true
}
}
/*<meta-data
android:name="SUNING_CHANNEL"
android:value="${SUNING_CHANNEL_VALUE}" />*/
/*productFlavors {
wandoujia {}
baidu {}
c360 {}
uc {}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [SUNING_CHANNEL_VALUE: name]
}
}*/
}
插件工程,依賴主工程的配置方式:app
apply plugin: 'com.android.application'
//apply plugin: 'android-library'
buildscript {
repositories {
jcenter()
}
// dependencies {
// classpath 'com.android.tools.build:gradle:1.3.0'
// }
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
//compile project(':SmartHome2.0')
//provided project(':SmartHome2.0')
provided files('../../SmartHome2.0/build/libs/SmartHome2.0.jar')
provided fileTree(include: ['*.jar'], dir: '../../SmartHome2.0/libs')
}
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
task beforeBuild(dependsOn: [':SmartHome2.0:buildPluginLib']) << {
println 'do it before build'
}
preBuild.dependsOn beforeBuild