ViVo手机无法安装run出来的apk-testOnly run出来一直为true

说明

点击Android Studio上面的绿色Run按钮,出来的debug apk的AndroidManifest.xml的android:testOnly="true",即使修改为false也没有用。可以使用Build-Build APK(s)来打出testOnly为false的apk,再使用adb命令安装。或者在gradle中强制修改testOnly为false。

判断环境是否为测试环境

//判断是否是线上包(仅通过jenkins的release任务打包或者手动设置BUG_TYPE环境变量或者bugType属性)
def bugTypeIsBeta(){
    if (System.getenv("BUG_TYPE") == "BUG_TYPE_LIVE") {
        return false
    }
    if (hasProperty("bugType") && getProperty("bugType") == "BUG_TYPE_LIVE"){
        return false
    }
    return true
}

根据是否为测试环境,强制修改testOnly为false

app模块下的android节点添加如下代码

if (bugTypeIsBeta()){
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.processManifest.doLast {
                String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"
                def manifestContent = file(manifestPath).getText('UTF-8')
                manifestContent = manifestContent.replaceAll("android:testOnly=\"true\"", "android:testOnly=\"false\"")
                file(manifestPath).write(manifestContent, 'UTF-8')
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/ybf326/article/details/82931677