Android Studio Custom Pack apk name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.