common.gradle 5.1 KB
if ("app" == project.name) {
    apply plugin: 'com.android.application'
} else {
    if (isBuildModule.toBoolean()) {
        if (project.name == "common" || project.name == "commonRes" || project.name == "network") {
            apply plugin: 'com.android.library'
        } else {
            apply plugin: 'com.android.application'
        }
    } else {
        apply plugin: 'com.android.library'
    }
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
kapt {
    arguments {
        arg("AROUTER_MODULE_NAME", project.getName())
    }

}
kapt {
    correctErrorTypes true
}

android {
    compileSdkVersion rootProject.ext.android["compileSdkVersion"]
    buildToolsVersion rootProject.ext.android["buildToolsVersion"]
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        if (project.name == "app") {
            applicationId rootProject.ext.project["applicationId"]
        } else {
            if (isBuildModule.toBoolean() && project.name != "common" && project.name != "commonRes" && project.name != "network") {
                applicationId rootProject.ext.project["applicationId"] + ".${project.name}"
            }
        }
        minSdkVersion rootProject.ext.android["minSdkVersion"]
        targetSdkVersion rootProject.ext.android["targetSdkVersion"]
        versionCode rootProject.ext.android["versionCode"]
        versionName rootProject.ext.android["versionName"]
        testInstrumentationRunner rootProject.ext.dependencies["androidJUnitRunner"]
        multiDexEnabled true
        ndk {
            //选择要添加的对应 cpu 类型的 .so 库。
            abiFilters 'armeabi', 'armeabi-v7a'
            // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
        }
    }
    signingConfigs { //签名配置
        config {
            storeFile file("../sign_tools/lianhe.jsk")
            storePassword rootProject.ext.sign["KEYSTORE_PASSWORD"]
            keyAlias rootProject.ext.sign["KEY_ALIAS"]
            keyPassword rootProject.ext.sign["KEY_PASSWORD"]
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }
    buildTypes {
        debug {
            buildConfigField "String", "API_HOST", "${host_debug}"//本地测试
            buildConfigField "boolean", "LOG_DEBUG", "true"
            buildConfigField "boolean", "IS_BUILD_MODULE", "${isBuildModule}"
            minifyEnabled false
            signingConfig signingConfigs.config
            zipAlignEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        release {
            buildConfigField "String", "API_HOST", "${host_api}"//测试地址
            buildConfigField "boolean", "LOG_DEBUG", "false"
            buildConfigField "boolean", "IS_BUILD_MODULE", "${isBuildModule}"
            minifyEnabled false
            zipAlignEnabled true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        beta {
            buildConfigField "String", "API_HOST", "${host_cs}"//测试地址
            buildConfigField "boolean", "LOG_DEBUG", "false"
            buildConfigField "boolean", "IS_BUILD_MODULE", "${isBuildModule}"
            minifyEnabled false
            zipAlignEnabled true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        //sh环境
        uat {
            buildConfigField "String", "API_HOST", "${host_sh}"//测试地址
            buildConfigField "boolean", "LOG_DEBUG", "false"
            buildConfigField "boolean", "IS_BUILD_MODULE", "${isBuildModule}"
            minifyEnabled false
            zipAlignEnabled true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    dataBinding {
        enabled = true
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        disable 'InvalidPackage'
        disable "ResourceType"
        abortOnError false
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    // App dependencies
    api fileTree(dir: 'libs', include: ['*.jar'])

    // Kotlin
    api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10"
    //test
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    // Hilt  因为顶部依赖了hilt 插件 apply plugin: 'dagger.hilt.android.plugin' 所以 以下两个hilt的依赖是必须的
    api "com.google.dagger:hilt-android:2.29.1-alpha"
    kapt "com.google.dagger:hilt-android-compiler:2.29.1-alpha"
    //hilt
    api 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02'
    kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'


}