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 目录下文件一样,如果有人知道,麻烦留言告知,感谢。