[英]Android Studio not installing latest apk
I'm generating my apk filename with some data from the last commit (commit id and timestamp). 我正在使用上次提交中的一些数据生成我的apk文件名(提交ID和时间戳)。 The apk renaming is working as expected. apk重命名正在按预期工作。 As an example here is the filename that is created: MyApp_debug_de2de27_240317_1554.apk
这里的示例是创建的文件名: MyApp_debug_de2de27_240317_1554.apk
I then, for example, at 16:12 make another commit. 然后我,例如,在16:12进行另一次提交。 The filename created is MyApp_debug_0370898_240317_1612.apk
. 创建的文件名是MyApp_debug_0370898_240317_1612.apk
。 Now, if I build the apk, my output directory has two apk: MyApp_debug_0370898_240317_1612.apk
and the previous one MyApp_debug_de2de27_240317_1554.apk
, but the apk that is uploaded to the device is the older one. 现在,如果我构建apk,我的输出目录有两个apk: MyApp_debug_0370898_240317_1612.apk
和前一个MyApp_debug_de2de27_240317_1554.apk
,但上传到设备的apk是较旧的。 I know this because if, before building the new apk after the commit, I delete the old apk. 我知道这是因为如果在提交之后构建新的apk之前,我删除旧的apk。 I get this message: 我收到这条消息:
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
If I then sync the project, MyApp_debug_0370898_240317_1612.apk
is installed. 如果我然后同步项目,则安装MyApp_debug_0370898_240317_1612.apk
。
Any idea why? 知道为什么吗?
Here is how I'm generating the filename. 这是我如何生成文件名。
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);
}
}
}
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
This error will resolve first you will click on build > clean project 首先您将单击build> clean project解决此错误
Rebuild your project. 重建您的项目。 Follow: 跟随:
Build>Rebuild project 构建>重建项目
And then build apk 然后构建apk
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.