登录
  • 欢迎访问 Sharezer Blog

apk编译写入编译时间和最后次git commit的sha值

Android sharezer 2038次浏览 已收录 0个评论
apply plugin: 'com.android.application'

//创建当前时间字符创 比如 0411_1213 表示 4月11号,12点13分
def buildTime() {
    def date = new Date()
    def formattedDate = date.format('MMdd_HHmm')
    return formattedDate
}

//获取文件夹最后一次git commit的sha值
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.administrator.myapplication"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        //在BuildConfig里面创建BUILD_TIME变量,代表apk编译时间
        buildConfigField "String", "BUILD_TIME", "\"${buildTime()}\""
        //在BuildConfig里面创建GIT_SHA变量,代表本项目最新git的commit的值
        buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.2'
}

Sharezer , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明apk编译写入编译时间和最后次git commit的sha值
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址