我知道它可能有多種風味與他們每個人的配置。但我有一個大的配置列表(約15),我不想在構建配置中定義15味道。我正在尋找一些基於循環使用Gradle構建任務的方法,它可以通過更改配置風格或任何類似的方法,而無需手動定義所有風格。構建多個apk與一個風味和多個配置
有什麼建議嗎?
更新時間:
repositories {
mavenCentral()
}
apply plugin: 'com.android.application'
android {
Properties props = new Properties()
props.load(new FileInputStream(file('build.properties')))
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.example.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
resConfigs "en"
versionCode props['VERSION_CODE'].toInteger()
versionName props['VERSION_NAME']
buildConfigField('boolean', 'DEBUG_MODE', "false")
buildConfigField('String', 'DEBUG_VERSION', props['EMPTY_STRING'])
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles 'proguard-rules.pro'
}
}
sourceSets {
sd_debug {
assets {
srcDirs('src/sd_debug/assets')
}
java {
srcDirs('src/sd_debug/java')
}
res {
srcDirs('src/sd_debug/res')
}
}
sp_debug {
assets {
srcDirs('src/sd_debug/assets')
}
java {
srcDirs('src/sd_debug/java')
}
res {
srcDirs('src/sd_debug/res')
}
}
sd_debug_devpackage {
assets {
srcDirs('src/sd_debug/assets')
}
java {
srcDirs('src/sd_debug/java')
}
res {
srcDirs('src/sd_debug/res')
}
}
sp_prod {
assets {
srcDirs('src/main/assets')
}
java {
srcDirs('src/sp_prod/java')
}
res {
srcDirs('src/sp_prod/res')
}
}
}
productFlavors {
// develop flavor
sd_debug {
buildConfigField 'String', 'DEBUG_VERSION', props['DEBUG_VERSION']
buildConfigField 'boolean', 'DEBUG_MODE', "true"
buildConfigField 'Integer', 'HOST_ID', "90"
}
sp_debug {
buildConfigField 'String', 'DEBUG_VERSION', props['DEBUG_VERSION']
buildConfigField 'boolean', 'DEBUG_MODE', "true"
buildConfigField 'Integer', 'HOST_ID', "1"
}
sd_debug_devpackage {
buildConfigField 'String', 'DEBUG_VERSION', props['DEBUG_VERSION']
buildConfigField 'boolean', 'DEBUG_MODE', "true"
buildConfigField 'Integer', 'HOST_ID', "91"
}
sp_prod {
buildConfigField 'boolean', 'DEBUG_MODE', "false"
buildConfigField 'Integer', 'HOST_ID', "1"
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude '.readme'
}
dexOptions {
jumboMode = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:design:$rootProject.supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
compile "com.google.android.gms:play-services-base:$rootProject.playServiceVersion"
compile "com.google.android.gms:play-services-gcm:$rootProject.playServiceVersion"
compile "com.google.android.gms:play-services-analytics:$rootProject.playServiceVersion"
compile "com.squareup.okhttp3:okhttp:$rootProject.okhttpVersion"
compile "com.google.code.gson:gson:$rootProject.gsonVersion"
compile "com.j256.ormlite:ormlite-core:$rootProject.ormliteVersion"
compile "com.j256.ormlite:ormlite-android:$rootProject.ormliteVersion"
compile "com.jakewharton:butterknife:$rootProject.butterknifeVersion"
compile "me.dm7.barcodescanner:zbar:$rootProject.zbarVersion"
compile "de.greenrobot:eventbus:$rootProject.eventbusVersion"
// compile "io.reactivex:rxjava:$rootProject.rxjavaVersion"
// compile "io.reactivex:rxandroid:$rootProject.rxjavaVersion"
compile "com.google.dagger:dagger:$rootProject.daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
// Dependencies for local unit tests
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"
// Android Testing Support Library's runner and rules
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
androidTestCompile "com.android.support.test:rules:$rootProject.ext.rulesVersion"
// Espresso UI Testing dependencies.
androidTestCompile "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support:design:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"
}
每種味道必須建立與API密鑰,和我有15個API密鑰。
您可以使用Groovy的全部功能集與它的表現力和緊湊性和動態性。是不是足夠以緊湊的方式定義您的口味,不需要太多重複?我沒有做Android開發,所以讓我看看你的構建有2或3種風格,我可能會告訴你如何使它更簡潔。 – Vampire
@吸血鬼謝謝你,請出示你的解決方案。 –
我沒有在任何地方看到'api'或'key'。哪個部分是您需要15次的部件,哪些部件在15個實例中有所不同? – Vampire