在 app 的 build.gradle 中通过outputDirectory
和outputFileName
修改目标 apk 文件的输出目录后,使用菜单"Run"->"Debug app..."
时就会失败,提示 apk 文件无效(提示的是仍然默认的输出文件目录和文件名)。
错误提示如下:
Installation did not succeed.
The application could not be installed.
List of apks:
[0] 'C:\Android\Test\app\build\outputs\apk\debug\app-debug.apk'
Installation failed due to: 'Invalid File: C:\Android\Test\app\build\outputs\apk\debug\app-debug.apk'
Retry
修改版本输出目录的脚本如下:
applicationVariants.all { variant ->
variant.outputs.all { output ->
def app = applicationId
def type = variant.buildType.name
def releaseApkName = "${app}-${versionCode}.apk"
variant.packageApplicationProvider.get().outputDirectory = new File("build/apk/${type}")
outputFileName = releaseApkName
}
}
}
1
Macolor21 2020-09-08 18:18:11 +08:00
Run “-> Debug App...”这一步通过参数指定 APK 文件地址试试?
|
2
firemeteor 2020-09-08 18:41:04 +08:00 via Android
4
|
3
howellz OP @Macolor21 请问具体是怎么指定啊?只看到 Depoly 中有"Default APK", "APK from app bundle", "Custom artifact"和"nothing",并没有看到具体如何指定 apk 的位置。谢谢~
|
4
likaci 2020-09-08 21:00:27 +08:00
if (variant.buildType.name != "debug") {
variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/release") } |
6
zhuz 2020-11-04 21:32:30 +08:00
遇到了同样的问题,大佬有找到方法嘛
|