Error adding `androidResources` no compress option to Android Library Gradle

huangapple go评论94阅读模式
英文:

Error adding `androidResources` no compress option to Android Library Gradle

问题

我正在尝试将以下选项添加到我的 gradle.kts 文件中,用于 Android 库项目:

android {
    androidResources {
        noCompress += "tflite"
    }
}

但不知何故,每当我尝试同步项目时,我会收到以下错误信息:

> * 出现了什么问题:
class com.android.build.gradle.internal.dsl.AaptOptions$AgpDecorated_Decorated 无法转换为 com.android.build.api.dsl.LibraryAndroidResources(com.android.build.gradle.internal.dsl.AaptOptions$AgpDecorated_Decorated 和 com.android.build.api.dsl.LibraryAndroidResources 在 org.gradle.internal.classloader.VisitableURLClassLoader @481a697b 的未命名模块中)。 

有人知道如何解决这个问题吗?互联网上似乎没有相关信息。

像这样使用已弃用的旧版本不会产生任何错误:

```kotlin
aaptOptions {
    noCompress += "tflite"
}

我正在使用 Android Gradle 插件 8.1.0-beta05,Gradle Wrapper 版本 8.0,但在 AGP 8.1.0-beta04 版本上也出现了相同的问题。

这是 gradle.kts 文件的内容:

@Suppress("DSL_SCOPE_VIOLATION") // TODO: 移除一旦 KTIJ-19369 问题得到解决
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 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"
    }
}

答案1

得分: 2

我遇到了同样的问题并报告了它。似乎在新版本中已修复。
https://issuetracker.google.com/issues/294771624

修复已合并到8.1.2、8.2.0-beta03和8.3.0-alpha02中。

感谢您在我们的工程团队努力解决此问题期间的耐心等待。此问题的修复现在在以下版本中可用:
Android Studio Hedgehog | 2023.1.1 Beta 3。
Android Gradle Plugin 8.2.0-beta03。

英文:

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

答案2

得分: 1

It worked with me

 aaptOptions {
        noCompress  += "tflite"
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

<details>
<summary>英文:</summary>

It worked with me

aaptOptions {
noCompress += "tflite"
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!.scc:.:!CVS:!thumbs.db:!picasa.ini:!*~"
}

答案3

得分: 0

尝试最新更新和此问题的修复已提供:

  • Android Studio Hedgehog | 2023.1.1 Beta 3

  • Android Gradle Plugin 8.2.0-beta03

因此,请使用最新的更新。

英文:

Try the latest update and A fix for this issue is available in:

  • Android Studio Hedgehog | 2023.1.1 Beta 3

  • Android Gradle Plugin 8.2.0-beta03

So use latest updates

huangapple
  • 本文由 发表于 2023年6月13日 05:51:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76460539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定