Android Gradle 之 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26

    def VOICE_REQUEST = true
    defaultConfig {
        applicationId 'com.test.project'
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    // Encapsulates signing configurations.
    signingConfigs {
        // Creates a signing configuration called "release".
        release {
            // Specifies the path to your keystore file.
            storeFile file("my-release-key.jks")
            // Specifies the password for your keystore.
            storePassword "password"
            // Specifies the identifying name for your key.
            keyAlias "my-alias"
            // Specifies the password for your key.
            keyPassword "password"
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    android.applicationVariants.all {
        variant ->
            variant.outputs.all {
                // 此处指定生成的apk文件名
                outputFileName = "test.apk"
            }
            if(!VOICE_REQUEST){
                //if not support voice search, delete asset file while build apk
                variant.mergeAssetsProvider.get().doLast{
                    delete(fileTree(dir: variant.mergeAssets.outputDir, includes: ['iflytek/**/*','iat/*']))
                }
            }
    }

    lintOptions {
        abortOnError false
        checkReleaseBuilds false
        // 防止在发布的时候出现因MissingTranslation导致Build Failed!
        disable 'MissingTranslation'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField("Boolean","VOICE_REQUICE","${VOICE_REQUEST}")
            // if need sign,enable it
            //signingConfig signingConfigs.release
        }
        debug {
            buildConfigField("Boolean","VOICE_REQUICE","${VOICE_REQUEST}")
            //Log.i(TAG, getString(R.string.build_time));
            //resValue("string", "build_time", "${minutesSinceEpoch}")
        }
    }
    productFlavors {
    }
    buildToolsVersion = '29.0.2'
    ndkVersion '23.0.7599858'
}
repositories {
    mavenCentral()
    
    maven { url "https://jitpack.io" }
}
dependencies {
    //api fileTree(include: ['*.jar'], dir: 'libs')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //implementation 'com.android.support:design:26.1.0'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation "com.android.support:appcompat-v7:26.0.0-beta1"
    testImplementation 'junit:junit:4.13-beta-3'

    implementation 'net.zetetic:android-database-sqlcipher:4.2.0'


}

1.在gradle 里面如何定义变量然后在JAVA代码里面使用,可能 通过buildConfigField

buildConfigField("Boolean","VOICE_REQUICE","${VOICE_REQUEST}")

2. 在编译过程中动态删除asset 目录下的资料

更多关于build.gradle 如何编写来编译可以参考google官方地址  https://developer.android.com/studio/build

https://developer.android.com/studio/build/gradle-tips#groovy

本人还有一个问题,就是在编译过程中如何动态删除lib库的so 文件,因为根据项目需求,如果编译的APK 不需要支持某些功能,就可以删除这些功能对应的so文件。跟前面删除asset 目录下文件一样,如果有人知道,麻烦留言告知,感谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值