Android studio 中build.gradle的配置

指定文件名称

// 指定名称
    android.libraryVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith("release.aar")) {
                def fileName = "payegis-did-v${defaultConfig.versionName}-release.aar"
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }

Android studio默认会有so文件进行压缩优化,加入以下配置可以不压缩so

 packagingOptions{
        doNotStrip "*/armeabi/*.so"
        doNotStrip "*/armeabi-v7a/*.so"
//            doNotStrip "*/x86/*.so"
    }

忽略链接错误

lintOptions {
        abortOnError false
    }

签名文件配置

    signingConfigs {
        def alias = "key0"
        def password = "111111"
        def keyPass = "111111"
        def filePath = "keystore.jks"  //签名文件路径
        debug {
            v1SigningEnabled true
            v2SigningEnabled true
            keyAlias alias
            keyPassword keyPass
            storeFile file(filePath)
            storePassword(password)
        }
        release {
            v1SigningEnabled true
            v2SigningEnabled true
            keyAlias alias
            keyPassword keyPass
            storeFile file(filePath)
            storePassword(password)
        }
    }

配置BuildConfig.java中常量

release {
            buildConfigField "String", "SO_VERSION", project.so_version
            buildConfigField("boolean", "LOG_DEBUG", "false")
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

使用gradle.properties中的配置
如gradle.properties中添加如下键值对

version_code=108
version_name=5.6.0

build.gradle中可以通过project引用

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 25
        versionCode project.version_code.toInteger()
        versionName project.version_name
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

build.gradle使用编译时的额外参数,如在使用gradlew打包指令时添加参数

gradlew build -PtestParams=true

build.gradle可以根据参数进行条件分支处理

if (project.hasProperty("testParams")) {
...
} 
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,328评论 19 139
  • Gradle对于很多开发者来说有一种既熟悉又陌生的感觉,他是离我们那么近,以至于我每天做项目都需要他,但是他又是离...
    阿_希爸阅读 13,175评论 10 199
  • 1.介绍 如果你正在查阅build.gradle文件的所有可选项,请点击这里进行查阅:DSL参考 1.1新构建系统...
    Chuckiefan阅读 14,165评论 8 72
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,173评论 25 709
  • 放下 文/海煦 放下 放下 放下了多少次 祈愿 祈愿 祈愿了多少回 普陀山 我的心归之处 还愿了 回愿...
    海煦阅读 2,615评论 3 7