I am trying to add the following option to my gradle.kts file for an Android Library
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
This is the gradle.kts file:
@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
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