Android 自动递增 versionCode 为 svn 版本号

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/johnWcheung/article/details/80819990

// project build.gradle

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath group: 'org.tmatesoft.svnkit', name: 'svnkit', version: '1.8.11'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            // 此处是相对路径,服务器和本地统一使用这个路径
            options.compilerArgs.add('-Xbootclasspath/p:app/tvos/framework.jar')
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

//module build.gradle

import org.tmatesoft.svn.core.wc.*
apply plugin: 'com.android.application'

def getSvnRevision() {
    ISVNOptions options = SVNWCUtil.createDefaultOptions(true)
    SVNClientManager clientManager = SVNClientManager.newInstance(options)
    SVNStatusClient statusClient = clientManager.getStatusClient()
    SVNStatus status = statusClient.doStatus(projectDir, false)
    SVNRevision revision = status.getCommittedRevision()
    return revision.getNumber()
}

def getVersionName = {
    return new Date().format("yyyy.MM.dd.HH.mm.ss")
}

def getVersionCode = {
    long svnVersion = getSvnRevision()
    return svnVersion.toInteger()
}

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.xx.xx"
        minSdkVersion 23
        targetSdkVersion 27
        versionCode getVersionCode()
        versionName getVersionName()
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        XxkeyStore {
            keyAlias 'androiddebugkey'
            keyPassword 'android'
            storeFile file('xx.keystore')
            storePassword 'android'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.XxkeyStore
        }
        debug {
            signingConfig signingConfigs.XxkeyStore
        }
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

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'
    compileOnly files('os/xxx.jar')
}

猜你喜欢

转载自blog.csdn.net/johnWcheung/article/details/80819990
今日推荐