gradle dsl

2024-09-06 07:58
文章标签 gradle dsl

本文主要是介绍gradle dsl,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

仅仅是为了 提取 一些 gradle语法

compileSdkVersion: "23" as int,
 
compileSdkVersion Integer.parseInt(ANDROID_BUILD_COMPILE_SDK_VERSION)
minSdkVersion Integer.parseInt(MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode Integer.parseInt(VERSION_CODE)
versionName VERSION_NAME


 
 
 
dexOptions {javaMaxHeapSize '2g'
}

 
 
 
 
 
android.applicationVariants.all { variant ->// 开始构建当前变体的即时时间
    def currentTime = buildTime()variant.outputs.each { output ->println "**************************************"
        println "currentTime: ${currentTime}"
        println "variant: ${output.name}"
        println "buildType: ${variant.buildType.name}"
        println "flavor: ${variant.flavorName}"
        println "manifest:  ${output.processResources.manifestFile}"
        println "**************************************"

        //将生成的apk文件保存至根目录的_apk文件下
        def outputFile = output.outputFileif (outputFile != null && outputFile.name.endsWith('.apk')) {File outputDirectory = new File("${projectDir}/../_apk");def apkName = "${variant.buildType.name}/app-${output.name}-V${frameworkVersion}-#${buildNumber}-${currentTime}.apk"

            output.outputFile = new File(outputDirectory, apkName)}// 如果开启混淆,则保留混淆的映射关系文件,方便release进行调试
        if (variant.getBuildType().isMinifyEnabled()) {variant.assemble.doLast {copy {from variant.mappingFileinto "${projectDir}/../_mappings"
                    rename { String fileName ->"mapping-${output.name}-V${frameworkVersion}-#${buildNumber}-${currentTime}.txt"
                    }}}}}
}def buildTime() {return new Date().format("yyyy.MM.dd_HH.mm.ss", TimeZone.getTimeZone("UTC"))
}

 
 
 
 
import org.tmatesoft.svn.core.wc.*
import org.tmatesoft.svn.core.wc2.*
import org.tmatesoft.svn.core.*
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
// 包名
applicationId "com.zhb.studiotest"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0.0.1"
manifestPlaceholders = [ CHANNEL_NAME:"Unspecified",APPLICATION_LABLE:"StudioTest"]
}
sourceSets.main.jni.srcDirs = []
sourceSets.main.jniLibs.srcDir 'src/main/libs'
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def prename = versionProps['VERSION_NAME_MAJOR']
def name = versionProps['VERSION_NAME_BUILD'].toInteger()
def runTasks = gradle.startParameter.taskNames
if ('buildAll' in runTasks) {
name++
}
versionProps['VERSION_NAME_BUILD']=name.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
versionName prename + name
}
}
signingConfigs {
releaseConfig {
// 写死签名密码
keyAlias 'xxx'
keyPassword 'xxxx'
storeFile file("keystore.jks")
storePassword 'xxxx'
// 要求输入签名密码
//            storeFile file("keystore.jks")
//            keyAlias System.console().readLine("\nkeyAlias: ")
//            storePassword System.console().readLine("\nKeystore password: ")
//            keyPassword System.console().readLine("\nKey password: ")
}
}
/*productFlavors {
xiaomi {
applicationId = "com.zhb.xiaomi"
manifestPlaceholders = [UMENG_CHANNEL_VALUE: name,APPLICATION_LABLE:name]
}
baidu {
applicationId = "com.zhb.baidu"
manifestPlaceholders = [UMENG_CHANNEL_VALUE: name,APPLICATION_LABLE:name]
}
wandoujia {
applicationId = "com.zhb.wandoujia"
manifestPlaceholders = [UMENG_CHANNEL_VALUE: name,APPLICATION_LABLE:name]
}
}*/
productFlavors {
wandoujia {}
baidu {}
//c360 {}
//uc {}
productFlavors.all { flavor ->
applicationId = "com.zhb."+name
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name,APPLICATION_LABLE:name]
}
}
buildTypes {
debug {
buildConfigField "boolean", "LOG_DEBUG", "true"
versionNameSuffix "-debug"
// 混淆开关
minifyEnabled false
// 在Android中,每个应用程序中储存的数据文件都会被多个进程访问:
// 安装程序会读取应用程序的manifest文件来处理与之相关的权限问题;
// Home应用程序会读取资源文件来获取应用程序的名和图标;
// 系统服务会因为很多种原因读取资源(例如,显示应用程序的Notification);
// 此外,就是应用程序自身用到资源文件。
// 当资源文件通过内存映射对齐到4字节边界时,访问资源文件的代码才是有效率的。
zipAlignEnabled false
// 删除没用的资源文件
shrinkResources false
}
release {
buildConfigField "boolean", "LOG_DEBUG", "false"
minifyEnabled true
zipAlignEnabled true
shrinkResources true
// 混淆文件
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// 签名
signingConfig signingConfigs.releaseConfig
applicationVariants.all { variant ->
// 修改APK名称
variant.outputs.each { output ->
def file = output.outputFile
def fileName = file.name
fileName = fileName.replace(".apk", "-V${defaultConfig.versionName}.apk")
fileName = fileName.replace("app", "StudioTest")
fileName = fileName.replace("debug-unaligned", "debug")
output.outputFile = new File(file.parent, fileName)
}
// 修改values.xml
variant.mergeResources.doLast(){
File valuesFile = file("${buildDir}/intermediates/res/merged/${variant.dirName}/values/values.xml")
String content = valuesFile.getText('UTF-8')
content = content.replaceAll("CHANNEL_NAME","${variant.productFlavors[0].name}")
valuesFile.write(content,'UTF-8')
}
}
}
}
}
def getSvnRevision(){
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
SVNClientManager clientManager = SVNClientManager.newInstance(options);
SVNStatusClient statusClient = clientManager.getStatusClient();
SVNStatus status = statusClient.doStatus(project.rootDir, false);
SVNRevision revision = status.getRevision();
return revision.getNumber();
}
task svnCommitVersionFile(){
description = "Commits a single file to an SVN repository"
doLast{
if (!project.hasProperty("commitMsg")){
ext.commitMsg = "//change version"
}
SvnOperationFactory svnOperationFactory = new SvnOperationFactory()
def authentication = SVNWCUtil.createDefaultAuthenticationManager("haibo.zhou", "hbzhou0622")
svnOperationFactory.setAuthenticationManager(authentication)
try {
SvnCommit commit = svnOperationFactory.createCommit()
commit.setSingleTarget(SvnTarget.fromFile(new File('app/version.properties')))
commit.setCommitMessage(commitMsg)
SVNCommitInfo commitInfo = commit.run()
println "Commit info: " + commitInfo
println "Commit message: " + commitMsg
} finally{
svnOperationFactory.dispose()
}
}
}
task generateZip(type: Zip){
def versionPropsFile = file('version.properties')
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def prename = versionProps['VERSION_NAME_MAJOR']
def name = versionProps['VERSION_NAME_BUILD'].toInteger()
def version = "V" + prename + name + "_(" + getSvnRevision() + ")"
from 'build/outputs'
archiveName "StudioTest_" + version + ".zip"
destinationDir file("build/release")
doLast(){
copy{
from ("build/release/"+archiveName)
into ("release")
}
if (!project.hasProperty("commitMsg")){
ext.commitMsg = "//upload compile result"
}
SvnOperationFactory svnOperationFactory = new SvnOperationFactory()
def authentication = SVNWCUtil.createDefaultAuthenticationManager("haibo.zhou", "hbzhou0622")
svnOperationFactory.setAuthenticationManager(authentication)
try {
SvnScheduleForAddition add = svnOperationFactory.createScheduleForAddition();
SvnTarget target = SvnTarget.fromFile(new  File("app/release/"+archiveName));
add.addTarget(target);
add.setAddParents(true);
add.setForce(true);
add.run();
SvnCommit commit = svnOperationFactory.createCommit()
commit.setSingleTarget(SvnTarget.fromFile(new File("app/release/"+archiveName)))
commit.setCommitMessage(commitMsg)
SVNCommitInfo commitInfo = commit.run()
println "Commit info: " + commitInfo
println "Commit message: " + commitMsg
} finally{
svnOperationFactory.dispose()
}
}
}
// build script for jenkins only
task buildAll(){
println 'start build'
}
svnCommitVersionFile.dependsOn build
generateZip.dependsOn svnCommitVersionFile
buildAll.dependsOn generateZip
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
workingDir file('src/main/jni')
commandLine getNdkBuildCmd()
}
task cleanNative(type: Exec){
workingDir file('src/main/jni')
commandLine getNdkBuildCmd(), 'clean'
}
clean.dependsOn cleanNative
def getNdkDir() {
if (System.env.ANDROID_NDK_ROOT != null)
return System.env.ANDROID_NDK_ROOT
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkdir = properties.getProperty('ndk.dir', null)
if (ndkdir == null)
throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")
return ndkdir
}
def getNdkBuildCmd() {
def ndkbuild = getNdkDir() + "/ndk-build"
ndkbuild += ".cmd"
return ndkbuild
}
dependencies {
// 工程目录里面的libs文件夹下所有的jar包
compile fileTree(dir: 'libs', include: ['*.jar'])
// 网络仓库里面的工程
//compile 'com.github.chrisbanes.photoview:library:1.2.4'
// 本地的工程
compile project(':PhotoView-master')
}

这篇关于gradle dsl的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1141450

相关文章

Gradle的基本使用

新建一个项目后,在项目文件夹下创建build.gradle文件,并加入内容:       apply plugin: 'eclipse'。    然后在终端运行gradle eclipse即可构建eclipse IDE的开发环境。    gradle默认值:gradle有些目录是有默认值存在,建议项目的配置,承袭了maven的风格,如:         java的源码目录:src/mai

使用gradle做第一个java项目

涉及到的任务如下: assemble任务会编译程序中的源代码,并打包生成Jar文件,这个任务不执行单元测试。 Total time: 5.581 secs E:\workspace\Test>gradle assemble :compileJava :processResources UP-TO-DATE :classes :findMainClass :jar :b

Gradle的安装和配置

Gradle是一个基于JVM的构建工具,它提供了: 像Ant一样,通用灵活的构建工具可以切换的,基于约定的构建框架强大的多工程构建支持基于Apache Ivy的强大的依赖管理支持maven, Ivy仓库支持传递性依赖管理,而不需要远程仓库或者是pom.xml和ivy.xml配置文件。对Ant的任务做了很好的集成基于Groovy,build脚本使用Groovy编写有广泛的领域模型支持构建 G

ElasticSearch的DSL查询⑤(ES数据聚合、DSL语法数据聚合、RestClient数据聚合)

目录 一、数据聚合 1.1 DSL实现聚合 1.1.1 Bucket聚合  1.1.2 带条件聚合 1.1.3 Metric聚合 1.1.4 总结 2.1 RestClient实现聚合 2.1.1 Bucket聚合 2.1.2 带条件聚合 2.2.3 Metric聚合 一、数据聚合 聚合(aggregations)可以让我们极其方便的实现对数据的统计、分析、运算。例如:

ElasticSearch的DSL查询④(DSL查询、RestClient的DSL查询)

目录 一、DSL查询 1.1 快熟入门 1.2 叶子查询 1.2.1 全文检索查询 1)match查询 2)multi_match查询 1.2.2 精确查询 1)term查询 2)range查询 3)ids查询 1.3 复合查询 1.3.1 bool查询 1.3.2 算分函数查询 1)基本语法: 2)运行流程: 3)示例: 4)执行结果: 1.4 排序 1.5

兔子-build.gradle中代码的含义

//声明构建的项目类型,这里当然是android了apply plugin: 'com.android.application'//设置编译android项目的参数android {// SDK的版本号,也就是API Level,例如API-19、API-20、API-21等等。compileSdkVersion 23//构建工具的版本,其中包括了打包工具aapt、dx等等。// 这个工具的目

Android Studio打开Modem模块出现:The project ‘***‘ is not a Gradle-based project

花了挺长时间处理该问题,特记录如下:1.背景: 在Android studio 下导入一个新增的modem模块,如MPSS.DE.3.1.1\modem_proc\AAA, 目的是看代码方便一些,可以自由搜索各种关键字。但导入该项目时出现了如下错误: The project '***' is not a Gradle-based project.造成的问题: (1) project 下没有代码,而

【Flutter】解决第一次运行项目很慢(gradle需要下载依赖)

配置gradle默认下载路径 默认下C盘谁顶得住 配置环境变量 名称: GRADLE_USER_HOME 值: D:\Develop\gradle 自己创建一个 下边是重点 配置gradle远端下载地址 后边版本号自己换 https://mirrors.cloud.tencent.com/gradle/ https://mirrors.cloud.tencent.com/gradle/g

Android Studio下载Gradle失败问题解决

问题说明 使用 Android Studio 构建程序报错如下 Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-7.5.1-bin.zip'.Reason: java.net.SocketTimeoutException: Connect timed ou

Elastic Stack--ES的DSL语句查询

前言:本博客仅作记录学习使用,部分图片出自网络,如有侵犯您的权益,请联系删除 学习B站博主教程笔记:  最新版适合自学的ElasticStack全套视频(Elk零基础入门到精通教程)Linux运维必备—ElasticSearch+Logstash+Kibana精讲_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1VMW3e6Ezk/?spm_