我是应用程序开发的新手。首先我发现我需要在“”而不是"“中使用Gradle,就像在大多数视频//和我访问过的地方一样,不知道为什么。
我试图使kapt或ksp工作,但找不到一种方法来做到这一点。
Ksp
在android网站https://developer.android.com/build/migrate-to-ksp中尝试过
应用Gradle
android {
namespace = "com.example.myapplication"
compileSdk = 33
defaultConfig {
applicationId = "com.example.myapplication"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
ksp("androidx.room:room-compiler:2.5.0")
implementation("com.google.android.material:material:1.10.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
字符串
线ksp("androidx.room:room-compiler:2.5.0")
错误Unresolved reference: ksp (ksp highlaited in red)
Gradle项目
plugins {
id("com.android.application") version "8.1.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.google.devtools.ksp")
}
型
错误
例外情况是:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.devtools.ksp']
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
型
卡普特
android
//apply plugin: 'kotlin-kapt'
// (shows error: Expecting an element)
// kapt "androidx.room:room-compiler:2.4.2"
// Kept highlated in red
型
应用Gradle
plugins
id 'org.jetbrains.kotlin.kapt'
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp") version "1.8.10-1.0.9" apply false
id("org.jetbrains.kotlin.kapt")
}
android {
namespace = "com.example.myapplication"
compileSdk = 33
defaultConfig {
applicationId = "com.example.myapplication"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
apply plugin: 'kotlin-kapt'
dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation ("androidx.room:room-runtime:2.4.2")
implementation ("androidx.room:room-ktx:2.4.2")
kapt "androidx.room:room-compiler:2.4.2"
("androidx.room:room-compiler:2.5.0")
implementation("com.google.android.material:material:1.10.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
型
1条答案
按热度按时间4jb9z9bj1#
Gradle在插件版本4.0中增加了对Kotlin的支持,以取代Groovy -https://developer.android.com/build/migrate-to-kotlin-dsl
用引号,你是指:
**字符串的双引号:**Groovy允许使用单引号定义字符串,而Kotlin需要双引号。
类似情况适用于Kapt到KSP:https://developer.android.com/build/migrate-to-ksp
编辑:
至于ksp/kapt,我不太确定,但在我的工作项目(库,但它应该是相同的):
顶层构建.gradle:
字符串
模块特定build.gradle:
型