I have successfully incremented version code. But I only want to increment it while I do generate signed apk from menu Build -> Generate signed APK. Following is my gradle code.
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['build.version'].toInteger() + 1
versionProps['build.version']=code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
applicationId "com.test"
multiDexEnabled true
versionCode code
versionName "1.1"
minSdkVersion 18
targetSdkVersion 23
}
}
else {
throw new GradleException("Could not read version.properties!")
}
buildTypes {
release {
//minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
preDexLibraries = false
}}
And my version.properties file contains following info:
Minor=7
Branch=4
Major=10
build.version=73
I am able to do it by hooking up my code on assembleRelease gradle task. Got help from Tim's blog. Following is the code-
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
def Properties versionProps = loadVersionFile()
defaultConfig {
applicationId "com.test"
multiDexEnabled true
versionCode getCode(versionProps)
versionName getName(versionProps)
minSdkVersion 18
targetSdkVersion 23
}
signingConfigs {
release {
storeFile file(".../keys.jks")
storePassword "..."
keyAlias "..."
keyPassword "..."
}
}
buildTypes {
release {
signingConfig signingConfigs.release
//minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
}
dexOptions {
...
}
}
def loadVersionFile() {
def versionPropsFile = file('version.properties')
def Properties versionProps
if (versionPropsFile.canRead()) {
versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
} else {
throw new GradleException("Could not read version.properties!")
}
return versionProps}
def getCode(Properties versionProps) {
return versionProps['build.version'].toInteger()}
def getName(Properties versionProps) {
return versionProps['product.version']}
assembleRelease << {
def versionPropsFile = file('version.properties')
def code
def Properties versionProps
if (versionPropsFile.canRead()) {
versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
code = versionProps['build.version'].toInteger() + 1
} else {
throw new GradleException("Could not read version.properties!")
}
versionProps['build.version'] = code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
project.android.defaultConfig.versionCode code}
allprojects {
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'libs'
}
maven {
...
}
}}
dependencies {...}
apply plugin: 'com.google.gms.google-services'
To find out where you have to place the gradle.properties
Extract the whole signing config
First option is, to extract the whole signing config to a separate user file. Create a new property in your gradle.properties:
MyProject.signing=/home/username/.signing/myproject
MyProject doesn’t need to match any application names or so, you can in fact name the property whatever you like. Also if you’re on windows use \ instead of /.
Place your keystore at /home/username/.signing/myproject.keystore.
Now create a file name myproject.gradle in /home/username/.signing (create the folder if necessary). This file will contain your signing config, that should be used to sign the package. This could look like the following:
android {
signingConfigs {
release {
storeFile file(project.property("MyProject.signing") + ".keystore")
storePassword "mypassword"
keyAlias "KeyAlias"
keyPassword "mypassword"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
Now its time to configure the actual build.gradle file in the project you want to use this signing config. Just add the following lines to it:
if(project.hasProperty("MyProject.signing")
&& new File(project.property("MyProject.signing") + ".gradle").exists()) {
apply from: project.property("MyProject.signing") + ".gradle";
}
Only extract some variables from file
project.ext {
uploadRepo = 'http://....'
uploadUser = 'myusername'
uploadPass = 'mypass'
}
Now make sure you only use the variables if they are available by putting the configuration in the if after you loaded the file. So your build.gradle could look like that:
if(project.hasProperty("MyProject.signing")
&& new File(project.property("MyProject.signing") + ".gradle").exists()) {
apply from: project.property("MyProject.signing") + ".gradle";
// Configure stuff that relies on these variables
uploadArchives {
repositories.mavenDeployer {
repository(url: uploadRepo) {
authentication(userName: uploadUser, password: uploadPass)
}
}
// .. whatever else you need ...
}
}
Only extract some strings from file
Again add a path to your gradle.properties (let’s do it a full path this time):
MyProject.properties=/home/username/.signing/myproject.properties
if(project.hasProperty("MyProject.properties")
&& new File(project.property("MyProject.properties")).exists()) {
Properties props = new Properties()
props.load(new FileInputStream(file(project.property("MyProject.properties"))))
android {
signingConfigs {
release {
storeFile file(props['keystore'])
storePassword props['keystore.password']
// ...
}
}
}
}
Just generate a plain properties file at /home/username/.signing/myproject.properties:
keystore=/path/to/my/keystore
keystore.password=mypassword
Related
Hi I am trying to include debug debug symbols in android app bundle generated by flutter. But it doesn't include debug symbols. This is my release build configuration. It once worked but after I added abi filters it stopped working.
buildTypes {
release {
minifyEnabled true
// multiDexKeepFile file('multidex-config.txt')
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
// useProguard true
ndk {
debugSymbolLevel 'SYMBOL_TABLE'
abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
}
Here is the complete build.gradle file
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
//CRASHLYTICS
apply plugin: 'com.google.firebase.crashlytics'
//END Crashlytics
android {
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "it.medory.app"
minSdkVersion 21
targetSdkVersion 31
versionCode 4033
versionName "1.0.9"
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
minifyEnabled true
// multiDexKeepFile file('multidex-config.txt')
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
// useProguard true
ndk {
debugSymbolLevel 'SYMBOL_TABLE'
abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
}
buildToolsVersion '30.0.3'
ndkVersion '21.4.7075529'
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
implementation "androidx.browser:browser:1.4.0"
//CRASHLYTICS
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:29.0.1')
// Declare the dependencies for the Crashlytics and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
//END CRASHLYTICS
}
Any one knows how to include debug symbols in app bundle generated using flutter.
I have already installed the NDK version '21.0.6113669' but still while I am trying to Sync Project with Gradle Files , getting the following error:
NDK not configured. Download it with SDK manager. Preferred NDK version is '21.0.6113669'.
Update NDK version to 21.0.6113669 and sync project
Kindly find below my build.gradle
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
plugins {
id "com.android.application"
}
android {
compileSdkVersion project.properties.compileSdkVersion.toInteger()
ndkVersion '21.0.6113669'
dependencies {
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.viewpager:viewpager:1.0.0"
implementation "androidx.drawerlayout:drawerlayout:1.1.0"
implementation project(":terminal-view")
}
defaultConfig {
applicationId "com.termux"
minSdkVersion project.properties.minSdkVersion.toInteger()
targetSdkVersion project.properties.targetSdkVersion.toInteger()
versionCode 101
versionName "0.101"
externalNativeBuild {
ndkBuild {
cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
}
}
ndk {
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
signingConfigs {
debug {
storeFile file('dev_keystore.jks')
keyAlias 'alias'
storePassword 'xrj45yWGLbsO7W0v'
keyPassword 'xrj45yWGLbsO7W0v'
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
ndkBuild {
path "src/main/cpp/Android.mk"
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
buildToolsVersion '27.0.3'
}
dependencies {
testImplementation 'junit:junit:4.13'
testImplementation 'org.robolectric:robolectric:4.3.1'
}
task versionName {
doLast {
print android.defaultConfig.versionName
}
}
def downloadBootstrap(String arch, String expectedChecksum, int version) {
def digest = java.security.MessageDigest.getInstance("SHA-256")
def localUrl = "src/main/cpp/bootstrap-" + arch + ".zip"
def file = new File(projectDir, localUrl)
if (file.exists()) {
def buffer = new byte[8192]
def input = new FileInputStream(file)
while (true) {
def readBytes = input.read(buffer)
if (readBytes < 0) break
digest.update(buffer, 0, readBytes)
}
def checksum = new BigInteger(1, digest.digest()).toString(16)
if (checksum == expectedChecksum) {
return
} else {
logger.quiet("Deleting old local file with wrong hash: " + localUrl)
file.delete()
}
}
def remoteUrl = "https://bintray.com/termux/bootstrap/download_file?file_path=bootstrap-" + arch + "-v" + version + ".zip"
logger.quiet("Downloading " + remoteUrl + " ...")
file.parentFile.mkdirs()
def out = new BufferedOutputStream(new FileOutputStream(file))
def connection = new URL(remoteUrl).openConnection()
connection.setInstanceFollowRedirects(true)
def digestStream = new java.security.DigestInputStream(connection.inputStream, digest)
out << digestStream
out.close()
def checksum = new BigInteger(1, digest.digest()).toString(16)
if (checksum != expectedChecksum) {
file.delete()
//throw new GradleException("Wrong checksum for " + remoteUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
throw new FileNotFoundException("Wrong checksum for " + remoteUrl + ": expected: " + expectedChecksum + ", actual: " + checksum)
}
}
clean {
doLast {
def tree = fileTree(new File(projectDir, 'src/main/cpp'))
tree.include 'bootstrap-*.zip'
tree.each { it.delete() }
}
}
task downloadBootstraps(){
doLast {
def version = 30
downloadBootstrap("aarch64", "7a90034285c614d23fa450547a5e2aec77d4242c9891ad662bf0c6fd3bd7ef4e", version)
downloadBootstrap("arm", "f030869ce9a43f84d88560d7ac5153ee4f7e517bca0b37ab01df3e1acba0fe37", version)
downloadBootstrap("i686", "1ea9b63f21602231140d58a5545cfbc6bc2ded56ef2b3c31cba2759d913eef00", version)
downloadBootstrap("x86_64", "a50eb8a4dd02b7898bbd4a9653a25c14b56c1737409ce7f64110fd33c2c69382", version)
}
}
//buildscript {
// dependencies {
// classpath 'com.android.tools.build:gradle:4.0.0'
// }
//}
afterEvaluate {
android.applicationVariants.all { variant ->
variant.javaCompileProvider.get().dependsOn(downloadBootstraps)
}
}
I have removed .gradle folder from my laptop and reinstalled and also tried the option Invalidate Caches/Restart option from Android Studio but still the issue remains unresolved.
Any suggestions will be welcome.
this is build.gradle in Android directory! you must add
android {
ndkVersion '21.3.6528147'
...
to build.gradle in Android/app and remove ndk version ... from Android/build.gradle
my simple build.gradle in Android/app code :
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 30
ndkVersion '21.0.6113669'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.test.test"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Download Ndk from " https://developer.android.com/ndk " and Unzip it to a location, Add it's path in local.properties file as like:
ndk.dir=C:\Users\AppData\android-ndk-r23b
And change the version of ndk in build.gradle file
android {
ndkVersion '23.1.7779620'
...
Syc Now and build your app
I have been working on adding flavors to project and ran into below problem. Instead of adding the keystore path, alias and password, I added them in a .properties file and tried accessing them in build.gradle.
So this is how I did,
The project is in git, so other users also get my local path to .properties file path if I keep it in gradle.properties. For that reason I added the .properties path in local.properties. In build.gradle I'm reading the variable from local.properties and getting the each variables written in properties file.
local.properties
variable.prop=C\:\\Users\\user\\signing\\project\\pro.properties
build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
def versionMajor = 1
def versionMinor = 0
def versionPatch = 1
def versionBuild = 1
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
Properties props = new Properties()
props.load(project.rootProject.file('local.properties').newDataInputStream())
def localPropertiesPath = props.getProperty('variable.prop', null);
if (localPropertiesPath == null)
throw new GradleException("Unable to find properties file. Variable might not be added in local.properties or file may not exist in given path")
else {
def propFile = file(localPropertiesPath)
if (propFile.canRead()) {
Properties properties = new Properties()
properties.load(new FileInputStream(propFile))
signingConfigs {
uat {
storeFile file(properties['uatKeystorePath'])
keyAlias properties['uatKeyAlias']
keyPassword properties['uatKeyPassword']
storePassword properties['uatStorePassword']
}
release {
storeFile file(properties['releaseKeystorePath'])
keyAlias properties['releaseKeyAlias']
keyPassword properties['releaseKeyPassword']
storePassword properties['releaseStorePassword']
}
}
defaultConfig {
applicationId "com.package.name"
minSdkVersion 15
targetSdkVersion 23
versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
setMultiDexEnabled true
}
dexOptions {
javaMaxHeapSize "2048M"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfig.release
}
}
}
}
}
Here, in the line properties.load(new FileInputStream(propFile)) it always throws
Malformed \uxxxx encoding.
I have tried,
Hard coding the path of pro.properties instead of taking from local.properties
Tried as given in the following link
Also tried with changing the forward-slash, backslash and escape-char combinations
But nothing helped so far. Any help will be appreciated
In pro.properties file
uatKeystorePath=C:\Users\user\.signing\project\uat_keystore.jks
uatStorePassword=StorePassword
uatKeyAlias=AliasName
uatKeyPassword=KeyPassword
releaseKeystorePath=C:\Users\user\.signing\project\release_keystore.jks
releaseStorePassword=StorePassword
releaseKeyAlias=AliasName
releaseKeyPassword=KeyPassword
I cannot comment so I have to answer, but i just want to ask you if you have the same typo in your real file as you got in your question?
variable.prop=C\:\\Users\\user\\signing\\project\\pro.properties
I mean that backslash between C and :
I have an android studio project, and I'm trying to port gradle from the stable version 2.0.0 to the experimental version 0.7.0-beta1:
This is the working code inside my android tag module my 2.0.0 gradle code:
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.test.myapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName "myNativeLib"
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set .so files location to libs
jni.srcDirs = [] //disable automatic ndk-build call
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task runSwig(type: Exec, description: 'Run swig config') {
workingDir 'src/main'
commandLine 'cmd', '/c', 'swig.bat'
}
Properties props = new Properties()
props.load(new FileInputStream(file(project.property("KeyStore.properties"))))
signingConfigs {
storeSignature {
storeFile = file(props['KEYSTORE'])
storePassword = props['KEYSTORE_PASSWD']
keyAlias = props['KEYSTORE_MYAPP']
keyPassword = props['KEYSTORE_MYAPP_PASSWD']
}
}
buildTypes {
def SERVER_URL = "SERVER_URL"
debug {
debuggable true
jniDebuggable true
buildConfigField "String", SERVER_URL, "\"http://testusound.eastus.cloudapp.azure.com/androidbackend/checkjson\""
versionNameSuffix getMasterName() + "." + getDate()
}
release {
signingConfig signingConfigs.storeSignature
debuggable false
jniDebuggable false
minifyEnabled false
buildConfigField "String", SERVER_URL, "\"http://www.usound.co/androidbackend/checkjson\""
versionNameSuffix getMasterName()
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Now here is my attempt to rewrite my code for the expermiental pluggin 0.7.0-beta1:
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig.with {
applicationId "com.test.myapp"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
}
ndk {
moduleName "myNativeLib"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task runSwig(type: Exec, description: 'Run swig config') {
workingDir 'src/main'
commandLine 'cmd', '/c', 'swig.bat'
}
buildConfigFields.with {
create() {
type "String"
name "SERVER_URL"
value "\"http://www.myserver.com/backend/checkjson\""
}
}
buildConfigFields.with {
create() {
type "String"
name "TEST_SERVER_URL"
value "\"http://www.mytestserver.com/backend/checkjson\""
}
}
sources {
main {
jni {
source {
srcDir "src"
}
}
jni.srcDirs = [] //disable automatic ndk-build call
}
}
buildTypes {
debug {
debuggable true
jniDebuggable true
buildConfigField $("android.buildConfigFields.TEST_SERVER_URL")
versionNameSuffix getMasterName() + "." + getDate()
}
release {
signingConfig = $("android.signingConfigs.mySignature")
debuggable false
jniDebuggable false
minifyEnabled false
buildConfigField $("android.buildConfigFields.SERVER_URL")
versionNameSuffix getMasterName()
proguardFiles.add(file('proguard-rules.pro'))
}
}
Properties props = new Properties()
props.load(new FileInputStream(file(project.property("KeyStore.properties"))))
}
android.signingConfigs {
create("mySignature")
storeFile = file(props['KEYSTORE'])
storePassword = props['KEYSTORE_PASSWD']
keyAlias = props['KEYSTORE_MYAPP']
keyPassword = props['KEYSTORE_MYAPP_PASSWD']
}
}
I'm getting this error error with the signingConfigs:
Error:Attempt to read a write only view of model of type 'java.lang.Object' given to rule 'android.signingConfigs { ... } # app\build.gradle line 165, column 5'
in my code would be this line:
android.signingConfigs {
for my signing configs I'm using a file called keystore.properties located under my main folder (I would like to keep it this way in a separate file so I don't upload my keystore signature data to git, so I haven't put the signing config keys like in the current experimental gradle projects).
What am I missing here? How should I write the signing configs to use properties loaded from a file?
As I'm just getting into experimental gradle feel free to give me some examples or info you believe might be useful.
The stuff after create should be in a set of {}'s
android.signingConfigs {
create("mySignature") { // <-- needed
storeFile = file(props['KEYSTORE'])
storePassword = props['KEYSTORE_PASSWD']
keyAlias = props['KEYSTORE_MYAPP']
keyPassword = props['KEYSTORE_MYAPP_PASSWD']
} // <-- needed
}
I'm trying to setup a nice little versioning script in gradle, android studio where the version name increases every time I make a build, while the version code only increases when I make a release build. Is this possible?
What I think would solve it is checking in the if statement below if it is a release or not. But how can I check if it is a release?
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
def versionPropsFile = file('version.properties')
def code
def name
def Properties versionProps
if (versionPropsFile.canRead()) {
versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
code = versionProps['VERSION_CODE'].toInteger() + 1
name = versionProps['VERSION_NAME'].toInteger() + 1
versionProps['VERSION_CODE']=code.toString()
versionProps['VERSION_NAME']=name.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
versionCode code
versionName "1.2." + name
minSdkVersion 14
targetSdkVersion 19
}
} else {
throw new GradleException("Could not read version.properties!")
}
signingConfigs {
debug {
...
}
releaseKey {
...
}
}
buildTypes {
debug {
debuggable true
packageNameSuffix ".debug"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.debug
}
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.releaseKey
}
}
lintOptions {
abortOnError false
}
}
I would like something like:
if (release) code = versionProps['VERSION_CODE'].toInteger() + 1
else code = versionProps['VERSION_CODE'].toInteger()
Any suggestions?
So after a few hours of trial and error I figured out a way this can be done.
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def value = 0
def runTasks = gradle.startParameter.taskNames
if ('assemble' in runTasks || 'assembleRelease' in runTasks || 'aR' in runTasks) {
value = 1;
}
def code = versionProps['VERSION_CODE'].toInteger() + value
def name = versionProps['VERSION_NAME'].toInteger() + 1
versionProps['VERSION_CODE']=code.toString()
versionProps['VERSION_NAME']=name.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
versionCode code
versionName "1.2." + name
minSdkVersion 14
targetSdkVersion 19
}
} else {
throw new GradleException("Could not read version.properties!")
}
signingConfigs {
debug {
...
}
releaseKey {
...
}
}
buildTypes {
debug {
...
}
release {
...
}
}
lintOptions {
abortOnError false
}
}
So what I'm doing is to check if I'm doing a assebleRelease task or not. If I am I increase the versionCode with +1.
Hope this helps anyone else.