序言:
此博客记录一下,如何将Gradle参数格式化,以便于日后的升级移植等操作!
正文:
基础版:https://blog.csdn.net/qq_41811438/article/details/103548055
此处使用工程中的2个build.gradle文件来完成,这个比基础版的要好用,也好记!
1、配置工程根目录下的build.gradle文件,如下:
//Jimmy-format /////////////////////////////////////////////////////////////////////////////////////
def SupportVersion = "26.1.0"
ext{
COMPILE_SDK_VERSION = 26
APPLICATION_ID = "com.terawins.www.demo003"
MIN_SDK_VERSION = 15
TARGET_SDK_VERSION = 26
VERSION_CODE = 1
VERSION_NAME = "1.0"
//NDK
Support_CPU = 'armeabi-v7a'
CMake_Arguments = '-DANDROID_STL=c++_static'
CMake_Path = 'src/main/jni/CMakeLists.txt'
//others
TEST_Instrumentation_Runner = "android.support.test.runner.AndroidJUnitRunner"
Lib_SupportAppcompat_v7 = "com.android.support:appcompat-v7:${SupportVersion}"
Lib_SupportConstraintLayout = "com.android.support.constraint:constraint-layout:1.1.3"
Lib_Junit = "junit:junit:4.12"
Lib_SupportTestRunner = "com.android.support.test:runner:1.0.1"
Lib_SupportTestEspresso = "com.android.support.test.espresso:espresso-core:3.0.1"
}
////////////////////////////////////////////////////////////////////////////////////////////////////
配置位置,如下截图所示:
2、配置一下app目录下的build.gradle文件,给出我的示例:
我的这个Demo003是一个融合两个独立工程的工程,其中一个主工程,另一个是其附属Library模块。
主工程下的build.gradle配置如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion COMPILE_SDK_VERSION
defaultConfig {
applicationId APPLICATION_ID
minSdkVersion MIN_SDK_VERSION
targetSdkVersion TARGET_SDK_VERSION
versionCode VERSION_CODE
versionName VERSION_NAME
testInstrumentationRunner TEST_Instrumentation_Runner
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation Lib_SupportAppcompat_v7
implementation Lib_SupportConstraintLayout
testImplementation Lib_Junit
androidTestImplementation Lib_SupportTestRunner
androidTestImplementation Lib_SupportTestEspresso
implementation project(':FileDialogTest')
}
截图示范:
附属Library模块中的build.gradle配置如下:
apply plugin: 'com.android.library'
android {
compileSdkVersion COMPILE_SDK_VERSION
defaultConfig {
minSdkVersion MIN_SDK_VERSION
targetSdkVersion TARGET_SDK_VERSION
versionCode VERSION_CODE
versionName VERSION_NAME
testInstrumentationRunner TEST_Instrumentation_Runner
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//jimmy add for ndk specified
defaultConfig.externalNativeBuild.cmake{
abiFilters Support_CPU
arguments CMake_Arguments
}
externalNativeBuild {
cmake {
path CMake_Path
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation Lib_SupportAppcompat_v7
implementation Lib_SupportConstraintLayout
testImplementation Lib_Junit
androidTestImplementation Lib_SupportTestRunner
androidTestImplementation Lib_SupportTestEspresso
}
截图示警:
---- The End.