编程知识 cdmana.com

Grade for Android 之九: android studio build.gradle脚本示例

apply plugin: 'com.android.application'
ext {
    buildInfo = [
            build_time : getFirstBuildTime(),
            vcs_version: getGitVersion(),
            app_name   : "TOKENPICK"
    ]
}

def getFirstBuildTime() {
    return new Date().format('yyyyMMddHHmmss')
}

// 获取提交记录后6位:没有返回 yyDDmm 日期
def getGitVersion() {
    String desc = 'git describe --always'.execute().getText().trim()
    return (desc == null || desc.size() == 0) ? new Date().format("yyMMdd") : desc.substring(desc.size() - 6)
}

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }

    }
}

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "net.joisen.lingjian"
        resValue "string", "app_name", buildInfo.app_name
        buildConfigField "String", "URL", '"http://lingjian.joisen.net.cn:8019/app/"'
        buildConfigField "String", "UPDATE_URL", '"http://47.104.31.171:8020/index.php/other/version"'
        buildConfigField "String", "BUILDTIME", '"' + "${buildInfo.build_time}" + '"'

        minSdkVersion 15
        targetSdkVersion 26
        versionCode 100
        versionName "1.0.0"
    }

    signingConfigs {
        release {
            keyAlias 'key0'
            keyPassword 'truss123'
            storeFile file('ext/su.jks')
            storePassword 'truss123'
        }
        debug {
            storeFile file('ext/debug.keystore')
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            signingConfig signingConfigs.release
        }
        debug {
            minifyEnabled false
            shrinkResources true
            signingConfig signingConfigs.debug
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    lintOptions {
        abortOnError false
        ignoreWarnings true
        checkReleaseBuilds false
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }

    applicationVariants.all {
        variant ->
            variant.outputs.each { output ->
                def outputFile = output.outputFile
                if (outputFile != null && !outputFile.name.contains("unaligned") && variant.buildType.name == "release") {
                    def fileName = "${buildInfo.app_name}_v${defaultConfig.versionName}_${buildInfo.build_time}_${variant.buildType.name}.apk"
                    output.outputFile = new File(project.buildDir.absolutePath + "/outputs/apk/" + fileName)
                    println("set fileName >>>>>>>>>>>  " + output.outputFile.absolutePath)
                }
            }
    }


    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.github.delight-im:Android-AdvancedWebView:v3.0.0'
        compile 'com.android.support:support-v4:24.0.0-alpha1'
    }
}

 

文章整理来自:https://my.oschina.net/sfshine/blog/1941298

版权声明
本文为[架构师训练营]所创,转载请带上原文链接,感谢
https://cbk419323.blog.csdn.net/article/details/89577782

Scroll to Top