I am trying to add the following option to my gradle.kts file for an Android Library
我正在尝试为Android库添加以下选项到我的gradle.kts文件中
android{
androidResources {
noCompress += "tflite"
}
}
But for some reason, whenever i try to Sync the project, I get this error
但由于某种原因,每当我试图同步项目,我得到这个错误
- What went wrong:
class com.android.build.gradle.internal.dsl.AaptOptions$AgpDecorated_Decorated cannot be cast to class com.android.build.api.dsl.LibraryAndroidResources (com.android.build.gradle.internal.dsl.AaptOptions$AgpDecorated_Decorated and com.android.build.api.dsl.LibraryAndroidResources are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @481a697b)
Anyone have any ideea how can i fix this? Internet seems to be of no use here.
有没有人知道我怎么才能解决这个问题?互联网似乎在这里毫无用处。
Using the deprecated, older, version like this does not produce any error
使用不推荐使用的旧版本不会产生任何错误
aaptOptions{
noCompress += "tflite"
}
I am using Android Gradle Plugin 8.1.0-beta05, with gradle wrapper 8.0, but behaved the same with AGP 8.1.0-beta04
我使用的是Android Gradle插件8.1.0-Beta05,带有Gradle包装器8.0,但在AGP 8.1.0-Beta04上表现相同
This is the gradle.kts file:
这是gradle.kts文件:
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
}
android {
namespace = "com.example.mylibrary"
compileSdk = 33
defaultConfig {
minSdk = 26
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs = listOf("-Xcontext-receivers", "-Xexplicit-api=warning")
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}
packaging {
resources.excludes.add("META-INF/notice.txt")
}
androidResources {
noCompress += "tflite"
}
}
更多回答
优秀答案推荐
I had the same problem and reported it. It seems to be fixed in the new version.
https://issuetracker.google.com/issues/294771624
我遇到了同样的问题,并报告了它。它似乎在新版本中得到了修复。https://issuetracker.google.com/issues/294771624
Fix is merged for 8.1.2, 8.2.0-beta03 and 8.3.0-alpha02
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
Android Studio Hedgehog | 2023.1.1 Beta 3.
Android Gradle Plugin 8.2.0-beta03
It worked with me
这对我很管用
aaptOptions {
noCompress += "tflite"
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
Try the latest update and A fix for this issue is available in:
尝试最新更新,此问题的修复程序可在以下站点找到:
Android Studio Hedgehog | 2023.1.1 Beta 3
Android Studio Hedgehog|2023.1.1 Beta 3
Android Gradle Plugin 8.2.0-beta03
Android Gradle插件8.2.0-Beta03
So use latest updates
所以请使用最新的更新
更多回答
我是一名优秀的程序员,十分优秀!