Android Studio打包apk自动获取SVN号、时间、

2020-05-18  本文已影响0人  飞天_shine

备注:打包之前一定要记得首先从svn update一下代码 这样才能保证打包的svn号是当前最新的SVN号

一、根目录下build.gradle文件配置

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {

mavenCentral()

google()

jcenter()

}

dependencies {

classpath 'com.android.tools.build:gradle:3.5.3'

    classpath "org.tmatesoft.svnkit:svnkit:1.8.11"//1.添加此处

}

}

allprojects {

repositories {

mavenCentral()

google()

jcenter()

maven { url "https://jitpack.io" }

}

}

task clean(type: Delete) {

delete rootProject.buildDir

}

​​​​​​​二、app中的build.gradle文件配置

apply plugin: 'com.android.application'

import org.tmatesoft.svn.core.wc.*//2.添加此处

//3.添加时间

def releaseTime() {

    return new Date().format("yyMMddHHmm", TimeZone.getTimeZone("GMT+08:00"))

}

//4.添加SVN号

def getSvnRevision() {

    ISVNOptions options = SVNWCUtil.createDefaultOptions(true)

    SVNClientManager clientManager = SVNClientManager.newInstance(options)

    SVNStatusClient statusClient = clientManager.getStatusClient()

    SVNStatus status = statusClient.doStatus(projectDir, false)

    status.getCommittedRevision().getNumber()

    SVNRevision revision = status.getCommittedRevision()

    return revision.getNumber()

}

android {

    compileSdkVersion 28

    defaultConfig {

        applicationId "com.a.b"

        minSdkVersion 19

        targetSdkVersion 22

        versionCode 2

        versionName "2.2"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled true

    }

    buildTypes {

        debug {

            minifyEnabled false

            //app打包名称

            android.applicationVariants.all { variant ->

                variant.outputs.all {

                    outputFileName = "app_v${variant.versionName}_debug_${releaseTime()}_svn${getSvnRevision()}_V${variant.versionCode}.apk"

                }

            }

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            signingConfig signingConfigs.debug

            debuggable true

            jniDebuggable true

        }

        release {

            minifyEnabled false

            android.applicationVariants.all { variant ->

                variant.outputs.all {

                    outputFileName = "app_v${variant.versionName}_release_${releaseTime()}_svn${getSvnRevision()}_V${variant.versionCode}.apk"

                }

            }

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            signingConfig signingConfigs.release

            debuggable false

            jniDebuggable false

        }

    }

    buildToolsVersion '28.0.3'

}

dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation fileTree(include: ['*.aar'], dir: 'libs')

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    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'

}

————————————————

版权声明:本文为CSDN博主「会飞的猪_shine」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/qq_32673327/article/details/106196757

三、最终打包apk名称

app_v1.1_release_2005181652_svn999_V1.apk

备注:打包之前一定要记得首先从svn update一下代码 这样才能保证打包的svn号是当前最新的SVN号

上一篇下一篇

猜你喜欢

热点阅读