【发布时间】:2016-06-03 09:41:01
【问题描述】:
这是一个使用 gradle 的 Android 应用程序。点击Run后,在outputs/apk中找到了APP_V1.3.4_2016-02-22_11:30:29_google_play.apk,但是事件日志说:
11:30:31 EmptyThrowable:APK 文件 /.../WorkSpace/Android/.../app/build/outputs/apk/APP_V1.3.4_2016-02-22_11:30:14 _google_play.apk 在磁盘上不存在。
11:30:32 会话“应用程序”:安装 APK 时出错
这是我的build.gradle 文件:
apply plugin: 'com.android.application'
def releaseTime() {
return new Date().format("yyyy-MM-dd_HH:mm:ss",
TimeZone.getTimeZone("GMT+08:00"))
}
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 23
versionCode 29
versionName "1.3.4"
manifestPlaceholders = [SOME_CHANNEL_VALUE: "some_channel"]
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
debug {}
release {
// ...
}
}
buildTypes {
debug {
zipAlignEnabled true
minifyEnabled false
shrinkResources true
}
release {
zipAlignEnabled true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
signingConfig signingConfigs.release
applicationVariants.all { variant ->
def time = releaseTime()
variant.outputs.each { output ->
def apk = output.outputFile
def endFileName = "${time}_${variant.productFlavors[0].name}.apk"
if (apk != null &&
apk.name.endsWith('.apk') &&
!apk.name.endsWith('${endFileName}')) {
def fileName = "APP_V${defaultConfig.versionName}_${endFileName}"
output.outputFile = new File(apk.parentFile, fileName)
}
}
}
}
}
productFlavors {
google_play {
manifestPlaceholders = [SOME_CHANNEL_VALUE: "google_play"]
}
}
}
dependencies {
// ...
}
那么releaseTime()有什么问题吗?
【问题讨论】:
-
是的,你看到确切的时间了吗?一是11:30:14。另一个是 11:30:29(这是您发现的,但与计算机预期的不同)
-
@ucsunil 感谢您的回复。我注意到两次之间的区别,但我不知道如何解决它:(我不知道gradle是如何找到apk的。
-
建议使用 git date 代替:例如。 "git show -s --format=%ci" 以及更多内容:github.com/JakeWharton/u2020/blob/master/build.gradle 关于漂亮格式:git-scm.com/docs/pretty-formats
标签: android gradle android-gradle-plugin