【问题标题】:INSTALL_FAILED_DUPLICATE_PERMISSION when execute test using Jetpack Benchmark使用 Jetpack Benchmark 执行测试时的 INSTALL_FAILED_DUPLICATE_PERMISSION
【发布时间】:2020-08-31 10:42:28
【问题描述】:

我有一个使用自定义权限的项目

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>

然后我添加了 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>

当我运行基准测试时,它构建成功但安装失败。

安装没有成功。无法安装应用程序: INSTALL_FAILED_DUPLICATE_PERMISSION

apk 列表:[0] '/Users/lap12846/avengers/ironman/demoapp/benchmark/build/outputs/apk/androidTest/release/benchmark-release-androidTest.apk' 安装失败,原因是:'null'

我的构建变体:应用程序:调试,基准测试:发布


请注意,如果我在运行测试之前卸载应用程序,它可以工作。但它会清除我所有应用的数据。

【问题讨论】:

    标签: android benchmarking android-testing android-jetpack


    【解决方案1】:

    您可以在 benchmark/src/androidTest/AndroidManifest.xml 中添加 tools:node="remove" 到 "permission" 标签:

    <?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>
    

    参考:https://developer.android.com/studio/build/manifest-merge

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      • 2022-11-10
      • 2017-03-08
      • 2017-10-26
      • 2014-11-09
      相关资源
      最近更新 更多