Azure Pipeline - Automating Android Version Code - android

I picked up a project that had been managed by another team and the last released version use a version code of 5034.
They had been pushing these out from a developers machine directly rather than using a formal build process.
In my build script I have a manifest versioning step defined as:
- task: android-manifest-version#1
displayName: 'Set Android version numbers'
inputs:
sourcePath: '$(androidManifestPath)'
versionCodeOption: 'buildid'
versionCode: $(Build.BuildId)
versionName: $(baseVersion).$(Build.BuildId)
printFile: true
But our buildId is at a much lower number (4444) at the moment.
Looking over the available variables here, nothing seems to be jumping out as a solution.
I suppose I could just set this to a value manually in the build script but that feels a little dirty.
Is there a simple solution I'm overlooking?
UPDATE
I'm wondering if I could use something like this:
Create a new variable in my custom shared-variables.yml like:
versionCodePrefix: '600'
And then in the scripts use this
versionCode: $(versionCodePrefix)$(Rev:r)
UPDATE2
I've just found this option for the build step:
versionCodeOption: 'timestamp'
Inserts a unix format time stamp. Going to try this approach.

So it turns out the versioning plugin has a few options I'd not investigated.
My final yml task looks like this:
task: android-manifest-version#1
displayName: 'Set Android version numbers'
inputs:
sourcePath: '$(androidManifestPath)'
versionCodeOption: 'buildid'
versionCode: $(Build.BuildId)
versionCodeOffset: '1000'
versionName: $(baseVersion).$(Build.BuildId)
printFile: true
Keeping it all automated but by using the versionCodeOffset value it combines by adding the two integer values together. So a build version of 2.0.4448 will result in a versionCode of 5448.

Related

Azure DevOps Android increase versioning during the build

How should I increase my version number in an android project, as a step of build pipeline app center deployment? Does the Azure DevOps has a version manager plugin, or should I create a version.properties file and edit, commit, push into the current branch?
Build pipeline:
This can be done more clean with out using the properties file and then replacing that using a shell script.
In the top level build.gradle file, under the build scripts:
buildscript {
def getVersionCode = { ->
def code = project.hasProperty('versionCode') ? versionCode.toInteger() : -1
println "VersionCode is set to $code"
return code
}
def getVersionName = { ->
def name = project.hasProperty('versionName') ? versionName : "1.0"
println "VersionName is set to $name"
return name
}
ext{
versionCode = getVersionCode()
versionName = getVersionName()
}
}
In your module specific gradle file :
defaultConfig {
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
In your Devops pipeline for the gradle build task, just pass on the options like so:
-PversionName=$(Build.BuildNumber) -PversionCode=$(Build.BuildId)
Unfortunately is no out of the box support, but you can find here a good tutorial:
Install Colin's ALM Corner Build & Release Tools that include Version Assemblies task.
In the Android manifest the name and code should look like this:
android:versionCode="1" android:versionName="1.0.0"
Add the “Version Assemblies” task TWICE, once for the version name and once for the version code.
Once added, we will bump the name.
First insert the following (with examples):
Source Path: src/MobileApps/MyDriving/MyDriving.Android/Properties
File Pattern: AndroidManifest.xml
Build Regex Pattern: (?:\d+.\d+.\d+.)(\d+)
Under Advanced:
Build Regex Group Index: 0
Regex Replace Pattern: versionName=“\d+.\d+.\d+
Prefix for Replacements: versionName=”
What this will do is update the version name to the Build number format found under “General”, which mine is set to 1.0.0$(rev:.r)
Now for the next one, which is the version code:
Source Path: src/MobileApps/MyDriving/MyDriving.Android/Properties
File Pattern: AndroidManifest.xml
Build Regex Pattern: (?:\d+.\d+.\d+.)(\d+)
Under Advanced:
Build Regex Group Index: 1
Regex Replace Pattern: versionCode=“\d+
Prefix for Replacements: versionCode\
And just like that you are good to go. This will simply update it with the current version revision :)
There is an existing task called
Mobile App Tasks for iOS and Android in the marketplace which was developed by James Montemagno
You can find the step-by-step instruction in the github
He has developed this task mainly to address this kind of versioning in both android/IOS Apps.
The best solution for me was make a version.properties file to track versioning and then modify it during the pipeline build process (shell script). The others are bad especially for custom versioning.

include.gradle file being generated is causing problems

When building a project I get the following error:
Flavor 'nativescript-telerik-ui' has unknown dimension 'nativescript-telerik-ui'.
It happens only when using the pro version through the #progress registry. Doesn't happen with the local .tgz pro version.
I noticed the error has to do with the include.gradle file it generates. I read the following article: https://docs.nativescript.org/plugins/plugins#includegradle-specification
It says that when the plugin doesn't have the include.gradle, at build time gradle creates a default one with default elements. When I saw the include.gradle it generated for the plugin it seems to have generated a default one like so:
android {
productFlavors {
"nativescript-telerik-ui" {
dimension "nativescript-telerik-ui"
}
}
}
The include.gradle generated for the local .tgz version of the plugin is like this:
android {
productFlavors {
"F6" {
dimension "nativescripttelerikuipro"
}
}
}
I replaced the default include.gradle with the latter and it got past the error. You can recreate the problem by following these steps:
create a new hello world app
use the command npm login --registry=https://registry.npm.telerik.com/ --scope=#progress to log in if you're a paying customer.
use the command npm install --save #progress/nativescript-telerik-ui-pro to install the plugin
use tns run android
Is there anything I can do to solve this problem? Really need help on this.
My name is Vladimir and I am part of the nativescript-telerik-ui-pro team. Thank you for logging this issue in our feedback portal. We are going to review it as soon as possible and update you regarding its status, but from what I currently see there is some incorrect "parameters" passed to the 'pro' version of the plugin that are going to be resolved very fast.
We apologize for any inconvenience that this is causing.

Tensorflow Quantized Graph for Android

I'm trying to load a quantized graph into an Android app.
My BUILD file contains
deps = ["//tensorflow/core:android_tensorflow_lib",
"//tensorflow/contrib/quantization:cc_array_ops",
"//tensorflow/contrib/quantization:cc_math_ops",
"//tensorflow/contrib/quantization:cc_nn_ops",
"//tensorflow/contrib/quantization/kernels:quantized_ops"]
The additional quantization deps work for standalone C++ builds.
I can't compile with Bazel, due to a large number of errors in GEMMLOWP. What's the proper way to include gemmlowp and the quantization ops in Android?
Here is an example error:
external/gemmlowp/eight_bit_int_gemm/eight_bit_int_gemm.cc:125:13: error: 'int32_t' is not a member of 'std'
MatrixMap<std::int32_t, ResultOrder> result(c, m, n, ldc);
This is on Ubuntu 16.04 with Bazel 0.3.0.
Here's a gist that has the output of two sequential attempts to build the package - it fails on highwayhash the first time and gemmlowp the second.
https://gist.github.com/ericdanz/81b799f2e0bbb3cc462aa3c90468c71b
Ultimately got it to compile and run with liberal addition of "-std=c++11" in BUILD files for gemmlowp and highwayhash, and substitution of the android framework for the framework dependencies in the quantized ops. It produces fairly different results though, and runs about 4x slower (26-3200ms vs 6-800 ms). I'll try to do a little deeper investigation.
Here's what worked for me - it is basically a combination of all the comments from Eric D above, but I wanted to put it all in one place for someone new who comes across this problem:
Add quantized_ops in deps to libtensorflow_demo.so in the BUILD file for the Android app:
deps = ["//tensorflow/core:android_tensorflow_lib",
"//tensorflow/contrib/quantization/kernels:quantized_ops",]
Modify the deps for quantized_ops in tensorflow/contrib/quantization/kernels/BUILD:
deps = [
"//tensorflow/contrib/quantization:cc_array_ops",
"//tensorflow/contrib/quantization:cc_math_ops",
"//tensorflow/contrib/quantization:cc_nn_ops",
"//tensorflow/core:android_tensorflow_lib",
#"//tensorflow/core",
#"//tensorflow/core:framework",
#"//tensorflow/core:lib",
#"//tensorflow/core/kernels:concat_lib_hdrs",
#"//tensorflow/core/kernels:conv_ops",
#"//tensorflow/core/kernels:ops_util_hdrs",
#"//tensorflow/core/kernels:pooling_ops_hdrs",
#"//tensorflow/core/kernels:eigen_helpers",
#"//tensorflow/core/kernels:ops_util",
#"//tensorflow/core/kernels:pooling_ops",
"//third_party/eigen3",
"#gemmlowp//:eight_bit_int_gemm",
],
Remove/comment out the .Doc() parts in tensorflow/contrib/quantization/ops/array_ops.cc, math_ops.cc and nn_ops.cc
Modify the deps for cc_array_ops, cc_math_ops and cc_nn_ops in tensorflow/contrib/quantization/BUILD:
deps = [
#"//tensorflow/core:framework",
"//tensorflow/core:android_tensorflow_lib",
],
Run bazel build command for Android app with --cxxopt="-std=c++11" flag.

is there any way to configure gradle to check spelling in strings.xml?

I'd like strings.xml to be checked for spelling while building with gradle. Since we use continuous integration we need it to be configured for building from command-line not just in Android Studio. Any way to do it?
PS. I've tried:
lintOptions {
abortOnError false
// check *only* the given issue id's
check 'Typos'
}
strings.xml:
<resources>
<string name="app_name">Project</string>
<!-- Common Words -->
<string name="test_spelling">sdfsdfdfds</string>
and
./gradlew assembleDebug lint
but got nothing:
:app:lint
Ran lint on variant release: 0 issues found
Ran lint on variant debug: 0 issues found
Wrote HTML report to file:/Users/asmirnov/Documents/dev/src/Project/app/build/outputs/lint-results.html
Wrote XML report to /Users/asmirnov/Documents/dev/src/Project/app/build/outputs/lint-results.xml
Also i've checked lint --show :
...
Typos
-----
Summary: Spelling error
Priority: 7 / 10
Severity: Warning
Category: Correctness:Messages
This check looks through the string definitions, and if it finds any words
that look like likely misspellings, they are flagged.
...
PPS. If i add another rule to check (check 'Typos', 'TypographyEllipsis') i'm getting warnings (for TypographyEllipsis) as expected, so in general linting works. For some reason "Typos" rule is not working only
I am currently working on something similar, so have not completed my work. Not sure if you have an answer as yet, as it was asked a while ago. Here is what I have.
The code you have here:
lintOptions {
abortOnError false
// check *only* the given issue id's
check 'Typos'
}
should be fine. You can also add it within a flavor, to be more restrictive, if you are using them.
To get the report from the command line, you need to execute:
./gradlew lintAssembleDebug
or whatever your flavor is, e.g. ./gradlew lintAssembleMyFlavorDebug
I am trying to make use of the lintOptions.check() method, to programmatically add the checks I want, but no luck yet. Another alternative is as described here by Jason Atwood. I am looking at this, adding the blank file:
ext.lintCheckList = [
// Blank default list
] as String[]
to the repo, and replacing that in the CI job, as needed.
Hope that helps.
Update:
The command is incorrect. It should be
./gradlew lintDebug
or
./gradlew lintMyFlavorDebug
etc
If you do want spell check feature that is enabled by default in Android Studio IDE then follow the below given steps,
Go to Android Studio -> Preferences on your Mac OS X (Should be Window -> Preferences on Windows OS)
Now look for Inspections (if you cant trace it just use the Search)
Now look for the Spellings check box and check it (this also checks the Typo)
Apply and Close
Thats it!! You would now see any Typo or spelling correction highlights in Android Studio.

How to sync Gradle/Android versionCode between build server and workstation

Currently we have Bamboo listening to a Git repository on any changes. When a change occur the build process starts and increases the (Bamboo) build number by one.
I thought it would be nice to use this same build number for the Android project (versionCode) so that the user of the app can always refer to the actual build he/she received. This way the build number goes from 1 to 2 on the build server. Only the workstation doesn't know about this and still uses version 1.
Is there any way to sync this build number?
Tried:
One possible solution a friend of mine suggested was to use a git command to get the commit number: git rev-list HEAD --count which is awesome. The only downside of this is that you cannot properly change build number within Bamboo. So the build number of Bamboo should be leading.
Btw, I'm using Android Studio with Gradle
Bamboo can be configured to set the versionCode value in the manifest to the build number when building, so propagating this change back to where the development is happening should be unnecessary. To configure Bamboo to do this, add a Script task to the build plan (before the actual build task) with a body of:
sed -i 's/android:versionCode="[[:digit:]]*"/android:versionCode="${bamboo.buildNumber}"/' AndroidManifest.xml
Yes, it is quite easy with gradle. You have to retrieve the latest build result in the gradle script and put it in the versionCode.
Here it is what you need (remember to change the variables to refer your server):
def getBambooNumber(){
def url = "https://bambooServer:bambooPort/rest/api/latest/result/PROJECT-BAMBOO-ID/latest.json?os_authType=basic".toURL()
def authValue = "USER:PASSWORD".bytes.encodeBase64().toString()
def json = new JsonSlurper().parseText(url.getText(requestProperties : ["Authorization" : "Basic " + authValue]))
return json.buildNumber + 1 // +1 to Get the new build number
}
def bambooBuild = bambooBuildNumber()
android {
...
defaultConfig {
...
versionCode bambooBuild
//This allows you to access in BuildConfig to the bamboo build
buildConfigField "Integer", "BAMBOO_BUILD", "${bambooBuild}"
...
}
...
}
Let me know if this works for you.

Categories

Resources