ViVo手機無法安裝run出來的apk-testOnly run出來一直為true
阿新 • • 發佈:2018-12-13
說明
點選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') } } } }