Macrobenchmark throws INSTALL_FAILED_UPDATE_INCOMPATIBLE - android

We want to measure our (multi module) app performance. I setup macro benchmark but it's not start. When i try to start benckmark, it's throws this message:
Failed to install APK(s): /*****.apk
INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.*** signatures do not match previously installed version; ignoring!
com.android.ddmlib.InstallException: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.*** signatures do not match previously installed version; ignoring!
Benchmark module build gradle:
buildTypes {
// This benchmark buildType is used for benchmarking, and should function like your
// release build (for example, with minification on). It"s signed with a debug key
// for easy local/CI testing.
create("benchmark") {
isDebuggable = false
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("debug")
}
}
...
dependencies {
implementation("androidx.test.ext:junit:1.1.5")
implementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("androidx.test.uiautomator:uiautomator:2.2.0")
implementation("androidx.benchmark:benchmark-macro-junit4:1.2.0-alpha09")
}
Benchmark variant on app module's gradle:
create("benchmark") {
val releaseForInitWith = getByName("debug") {
isMinifyEnabled = false
isShrinkResources = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
initWith(releaseForInitWith)
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("debug")
isDebuggable = false
}
Could you help, how can i fix this?

Related

Travis CI - Failed to read encrypted key from store - Invalid Keystore format - Android

I've created encrypted keystore file. I'm using Travis CI for building and to generate apk. Its showing following error.
Error: Failed to read key [secure] from store
"app/[secure].jks.enc": Invalid keystore format
Can anyone help me to solve this issue?
Thanks,
Kamal
In your build.gradle, your should specify the storeFile to the original keystore file name, which not contains the suffix ".enc", because Travis will decrypt it for you:
android {
// ...
signingConfigs {
release
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
def isRunningOnTravis = System.getenv("CI") == "true"
if (isRunningOnTravis) {
// configure keystore
signingConfigs.release.storeFile = file("../myshape.jks") // <-- here
signingConfigs.release.storePassword = System.getenv("keystore_password")
signingConfigs.release.keyAlias = System.getenv("keystore_alias")
signingConfigs.release.keyPassword = System.getenv("keystore_alias_password")
}
}

Setting debuggable true for specific flavor Releases

How can be defined that debuggable=true is enabled in releaseBuildConfig, but just for a specific set of flavors:
This is the example code, including the trial (which does not work):
flavorDimensions "project", "environment"
productFlavors {
basic {
dimension "project"
}
advanced {
dimension "project"
}
flavorDevelopment {
dimension "environment"
applicationId "ch.myproject.app.development"
debuggable true // this does not work
}
flavorTest {
dimension "environment"
applicationId "ch.myproject.app.test"
debuggable true // this does not work
}
flavorIntegration {
dimension "environment"
applicationId "ch.myproject.app.integration"
debuggable true // this does not work
}
flavorProduction {
dimension "environment"
applicationId "ch.myproject.app.production"
// just here debuggble has to be on the default (in buildTypes.debug = on AND in buildTypes.release = off )
// this is working
}
the "debuggable true" statements wont work in the code example above.
But it should give you an impression, what I try to make.
The only productive Release I' gona make is the flavorProduction.
There I'm using the default behavior which is working fine.
But all the other internal releases flavorDevelopment, flavorTest, flavor Integration, those I would like to have with enabled debugging capability.
I tried a second approach:
applicationVariants.all { variant ->
// setting all releases expecting the Production one to debuggable
if (!variant.buildType.name.contains("ProductionRelease")) {
variant.buildType.debuggable = true
}
}
But there I'm getting the message:
Error:(132, 0) Cannot set readonly property: debuggable for class: com.android.build.gradle.internal.api.ReadOnlyBuildType
Does anybody know how to configure this with gradle?
thanks in advance luke
debuggable is a property of the BuildType object, and not of the ProductFlavor object, and so (as you have found), writing debuggable true inside a product flavor will have no effect.
Generally you will have a debug build type and a release build type, and then you will have build variants like flavorProductionDebug and flavorProductionRelease. It sounds like that's not enough for you, and you need to have whatever is different between your debug and release build types be maintained while also having debuggable true.
To achieve this, you can make a third build type.
buildTypes {
debug { ... }
release { ... }
releaseDebuggable {
initWith release
debuggable true
}
}
Now your releaseDebuggable build type will be exactly like your release build type, but debuggable!
This has the side-effect of creating a fooReleaseDebuggable build variant for all of your product flavors. If you want to suppress all those except for flavorProductionReleaseDebuggable, you could use the variantFilter interface.
There is a way to achieve this, just set debuggable attribute to be true in manifest in every source set of expected product flavors.
Step 1: Create source set of product flavors.
New source set in app/src/[flavor-name] and create a AndroidManifest.xml in it. Just like the following:
Step 2: Define debuggable in manifests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:debuggable="false"
tools:ignore="HardCodedDebugMode" />
</manifest>
tools:ignore="HardcodedDebugMode" is used to suppress warnings.
That's it, you're good to go. No need to touch your build.gradle files.
There's always a way.
def getCurrentFlavor() {
String tskReqStr = getGradle().getStartParameter()
.getTaskRequests().toString()
Pattern pattern
if( tskReqStr.contains("assemble"))
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
else if(tskReqStr.contains("bundle"))
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
else pattern = Pattern.compile("generate(\\w+)(Release|Debug)")
Matcher matcher = pattern.matcher( tskReqStr )
if(matcher.find())
return matcher.group(1).toLowerCase()
else return ""
}
android {
buildTypes {
release {
debuggable = getCurrentFlavor()
.containsIgnoreCase(("production")
}
debug {
debuggable = getCurrentFlavor()
.containsIgnoreCase(("production")
}
}
flavorDimensions "enviroment"
productFlavors {
flavorTest { ... }
flavorDevelopment { ... }
flavorIntegration { ... }
flavorProduction { ... }
}
}

How to define a String by build types in Gradle (Android Studio) and replace the file name

I want to replace the name of the generated apks by the specified build type:
android {
buildTypes {
def String proguard
release {
minifyEnabled false
zipAlignEnabled true
proguard = "noproguard"
}
releaseProguard {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
zipAlignEnabled true
proguard = "proguard"
}
}
// Replace the file names
android.applicationVariants.all { variant ->
variant.preBuild.doLast {
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}-${variant.versionCode}-" + proguard +.apk"))
}
}
}
}
However, if I make a signed APK with "release", I'm not getting the "noproguard" string in the APK's file name, it's getting overriden by the last build type: releaseProguard.
Expected output release:
app-qa-release-1.3.1-noprguard.apk
Expected output releaseProguard: app-qa-release-1.3.1-proguard.apk
It is not exactly what you are looking for.
You can use your build.gradle to set this attribute:
android {
//...
defaultConfig {
//...
project.ext.set("archivesBaseName", "XXXX_" + defaultConfig.versionCode);
}
}
Assigning the archivesBaseName you will obtain something like:
xxxx_0.9.6-flavorName-buildType.apk
You can use this inside the flavor block to assign specific value.
This attribute requires the gradle-plugin 1.3.1 or higher.

Android Studio : How to remove/filter build variants for default debug and release buildTypes and keep only those using custom buildTypes?

I have created custom buildTypes as follows:
buildTypes {
releasefree.initWith(buildTypes.release)
releasefree {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
releasepro.initWith(buildTypes.release)
releasepro {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix ".pro"
}
debugfree.initWith(buildTypes.debug)
debugfree {
shrinkResources true
applicationIdSuffix ".debug"
debuggable true
}
debugpro.initWith(buildTypes.debug)
debugpro {
shrinkResources true
applicationIdSuffix ".pro.debug"
debuggable true
}
}
I am not going to use the default debug and release build types ever and want to remove them from the build variants list. I have more than a few flavors and the list of variants is too huge. Removing the variants with default debug and release types will help as I'm never going to use them.
I tried using variant filter as follows but it did not work
android.variantFilter { variant ->
if(variant.buildType.name.endsWith('Release') || variant.buildType.name.endsWith('Debug')) {
variant.setIgnore(true);
}
}
Is there something wrong in the way I'm filtering the variants or is it just not possible to remove the variants with default debug and release build types.
Figured it out. It was a really silly mistake on my part.
The above variant filter does work. The names are all lower case and the upper case in the strings i was comparing with were the culprit.
Changing to the following (making compare strings lower case) made it work as expected:
android.variantFilter { variant ->
if(variant.buildType.name.endsWith('release') || variant.buildType.name.endsWith('debug')) {
variant.setIgnore(true);
}
}
or this
android.variantFilter { variant ->
if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
}
}
With New Variant APIs, it becomes:
androidComponents {
beforeVariants(selector().withBuildType("release")) { variantBuilder ->
variantBuilder.enabled = false
}
}
ref doc
If u want exclude by name use something like this
android.variantFilter { variant ->
if(variant.name.equals("qaRelease")|| variant.name.equals('something')) {
variant.setIgnore(true);
}
}
If you want to ignore specific build variant , Here is details for understanding.
flavorDimensions "client", "server"
productFlavors {
client1 {
manifestPlaceholders variant : 'Client 1'
dimension "client"
applicationId "com.edupointbd.bb"
}
client2 {
manifestPlaceholders variant : 'Client 2'
dimension "client"
applicationId "com.edupointbd.bb"
}
dev {
dimension "server"
}
staging {
dimension "server"
}
production {
dimension "server"
}
}
variantFilter { variant ->
def names = variant.flavors*.name
// To check for a certain build type, use variant.buildType.name == "<buildType>"
if (names.contains("client1") && names.contains("production")) {
// Gradle ignores any variants that satisfy the conditions above.
setIgnore(true)
}
}

Letting multiple flavorGroups influence packageName in Android gradle build

I have a build configuration with 2 build types (debug/release) and 2 flavorGroups (locale/environment).
These are 3 different axes, and I want to determine the packageName of the build variant by all of them.
However, it seems I can only set the full packageName for a given flavor, and then have a packageNameSuffix for the build type - attempting to do a packageNameSuffix for a flavour leads to an Could not find method packageNameSuffix() for arguments [...] error.
Any way around that, so that I could get a package name for each of the resulting build variants, along the lines of: com.app.LOCALE.ENVIRONMENT.TYPE, without having to "unroll" one of the axes into build types (which would lead to duplication)?
Thanks in advance.
You could use the solution I've written about here: https://stackoverflow.com/a/26585241/4177090
In short, you can find out the combined variant using variantFilter and then update the configuration (e.g. the appliciationId) from there:
android.variantFilter { variant ->
def flavorString = ""
def flavors = variant.getFlavors()
for (int i = 0; i < flavors.size(); i++) {
flavorString += flavors[i].name;
}
if(flavorString.equalsIgnoreCase("fooBar")) {
variant.getDefaultConfig().applicationId "com.example.foobar"
}
}
You could use a combination of packageName and packageNameSuffix from productFlavors and buildTypes like the following:
android {
productFlavors {
foo {
packageName "com.example.foo"
versionName "Foo"
}
bar {
packageName "com.example.bar"
versionName "Bar"
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
versionNameSuffix "-debug"
}
release {
packageNameSuffix ".release"
versionNameSuffix "-release"
}
}
}
But if you're using something like flavorGroups, then this may not work for you.
You can also check out this code sample config which adds new buildTypes https://github.com/bradmcmanus/Gradle-Build-Example/blob/master/GradleBuildExample/build.gradle

Categories

Resources