嗨,我在运行项目时遇到错误,我实际上已经更新了 gradle 和 gradle 插件版本,并且收到此错误
你能建议我在这里做错了什么吗
Task 'prepareKotlinBuildScriptModel' not found in project ':core'.
我已经将其添加到我的 gradle 文件中
tasks.register("prepareKotlinBuildScriptModel"){}
将此添加到插件部分
id("com.android.application") version "7.1.1"
设置。梯度
pluginId.startsWith("com.android") -> useModule("com.android.tools.build:gradle:7.2.0")
项目级别build.gradle
buildscript {
val kotlinVersion by extra("1.5.21")
dependencies {
"classpath"("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("com.android.tools.build:gradle:7.2.0")
}
}
我在 build.gradle.kts 旁边注意到一件事 - 模块版本 -
Module: app-android-core.unitTest
我没有看到核心的模块版本,也不知道为什么会发生这种情况。这就是里面的东西
import com.android.build.gradle.api.ApkVariant
import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.BaseVariantOutput
import com.android.build.gradle.api.TestVariant
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import java.io.FileInputStream
import java.util.*
plugins {
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
id("kotlinx-serialization")
// Needed for Firebase
id("com.google.gms.google-services")
// Needed for Crashlytics
id("com.google.firebase.crashlytics")
id("com.android.application") version "7.1.1"
}
// Load the signing info from the keystore.properties file
// (see https://developer.android.com/studio/publish/app-signing.html)
val keystorePropFile = rootProject.file("core/keystore.properties")
val keystoreProp = Properties()
keystoreProp.load(FileInputStream(keystorePropFile))
val securePropFile = rootProject.file("core/secure.properties")
val secureProp = Properties()
secureProp.load(FileInputStream(securePropFile))
android {
compileSdk = 31
buildToolsVersion = "30.0.3"
buildFeatures {
dataBinding = true
viewBinding = true
}
tasks.register("prepareKotlinBuildScriptModel"){}
defaultConfig {
applicationId = "io.xxxx.android"
manifestPlaceholders["MapAPIKey"] = secureProp.getProperty("MAPS_API_KEY")
minSdk = 23
targetSdk = 30
// Only get the FirebaseUI translations relevant to our app
// (see https://github.com/firebase/FirebaseUI-Android/tree/master/auth)
resourceConfigurations += "en"
// Export the local DB schema to the dbSchemas dir
// (see https://developer.android.com/training/data-storage/room/migrating-db-versions.html)
javaCompileOptions {
annotationProcessorOptions {
arguments += mapOf("room.schemaLocation" to "$projectDir/dbSchemas")
}
}
kotlinOptions {
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
// Clear the app's state between tests
testInstrumentationRunnerArguments += mapOf("clearPackageData" to "true")
}
sourceSets {
all {
java.srcDir("src/$name/kotlin")
}
getByName("androidTest") {
// Add the DB schemas dir as a test asset so we can test DB migrations
// (see https://developer.android.com/training/data-storage/room/migrating-db-versions.html)
assets.srcDir(files("$projectDir/dbSchemas"))
}
}
val debug = "debug"
val release = "release"
signingConfigs {
create(release) {
keyAlias = keystoreProp["keyAlias"] as? String
keyPassword = keystoreProp["keyPassword"] as? String
storeFile = file(keystoreProp["storeFile"]!!)
storePassword = keystoreProp["storePassword"] as? String
}
}
buildTypes {
getByName(debug) {
// We use the "version name suffix" instead of the "application ID suffix" so that we don't have to create
// multiple apps in Firebase
versionNameSuffix = "-$debug"
}
getByName(release) {
signingConfig = signingConfigs[release]
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), file("proguard-rules.pro"))
}
}
flavorDimensions("brand", "type", "server")
// We add different app ID suffix so we don't install different flavors overriding others, which might lead to
// data issues in the device and unpredictable errors
productFlavors {
}
applicationVariants.all {
}
applicationVariants.all(object : Action<ApplicationVariant> {
})
testVariants.all(object : Action<TestVariant> {
override fun execute(variant: TestVariant) {
renameApk(apkVariant = variant)
}
})
// Enable the Test Orchestrator (see https://developer.android.com/training/testing/junit-runner.html#using-android-test-orchestrator)
testOptions { execution = "ANDROIDX_TEST_ORCHESTRATOR" }
// Run instrumented tests on the release build
// testBuildType = release
// This fixes a compilation error caused by adding Coroutines lib twice (see https://github.com/Kotlin/kotlinx.coroutines/issues/1064)
// TODO: Remove when this is no longer happening
packagingOptions { exclude("META-INF/*") }
lintOptions { isAbortOnError = false }
dynamicFeatures += mutableSetOf()
}
/**
* Renames the APK generated for the [apkVariant] received.
*/
fun renameApk(apkVariant: ApkVariant) {
apkVariant.outputs.all(object : Action<BaseVariantOutput> {
override fun execute(output: BaseVariantOutput) {
(output as BaseVariantOutputImpl).outputFileName =
"${apkVariant.name}-${apkVariant.versionName?.replace("-debug","")}.apk"
}
})
}
// Necessary to use Kotlin experimental features, such as @Parcelize
androidExtensions {
isExperimental = true
}
dependencies {
implementation(kotlin("stdlib-jdk7"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2")
// Used to trigger a restart programmatically
implementation ("com.jakewharton:process-phoenix:2.1.2")
// Chatbot feature
implementation(project(":chatbot"))
// See https://developer.android.com/jetpack/androidx/releases
implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("androidx.collection:collection-ktx:1.2.0")
implementation("androidx.fragment:fragment-ktx:1.4.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.4.0")
implementation("com.google.android.gms:play-services-maps:18.0.0")
kapt("android.arch.lifecycle:common-java8:1.1.1")
implementation("androidx.room:room-ktx:2.3.0")
kapt("androidx.room:room-compiler:2.3.0")
implementation("androidx.annotation:annotation:1.3.0")
implementation("androidx.cardview:cardview:1.0.0")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.2")
implementation("androidx.drawerlayout:drawerlayout:1.1.1")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.21")
implementation("androidx.paging:paging-runtime:3.1.0")
implementation("com.google.android.material:material:1.4.0")
// Used to manage preferences
implementation("androidx.preference:preference-ktx:1.1.1")
// Used to send HTTP requests
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0") {
// Avoid duplicated import of Gson
exclude(group = "com.google.code.gson", module = "gson")
}
// Necessary to parse responses as strings (used in HttpService)
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
// Used to log requests and responses in Retrofit (for debug builds)
debugImplementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
// Used to send HTTP requests in xxxx-common
implementation("com.squareup.okhttp3:okhttp:4.9.1")
// Used to communicate with WebSockets
implementation("com.github.tinder.scarlet:scarlet:0.2.4")
implementation("com.github.tinder.scarlet:scarlet-protocol-websocket-okhttp:0.2.4")
implementation("com.github.tinder.scarlet:scarlet-stream-adapter-coroutines:0.2.4")
implementation("com.github.tinder.scarlet:scarlet-message-adapter-gson:0.2.4")
implementation("com.github.tinder.scarlet:scarlet-lifecycle-android:0.2.4") {
// Exclude this module to avoid a minify compilation issue (see https://github.com/Tinder/Scarlet/issues/59)
exclude(group = "com.github.tinder", module = "scarlet")
}
// Used for crashes with Firebase
implementation("com.google.firebase:firebase-crashlytics:18.2.5")
// Used for sending feedback
implementation("com.instabug.library:instabug:10.4.1")
// Necessary to add network logs to Instabug reports
implementation("com.instabug.library:instabug-with-okhttp-interceptor:10.4.1")
// Used for authentication with Firebase
implementation("com.firebaseui:firebase-ui-auth:7.0.0")
// Necessary for Facebook sign in (see https://github.com/facebook/facebook-android-sdk/blob/master/CHANGELOG.md)
implementation("com.facebook.android:facebook-login:12.0.0")
// Used for analytics
implementation("com.google.firebase:firebase-analytics:20.0.0")
// Used for tracking user interactions
implementation("com.uxcam:uxcam:3.3.0@aar")
// Used for receiving push messages
implementation("com.google.firebase:firebase-messaging:23.0.0")
// Used to get remote configuration from Firebase (e.g., for force update)
implementation("com.google.firebase:firebase-config-ktx:21.0.1")
// Used for dynamic links
implementation("com.google.firebase:firebase-dynamic-links-ktx:21.0.0")
// Used for reading QR codes
implementation("com.google.android.gms:play-services-vision:20.1.3")
// Used to easily run tasks in the background
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
// Needed to use java.time-like APIs for date and time (see https://github.com/JakeWharton/ThreeTenABP)
implementation("com.jakewharton.threetenabp:threetenabp:1.2.2")
// Used to load images from URLs
implementation("com.squareup.picasso:picasso:2.71828")
// Used to show tool tips
implementation("com.github.skydoves:balloon:1.3.3")
// Used for creating charts
implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
// Used fore creating custom DatePicker / TimePicker dialogs (see https://github.com/wdullaer/MaterialDateTimePicker/releases)
implementation("com.wdullaer:materialdatetimepicker:4.2.3")
// Used for DI, to make classes configurable for automated tests
implementation("com.google.dagger:dagger-android-support:2.28.1")
kapt("com.google.dagger:dagger-compiler:2.28.1")
kapt("com.google.dagger:dagger-android-processor:2.26")
// Used for payments
implementation("com.stripe:stripe-android:16.3.0")
// Test libs
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito:mockito-core:3.3.0")
testImplementation("io.mockk:mockk:1.9.3")
testImplementation("org.hamcrest:hamcrest-library:2.2")
testImplementation("androidx.room:room-testing:2.3.0")
testImplementation("com.jraska.livedata:testing-ktx:1.1.2")
testImplementation("android.arch.core:core-testing:1.1.1")
testImplementation("com.squareup.okhttp3:mockwebserver:4.4.1")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.3")
androidTestImplementation("androidx.arch.core:core-testing:2.1.0")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test:rules:1.4.0")
androidTestImplementation("androidx.test:runner:1.4.0")
androidTestUtil("androidx.test:orchestrator:1.4.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
androidTestImplementation("androidx.test.espresso:espresso-contrib:3.4.0")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.4.0")
androidTestImplementation("androidx.test.espresso:espresso-idling-resource:3.4.0")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
}
项目结构如下
我也面临同样的问题,但我通过在 build.gradle(:app) 中添加以下代码解决了该问题
task prepareKotlinBuildScriptModel {
}