Android你要的打包技巧,自定义打包apk名称,统一版本号

project中的Build.gradle,设置同一版本名称和版本号
ext {
commonComplainSdkVersion = “28.0.0”
}

//app build.gradle中使用改版本号
implementation “com.android.support:appcompat-v7: r o o t P r o j e c t . e x t . c o m m o n C o m p l a i n S d k V e r s i o n " i m p l e m e n t a t i o n " c o m . a n d r o i d . s u p p o r t : s u p p o r t − v 4 : rootProject.ext.commonComplainSdkVersion" implementation "com.android.support:support-v4: rootProject.ext.commonComplainSdkVersion"implementation"com.android.support:supportv4:rootProject.ext.commonComplainSdkVersion”
implementation “com.android.support:design: r o o t P r o j e c t . e x t . c o m m o n C o m p l a i n S d k V e r s i o n " i m p l e m e n t a t i o n " c o m . a n d r o i d . s u p p o r t : r e c y c l e r v i e w − v 7 : rootProject.ext.commonComplainSdkVersion" implementation "com.android.support:recyclerview-v7: rootProject.ext.commonComplainSdkVersion"implementation"com.android.support:recyclerviewv7:rootProject.ext.commonComplainSdkVersion”
implementation “com.android.support:cardview-v7:$rootProject.ext.commonComplainSdkVersion”

按照规定名称打包apk
android{
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = “beiangII_v”+versionCode+releaseTime()+".apk"
}
}

}
//定义方法
def releaseTime() {
return “_”+new Date().format(“yyyyMMddHHmm”, TimeZone.getTimeZone(“UTC”))
}

//Android Studio统一管理依赖版本号引用配置
ext {
globalCompileSdkVersion = 27
globalBuildToolsVersion = “27.0.3”
globalTargetSdkVersion = 27
globalMinSdkVersion = 16
supportLibraryVersion = “27.1.1”

/*===常用的引=====*/
//supportLibVersion 的头数字是和targetSdkVersion 版本一样的。
androidDependencies = [
        appcompat_v7 : "com.android.support:appcompat-v7:${supportLibraryVersion}",
        design        : "com.android.support:design:${supportLibraryVersion}",
        support_v4    : "com.android.support:support-v4:${supportLibraryVersion}",
        recyclerView : "com.android.support:recyclerview-v7:${supportLibraryVersion}",
]
/*=================================module中公共用到的引用
globalDependencies = [
        constraintLayout : "com.android.support.constraint:constraint-layout:1.1.2",
        glide : "com.github.bumptech.glide:glide:4.7.1",
]

}

apply plugin: ‘com.android.application’
android {
compileSdkVersion rootProject.ext.globalCompileSdkVersion
defaultConfig {
applicationId “com.why.project.androidcnblogsdemo”
minSdkVersion rootProject.ext.globalMinSdkVersion
targetSdkVersion rootProject.ext.globalTargetSdkVersion
}
}

dependencies {
implementation fileTree(dir: ‘libs’, include: [’*.jar’])
implementation androidDependencies.appcompat_v7
implementation globalDependencies.constraintLayout
implementation globalDependencies.glide
}

你可能感兴趣的