import java.nio.file.Files import java.nio.file.StandardCopyOption apply plugin: 'com.android.application' static T getExtValue(Project proj, String key, T defaultValue) { if (proj.hasProperty(key)) { return proj.getProperties().get(key) } else { return defaultValue } } static String calculateApplicationId(Project proj) { String addOnName = proj.parent.name String defaultId = "com.anysoftkeyboard." if (proj.path.contains('languages')) { defaultId += "languagepack.${addOnName}" } else if (proj.path.contains('themes')) { defaultId += "theme.${addOnName}" } else if (proj.path.contains('quicktexts')) { defaultId += "quicktexts.${addOnName}" } else if (proj.path.contains('ime')) { defaultId = 'com.menny.android.anysoftkeyboard' } else { throw new IllegalStateException('Called on an APK project that has an unknown parent') } return getExtValue(proj, "override_app_id", defaultId) } apply from: "${rootDir}/gradle/android_general.gradle" android { defaultConfig { applicationId calculateApplicationId(project) } applicationVariants.configureEach { variant -> variant.outputs.all { outputFileName = "${project.path.substring(1).replace(':', '-')}-${android.defaultConfig.versionCode}.apk" } variant.assembleProvider.configure { assemble -> assemble.doLast { copy { from variant.outputs*.outputFile into "${rootDir.absolutePath}/outputs/apks/${variant.dirName}/" } } } } def keystoreFile = file("/tmp/anysoftkeyboard.keystore") signingConfigs { release { if (keystoreFile.exists()) { storeFile keystoreFile storePassword System.getenv("KEY_STORE_FILE_PASSWORD") keyAlias getExtValue(project, 'override_release_key_alias', 'packs') keyPassword System.getenv("KEY_STORE_FILE_DEFAULT_ALIAS_PASSWORD") println "Using '${storeFile.absolutePath}' to release APK ${path} (with alias '${keyAlias}')." } else { println "Could not find '${keystoreFile.absolutePath}' file. Release APK will not be signed." } } } buildTypes { release { if (keystoreFile.exists()) { signingConfig signingConfigs.release } zipAlignEnabled true debuggable false minifyEnabled false } } } if (project.ext.shouldBePublished) { project.apply plugin: 'com.github.triplet.play' play { // you can promote from command-line by specifying the track to promote to: // ./gradlew promoteReleaseArtifact -DdeployChannel=beta -DdeployFraction=1.00 track = System.getProperty('deployChannel', 'alpha') userFraction = Double.parseDouble(System.getProperty('deployFraction', '1.0')).doubleValue() if (userFraction < 1.0) { releaseStatus = 'inProgress' } else { releaseStatus = 'completed' } serviceAccountCredentials = file('/tmp/apk_upload_key.json') if ('alpha' != track) { //to keep things simple, we will only specify release-notes in the alpha //channel Files.copy( project.file('src/main/play/release-notes/en-US/alpha.txt').toPath(), project.file("src/main/play/release-notes/en-US/${System.getProperty('deployChannel', 'alpha')}.txt").toPath(), StandardCopyOption.REPLACE_EXISTING) } } //verifying release-notes file File playStoreWhatsNewFile = file("${project.projectDir}/src/main/play/release-notes/en-US/alpha.txt") if (!playStoreWhatsNewFile.exists()) { throw new FileNotFoundException("Can not find whatsnew file for Play-Store upload at ${playStoreWhatsNewFile}!") } if (playStoreWhatsNewFile.text.length() > 500) { println("Locale " + Locale.getDefault()) println("file encoding " + CharsetToolkit.defaultSystemCharset) println("File contents:") println("***" + playStoreWhatsNewFile.text + "***") throw new IllegalStateException("whatsnew file can not be longer than 500 characters! Currently " + playStoreWhatsNewFile.text.length()) } } else { println("Project ${path} is NOT marked for publishing") } apply from: "$rootDir/gradle/versioning_apk.gradle"