问题来源
因为项目需要把旧版本as项目移植到新版本as里,并升级gradle及相关开发库。
升级参数:
相关升级参数 | 升级前 | 升级后 |
---|---|---|
Android Studio | 2.2.2 | Dolphin | 2021.3.1 Patch 1 |
Android Plugin Version | 2.2.3 | 3.5.3 |
Gradle Version | 2.14.1 | 6.7.1 |
是否支持Androidx | 不支持 | 支持并开启 |
迁移完后编译等各种报错全部解决,并且能正常打包,但就是无法通过调试直接在设备上进行安装,但调试的apk包是正常打出来了(且可以手动安装),具体报错看下面...
相关报错如下:
- Unable to determine application id: com.android.tools.idea.run.ApkProvisionException: No outputs for the main artifact of variant: general_display_online_ckxspDebug.
- ApkProvisionException: No outputs for the main artifact of variant: general_display_online_ckxspDebug.
- Execution failed for task ':infoShower_nj:installDebug'. >
Failed to install on any devices.
相关网上的方法:
网上查询资料,得到如下解决方法:
- as和gradle版本不兼容,需要降级as版本。
- 修改Edit Configurations...博客。
- 使用指令等方式
找了很久都没解决我的问题,依然是报一样的错误。
我的解决方法:
在app目录的build.gradle文件里,android.applicationVariants.all里的语句导致,移除即可。
移除前:
android {
...省略
android.applicationVariants.all { variant ->
def buildType = variant.buildType.name
def fileName//获取当前时间的"YYYY-MM-dd"格式。
def createTime = new Date().format("YYYY-MM-dd", TimeZone.getTimeZone("GMT+08:00"))
variant.outputs.all {
if (buildType == "release") {
...省略
}
if (buildType == "debug") {
variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/apks/${buildType}/${createTime}")
fileName = "${buildType}版本_${variant.productFlavors[0].manifestPlaceholders.APP_NAME}_${variant.productFlavors[0].versionName}_${createTime}.apk"
it.outputFileName = fileName
}
}
}
移除这行代码即可:variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath + "/apks/${buildType}/${createTime}")
移除后:
android {
...省略
android.applicationVariants.all { variant ->
def buildType = variant.buildType.name
def fileName//获取当前时间的"YYYY-MM-dd"格式。
def createTime = new Date().format("YYYY-MM-dd", TimeZone.getTimeZone("GMT+08:00"))
variant.outputs.all {
if (buildType == "release") {
...省略
}
if (buildType == "debug") {
fileName = "${buildType}版本_${variant.productFlavors[0].manifestPlaceholders.APP_NAME}_${variant.productFlavors[0].versionName}_${createTime}.apk"
it.outputFileName = fileName
}
}
}
总结
移除后,我的项目能调试时直接debug到指定设备上安装app,速度也提升了很多。