Android build.gradle版本名打包配置的方法
程序员文章站
2022-03-02 15:09:55
1、生成密钥文件到app工程目录下
2、在gradle.properties文件下配置密钥文件信息
# project-wide gradle se...
1、生成密钥文件到app工程目录下
2、在gradle.properties文件下配置密钥文件信息
# project-wide gradle settings. # ide (e.g. android studio) users: # gradle settings configured through the ide *will override* # any settings specified in this file. # for more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # specifies the jvm arguments used for the daemon process. # the setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-xmx1536m # when configured, gradle will run in incubating parallel mode. # this option should only be used with decoupled projects. more details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true release_key_password=key-password release_key_alias=key-alias release_store_password=store-password #jks文件名 release_store_file=sugr-ivy.jks
3、build.gradle文件下配置
apply plugin: 'com.android.application' android { compilesdkversion 26 project.archivesbasename = "appname" defaultconfig { applicationid "com.example.app" minsdkversion 23 targetsdkversion 26 versioncode 1 versionname "1.4.0" testinstrumentationrunner "android.support.test.runner.androidjunitrunner" } signingconfigs { release { keyalias release_key_alias keypassword release_key_password storefile file(release_store_file) storepassword release_store_password } debug { keyalias release_key_alias keypassword release_key_password storefile file(release_store_file) storepassword release_store_password } } buildtypes { release { buildconfigfield "boolean", "log_debug", "false" // 不显示log minifyenabled false //混淆 proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' signingconfig signingconfigs.release //签名 } debug { signingconfig signingconfigs.debug //签名 } } applicationvariants.all { variant -> variant.outputs.all { calendar calendar = calendar.getinstance(locale.china); def builddate = string.format(locale.china, "%04d%02d%02d", calendar.get(calendar.year), calendar.get(calendar.month) + 1, calendar.get(calendar.day_of_month)) def versionname = defaultconfig.versionname def versioncode = defaultconfig.versioncode //android studio3.0之前的写法 // output->output.outputfile=new file(output.outputfile.parent,output.outputfile.name.replace(".apk","-"+defaultconfig.versionname+".apk")) //android studio3.0的写法 //项目名-版本名-版本号-release/debug.apk if (variant.buildtype.name.equals('release')) { outputfilename = "${project.archivesbasename}-v${versionname}-c${versioncode}-${builddate}-release.apk" } else { outputfilename = "${project.archivesbasename}-v${versionname}-c${versioncode}-${builddate}-debug.apk" } } } } dependencies { implementation filetree(dir: 'libs', include: ['*.jar']) testimplementation 'junit:junit:4.12' androidtestimplementation 'com.android.support.test:runner:1.0.2' androidtestimplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:recyclerview-v7:26.1.0' }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。