-
-
Save Bramengton/38fc24ef432878d0084c1f74953e49e4 to your computer and use it in GitHub Desktop.
apply plugin: 'com.android.application' | |
@Nullable | |
def getProperties(String fileName) { | |
final Properties properties = new Properties() | |
def file = file(fileName) | |
if (file.exists()) { | |
file.withInputStream { stream -> properties.load(stream) } | |
} | |
return properties | |
} | |
static def getProperty(@Nullable Properties properties, String name) { | |
return properties.getProperty(name) ?: "$name missing" | |
} | |
android { | |
compileSdkVersion 25 | |
buildToolsVersion '25.0.3' | |
defaultConfig { | |
applicationId "io.brmtn.flavors" | |
minSdkVersion 11 | |
targetSdkVersion 23 | |
versionCode 1 | |
versionName "1.0" | |
} | |
lintOptions { | |
ignore 'ExtraTranslation', 'MissingTranslation' | |
abortOnError false | |
} | |
signingConfigs { | |
release { | |
def toolsPath = projectDir.getParent() + "/tools/" | |
try { | |
Properties properties = getProperties(toolsPath + "app.properties") | |
storeFile file(toolsPath + getProperty(properties, 'KEY_FILE')) | |
keyAlias getProperty(properties, 'KEY_ALIAS') | |
storePassword getProperty(properties, 'KEYSTORE_PASSWORD') | |
keyPassword getProperty(properties, 'KEY_PASSWORD') | |
} | |
catch (ex) { | |
throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in stored properties.") | |
} | |
} | |
} | |
buildTypes { | |
debug{ | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
release { | |
minifyEnabled false | |
proguardFiles = buildTypes.debug.proguardFiles | |
signingConfig signingConfigs.release | |
} | |
} | |
/* | |
* | |
* buildConfigField "int", "MAX_RETRIES", "3" | |
* buildConfigField "String", "SERVER_URL", "\"http://dev.myserver.com\"" | |
* buildConfigField "boolean", "STAGE_ONLY_THING", "true" | |
* | |
* manifestPlaceholders = [ appLabel: "@string/app_name" ] | |
* AndroidManifest.xml -> android:label="${appLabel}" | |
* | |
* */ | |
productFlavors { | |
develop_ { | |
manifestPlaceholders = [ appLabel: "@string/app_name" ] | |
buildConfigField "String", "SERVER_URL", "\"http://dev.myserver.com\"" | |
buildConfigField "boolean", "STAGE_ONLY_THING", "true" | |
} | |
brand1_ { | |
applicationId "com.brand.one" | |
buildConfigField "String", "SERVER_URL", "\"http://brand.one.com\"" | |
buildConfigField "boolean", "STAGE_ONLY_THING", "true" | |
manifestPlaceholders = [ appLabel: "Brand Name1" ] | |
} | |
brand2_ { | |
applicationId "com.brand.two" | |
buildConfigField "String", "SERVER_URL", "\"http://brand.two.com\"" | |
buildConfigField "boolean", "STAGE_ONLY_THING", "true" | |
manifestPlaceholders = [ appLabel: "Brand Name2" ] | |
} | |
brand3_ { | |
applicationId "com.brand.tree" | |
buildConfigField "String", "SERVER_URL", "\"http://brand.tree.com\"" | |
buildConfigField "boolean", "STAGE_ONLY_THING", "true" | |
manifestPlaceholders = [ appLabel: "Brand Name3" ] | |
} | |
} | |
} | |
dependencies { | |
compile 'com.android.support:appcompat-v7:25.3.1' | |
compile 'com.android.support.constraint:constraint-layout:1.0.2' | |
compile 'com.android.support:design:25.3.1' | |
} |
Можно задать собственное имя при компиляции проекта. Например, так.
defaultConfig {
project.ext.set("archivesBaseName", "MyName-" + defaultConfig.versionName);
}
Получим имя MyName-1.0.12-release.apk
или
defaultConfig {
project.ext.set("archivesBaseName", "${applicationId}-${versionName}-${versionCode}".toString());
}
Еше один вариант записи URL:
buildConfigField "String", "API_URL", '"http://developer.alexanderklimov.ru/api/debug/"'
Вариант с app_name:
resValue "string", "app_name", "AboutCat"
В таком случае нет необходимости в конструкции
* manifestPlaceholders = [ appLabel: "@string/app_name" ] * AndroidManifest.xml -> android:label="${appLabel}"
можно оставить стандартный вариант
AndroidManifest.xml -> android:label="@ string/app_name"
НО - главное это удалить строковый ресурс app_name в res/values/strings.xml, иначе получим ошибку при компиляции.
Как проверить все доступные варианты сборок: gradlew tasks
Как собрать все варианты сборк одновременно: gradlew assemble
Как собрать конкретный билд: gradlew assembleBrand1_
Дополнительно для gradlew:
clean - Deletes the build directory.
cleanBuildCache - Deletes the build cache directory.
Gradle - доходчиво, в примерах