INSTALL_FAILED_DUPLICATE_PERMISSION ao executar o teste usando o Jetpack Benchmark

Aug 31 2020

Eu tenho um projeto que usa permissão personalizada

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>

Em seguida, adicionei o módulo Jetpack Benchmark:

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>

Quando executo os testes do Benchmark, ele é compilado com êxito, mas não consegue instalar o .

A instalação não foi bem-sucedida. O aplicativo não pôde ser instalado: INSTALL_FAILED_DUPLICATE_PERMISSION

Lista de apks: [0] '/Users/lap12846/avengers/ironman/demoapp/benchmark/build/outputs/apk/androidTest/release/benchmark-release-androidTest.apk' A instalação falhou devido a: 'null'

Minhas variantes de compilação : app: debug, benchmark: release


Observe que, se eu desinstalar o aplicativo antes de executar o teste, ele funcionará. Mas apagará todos os dados do meu aplicativo.

Respostas

1 KhanhTran Sep 01 2020 at 10:35

Você pode adicionar tools:node="remove" à tag "permission" em 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