You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

build.gradle转build.gradle.kts后Gradle同步失败,遇Unresolved reference错误

问题及解决方案

错误详情

  1. 同步时提示Unresolved reference: android和Unresolved reference: compileSdkVersion,触发ScriptCompilationException
  2. signingConfigs中的register方法报错:接收器类型不匹配,无适用的重载方法

修正后的完整build.gradle.kts代码

plugins {
    id("com.android.application")
    id("com.google.firebase.crashlytics")
    id("kotlin-android")
    id("kotlin-kapt")
    id("com.google.gms.google-services")
    id("com.google.firebase.appdistribution")
    id("org.sonarqube")
}

apply(from = "buildsystem/api.gradle")
apply(from = "../buildtype.gradle")

android {
    // 升级前请确认副作用
    compileSdk = 33

    defaultConfig {
        applicationId = "com.tinkerventures.prnondemand"
        minSdk = 21
        targetSdk = 33 // 升级前请确认副作用
        versionCode = 94
        versionName = "0.0.94" // MAJOR.MINOR.PATCH
        testInstrumentationRunner = "androidx.layout_base_toolbar.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
        multiDexEnabled = true
    }

    buildFeatures {
        viewBinding = true
    }

    signingConfigs {
        create("releaseConfig") {
            storeFile = file("keystore.jks")
            storePassword = "prn_11"
            keyAlias = "prn_on_demand"
            keyPassword = "prn_11"
        }
    }

    lintOptions {
        checkReleaseBuilds = false
        // 或者保留发布构建检查,但即使有错误也继续构建
        isAbortOnError = false
    }

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

dependencies {
    implementation(project(":openCVLibrary"))
    implementation(project(":common"))

    val androidX = "1.3.0"
    val retrofit = "2.9.0"
    val retroConverter = "2.9.0"
    val glide = "4.12.0"
    val lifecycle = "2.2.0"
    val butterKnife = "10.2.1"
    val SDP = "1.0.6"
    val permission = "2.2.2"
    val room = "2.3.0"
    val playServices = "18.1.0"
    val locationServices = "19.0.0"
    val multidex_version = "2.0.1"
    val kotlin_version = "1.8.0" // 根据项目实际版本调整

    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

    implementation("androidx.work:work-runtime:2.7.1")
    implementation("androidx.work:work-runtime-ktx:2.7.1")

    implementation("androidx.appcompat:appcompat:$androidX")
    implementation("androidx.core:core-ktx:1.7.0-alpha01")
    implementation("androidx.constraintlayout:constraintlayout:2.1.0")
    implementation("com.google.android.material:material:1.4.0")
    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
    implementation("androidx.lifecycle:lifecycle-extensions:$lifecycle")
    implementation("androidx.room:room-runtime:$room")

    implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")

    implementation("com.google.android.play:core:1.10.3")

    implementation(platform("com.google.firebase:firebase-bom:31.1.1"))
    implementation("com.google.firebase:firebase-crashlytics")
    implementation("com.google.firebase:firebase-messaging")
    implementation("com.google.firebase:firebase-auth-ktx")
    implementation("com.google.firebase:firebase-database")
    implementation("com.google.firebase:firebase-dynamic-links-ktx")
    implementation("com.google.firebase:firebase-analytics") {
        exclude(module = "play-services-ads-identifier")
    }

    // GMS
    implementation("com.google.android.libraries.places:places:3.0.0")

    implementation("com.google.firebase:firebase-messaging-ktx:23.1.1")

    implementation("com.google.android.gms:play-services-base:18.1.0")
    implementation("com.google.android.gms:play-services-basement:18.1.0")
    implementation("com.google.android.gms:play-services-gcm:17.0.0")
    implementation("com.google.android.gms:play-services-tasks:18.0.2")
    implementation("com.google.android.libraries.maps:maps:3.1.0-beta")
    // Maps SDK工具类
    implementation("com.google.maps.android:android-maps-utils:2.4.0")
    implementation("com.google.auto.value:auto-value-annotations:1.8.2")
    implementation("com.google.code.gson:gson:2.8.9")

    annotationProcessor("androidx.room:room-compiler:$room")
    implementation("androidx.multidex:multidex:$multidex_version")
    implementation("androidx.browser:browser:1.4.0")

    implementation("com.google.android.gms:play-services-location:$locationServices")
    implementation("com.google.android.gms:play-services-maps:$playServices")
    implementation("com.google.android.gms:play-services-auth:20.4.0")

    /* Retrofit相关依赖 */
    implementation("com.squareup.retrofit2:retrofit:$retrofit")
    implementation("com.squareup.retrofit2:converter-gson:$retroConverter")

    implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.1"))
    implementation("com.squareup.okhttp3:okhttp")
    implementation("com.squareup.okhttp3:logging-interceptor")

    implementation("com.squareup.retrofit2:adapter-rxjava2:$retrofit")

    annotationProcessor("androidx.annotation:annotation:1.2.0")

    implementation("com.github.bumptech.glide:glide:4.12.0")
    annotationProcessor("com.github.bumptech.glide:compiler:4.12.0")
    kapt("com.github.bumptech.glide:compiler:4.12.0")

    /* Butter Knife相关依赖 */
    implementation("com.jakewharton:butterknife:$butterKnife")
    kapt("com.jakewharton:butterknife-compiler:$butterKnife")

    /* SDP & SSP相关依赖 */
    implementation("com.intuit.sdp:sdp-android:$SDP")
    implementation("com.intuit.ssp:ssp-android:$SDP")

    /* TED Permission相关依赖 */
    implementation("gun0912.ted:tedpermission:$permission")
    implementation("com.afollestad.material-dialogs:commons:0.9.6.0")
    implementation("com.romandanylyk:pageindicatorview:1.0.3")
    implementation("com.gmail.samehadar:iosdialog:1.0")

    implementation("com.scottyab:secure-preferences-lib:0.1.7")

    implementation("com.github.florent37:SingleDateAndTimePicker:2.2.5")
    implementation("com.github.stoyicker:aligningrecyclerview:1.0")

    implementation("me.leolin:ShortcutBadger:1.1.22@aar")
    implementation("com.github.delight-im:Android-AdvancedWebView:v3.0.0")

    implementation("com.github.mukeshsolanki:android-otpview-pinview:2.1.2")
    implementation("com.github.bluejamesbond:textjustify-android:2.1.6")

    /** 文档扫描相关 */
    implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
    implementation("com.github.mayuce:AndroidDocumentScanner:1.5.3")

    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")

    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0")

    implementation("com.github.yalantis:ucrop:2.2.2")

    /* 测试相关依赖 */
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test:runner:1.4.0")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
    androidTestImplementation("androidx.test:rules:1.4.0")
}

关键修正点说明

  1. 修复Unresolved reference: android

    • 移除无效的apply(plugin = "android"),com.android.application已包含Android插件核心功能
    • 移除过时的kotlin-android-extensions插件(该插件已废弃,项目已用viewBinding替代)
    • 改用plugins块加载插件,确保Android插件优先加载,语法更规范
    • 将compileSdkVersion(33)、minSdkVersion(21)等改为Kotlin DSL新语法compileSdk = 33、minSdk = 21
  2. 修复signingConfigs的register报错

    • Kotlin DSL中,signingConfigs创建配置的方法是create("releaseConfig"),register是TaskContainer的方法,不适用于签名配置
  3. 其他语法修正

    • 项目依赖路径修正:project(path = " =openCVLibrary")改为project(":openCVLibrary"),移除多余空格和等号
    • 修正annotationProcessor "androidx.annotation:annotation:1.2.0"为括号形式,符合Kotlin DSL语法
    • 显式定义kotlin_version,确保依赖版本匹配(可根据项目实际Kotlin版本调整)

内容的提问来源于stack exchange,提问作者Usman Saeed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 22:47:01