小编Nic*_*lio的帖子

如何在 Kotlin DSL 中为多模块项目创建“基础”gradle 文件?

为了重用 gradle 文件中的代码,我通常有一个用于某些模块的“基本”gradle 文件,只需应用它们并添加它可能需要的任何新依赖项。我正在将所有 gradle 文件转换为新的 Kotlin DSL,但使用以下“基本”文件时出现关键字“未解析的引用”错误。

plugins {
    id("com.android.library")
    kotlin("kotlin.android")
    kotlin("kapt")
}

android {
    compileSdkVersion(App.compileSdk)
    defaultConfig {
        minSdkVersion(App.minSdk)
        targetSdkVersion(App.targetSdk)
        versionCode = App.versionCode
        versionName = App.versionName
        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

dependencies {
    val implementation by configurations
    val testImplementation by configurations
    val androidTestImplementation by configurations

    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
    implementation(Libs.kotlin_stdlib_jdk8)
    implementation(Libs.appcompat_v7)
    testImplementation(Libs.junit)
    androidTestImplementation(Libs.com_android_support_test_runner)
    androidTestImplementation(Libs.espresso_core)
}
Run Code Online (Sandbox Code Playgroud)

上面的文件在我的根项目中,我只是在功能模块中使用以下内容

apply(rootProject.file("base-android.gradle.kts")) …
Run Code Online (Sandbox Code Playgroud)

gradle kotlin gradle-kotlin-dsl

8
推荐指数
1
解决办法
1708
查看次数

标签 统计

gradle ×1

gradle-kotlin-dsl ×1

kotlin ×1