Singkatnya, bagi mereka yang tidak tahu cara mengimpor paket build.gradle
(seperti saya), gunakan yang berikut buildTypes
,
buildTypes {
release {
signingConfig signingConfigs.release
applicationVariants.all { variant ->
def file = variant.outputFile
def manifestParser = new com.android.builder.core.DefaultManifestParser()
variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile) + ".apk"))
}
}
}
===== EDIT =====
Jika Anda mengatur versionCode
dan versionName
dalam build.gradle
file Anda seperti ini:
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0.0"
}
Anda harus mengaturnya seperti ini:
buildTypes {
release {
signingConfig signingConfigs.releaseConfig
applicationVariants.all { variant ->
def file = variant.outputFile
variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
====== EDIT dengan Android Studio 1.0 ======
Jika Anda menggunakan Android Studio 1.0, Anda akan mendapatkan kesalahan seperti ini:
Error:(78, 0) Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@67e7625f.
Anda harus mengubah build.Types
bagian ini:
buildTypes {
release {
signingConfig signingConfigs.releaseConfig
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
}