我正在使用上一次提交(提交ID和时间戳)中的一些数据生成我的apk文件名。 apk重命名正在按预期工作。这里的例子是文件名
已创建:MyApp_debug_de2de27_240317_1554.apk
然后我在16:12进行另一次提交。创建的文件名为MyApp_debug_0370898_240317_1612.apk
。现在,如果我构建apk,我的输出目录有两个apk:
MyApp_debug_0370898_240317_1612.apk
和前一个MyApp_debug_de2de27_240317_1554.apk
,但上传到设备的apk是较旧的。我知道这是因为如果在提交之后构建新的apk之前,我删除旧的apk。我收到这条消息:
03/24 16:13:36: Launching app
The APK file Z:\Builds\app-android\app\outputs\apk\MyApp_debug_de2de27_240317_1554.apk does not exist on disk.
Error while Installing APK
如果我然后同步项目,则会安装MyApp_debug_0370898_240317_1612.apk
。
知道为什么吗?
以下是我生成文件名的方法。
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.my.package"
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName gitVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
...
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def project = "MyApp"
def SEP = "_"
def buildType = variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def date = new Date();
date.setTime(TimeUnit.SECONDS.toMillis(gitVersionCodeTime));
def formattedDate = date.format('ddMMyy_HHmm')
def newApkName = project + SEP + buildType + SEP + version + SEP + formattedDate + ".apk"
println("Creating app with filename=" + newApkName);
output.outputFile = new File(output.outputFile.parent, newApkName)
println("OutputFile=" + output.outputFile);
}
}
}
答案 0 :(得分:0)
03/24 16:13:36: Launching app The APK file Z:\Builds\app-android\app\outputs\apk\MyApp_debug_de2de27_240317_1554.apk does not exist on disk. Error while Installing APK
此错误将首先解决,您将点击构建>清洁项目
答案 1 :(得分:0)
重建您的项目。遵循:
构建>重建项目
然后构建apk