Issue
I have a project that uses custom permission
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.company.app">
<uses-permission android:name="com.company.app.permission.MY_PERMISSION" />
<permission
android:name="com.company.app.permission.MY_PERMISSION"
android:description="@string/permission_access_summary"
android:label="@string/permission_access"
android:protectionLevel="signature" />
</manifest>
Then I added the Jetpack Benchmark module:
benchmark/build.gradle
plugins {
id 'com.android.library'
id 'androidx.benchmark'
id 'kotlin-android'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig.minSdkVersion 21
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
defaultConfig {
testInstrumentationRunner 'androidx.benchmark.junit4.AndroidBenchmarkRunner'
}
testBuildType = "release"
buildTypes {
debug {
// Since debuggable can"t be modified by gradle for library modules,
// it must be done in a manifest - see src/androidTest/AndroidManifest.xml
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "benchmark-proguard-rules.pro"
}
release {
isDefault = true
signingConfig signingConfigs.debug
}
}
}
dependencies {
androidTestImplementation "androidx.benchmark:benchmark-junit4:$androidx_benchmark_version"
androidTestImplementation "junit:junit:$junit_version"
androidTestImplementation "androidx.test:runner:$test_runner_version"
androidTestImplementation "androidx.test:rules:$test_rules_version"
androidTestImplementation "androidx.test.ext:junit:$androidx_junit_version"
// Add your dependencies here. Note that you cannot benchmark code
// in an app module this way - you will need to move any code you
// want to benchmark to a library module:
// https://developer.android.com/studio/projects/android-library#Convert
androidTestImplementation project(":app")
}
benchmark/src/androidTest/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.company.app.test">
<!--
Important: disable debugging for accurate performance results
In a com.android.library project, this flag must be disabled from this
manifest, as it is not possible to override this flag from Gradle.
-->
<application
android:debuggable="false"
android:requestLegacyExternalStorage="true"
tools:ignore="HardcodedDebugMode"
tools:replace="android:debuggable" />
</manifest>
When I run the Benchmark tests, it builds successfully but failed to install.
Installation did not succeed. The application could not be installed: INSTALL_FAILED_DUPLICATE_PERMISSION
List of apks: [0] '/Users/lap12846/avengers/ironman/demoapp/benchmark/build/outputs/apk/androidTest/release/benchmark-release-androidTest.apk' Installation failed due to: 'null'
My Build Variants: app: debug, benchmark: release
Note that if I uninstall the app before Run the test, it works. But it will erase all my app's data.
Solution
You can add tools:node="remove" to "permission" tag in benchmark/src/androidTest/AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.company.app.test">
<permission
android:name="com.company.app.permission.MY_PERMISSION"
tools:node="remove"/>
<!--
Important: disable debugging for accurate performance results
In a com.android.library project, this flag must be disabled from this
manifest, as it is not possible to override this flag from Gradle.
-->
<application
android:debuggable="false"
android:requestLegacyExternalStorage="true"
tools:ignore="HardcodedDebugMode"
tools:replace="android:debuggable" />
</manifest>
Ref: https://developer.android.com/studio/build/manifest-merge
Answered By - Khanh Tran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.