Android Studio Packaging App The default generated apk name is: app-release.apk, if we want to let the generated apk name with our version of the package name, then we will have to customize the generated apk name
You need to add the following in the Build.gradle (module:app) file android{}:
//apk name defAndroid.applicationVariants.all {variant-Variant.outputs.each {Output-Output.outputfile=NewFile (output.outputFile.parent, Defaultconfig.applicationid +"-"+ Buildtype.name +"- v"+Defaultconfig.versionname+"-"+ Defaultconfig.versioncode +". apk" ); } }
This way we pack the APK name is: com.test.demo-release-v1.01-2.apk, automatically bring our package name and version number, save each time you have to manually change.
如果要生成如下版本号时间戳的apk包名,则可以用如下build.gradle代码:
模块名-渠道名-版本号-版本名称-包名-编译时间.apk
Apply plugin:'com.android.application'def releasetime () {return NewDate (). Format ("YYYY-MM-DD", Timezone.gettimezone ("UTC"))}android {compilesdkversion atbuildtoolsversion"23.0.1"Defaultconfig {ApplicationID"com.djk.myapplication"minsdkversion -targetsdkversion atVersioncode1Versionname"1.0"} buildtypes {release {minifyenabledfalseproguardfiles Getdefaultproguardfile ('Proguard-android.txt'),'Proguard-rules.pro'}} productflavors{develop{} xiaomi{} huawei{} anzhi{}} ANDROID.APPL Icationvariants.all {Variant-Variant.outputs.each {Output-def OutputFile=Output.outputfileif(OutputFile! =NULL&& OutputFile.name.endsWith ('. apk')) { //here to modify the APK filenamedef fileName ="demo_${variant.productflavors[0].name}-${defaultconfig.versioncode}-${defaultconfig.versionname}-${ Releasetime ()}.apk" //def fileName = OutputFile.name.replace ("App", "${rootproject.ext.appname}-${releasetime ()}-${ Defaultconfig.versioncode}-${defaultconfig.versionname} ")Output.outputfile=NewFile (Outputfile.parent, FileName)}} }}dependencies {Compile filetree (dir:'Libs', include: ['*.jar']) Testcompile'junit:junit:4.12'Compile'com.android.support:appcompat-v7:23.1.0'}
Effect
Android Studio Custom Pack apk name