Android Studio開發之Gradle配置格式化---升級1

序言:

此博客記錄一下,如何將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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章