令人沮丧的是,每次Android Studio建议升级你的Gradle插件时--你确实这么做了--结果却出现了很多问题.

我被建议将Gradle插件从8.2.2升级到8.3,之后应用程序停止构建.

我try 的第一件事,没有效果,是git reset --hard HEAD将所有修改过的配置文件恢复到各自的先前状态,但同样的错误仍然发生.

我的应用已经在build.gradle中使用了minSdkVersion 26,但是只要我能从错误stacktrace中理解问题可能发生在Apache POIApache log4j jar库中,但我不知道如何处理它们,因为它们显然不是我项目的一部分,或者至少不是我直接添加的.

以下是我的错误stacktrack的相关部分:

AGPBI: {"kind":"error","text":"MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26): Lorg/apache/logging/log4j/util/ServiceLoaderUtil;callServiceLoader(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/Class;Ljava/lang/ClassLoader;Z)Ljava/lang/Iterable;","sources":[{"file":"/Users/diego/.gradle/caches/transforms-3/9a05842052291609defaad6cb51ec0bd/transformed/jetified-log4j-api-2.21.1.jar"}],"tool":"D8"}
AGPBI: {"kind":"error","text":"MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26): Lorg/apache/poi/poifs/nio/CleanerUtil;lambda$null$0(Ljava/lang/invoke/MethodHandle;Ljava/nio/ByteBuffer;)Ljava/lang/Throwable;","sources":[{"file":"/Users/diego/.gradle/caches/transforms-3/52819773c62ede0f70c689b16da3da7e/transformed/jetified-poi-5.2.5.jar"}],"tool":"D8"}

更多信息:

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':Services:mergeExtDexDebugAndroidTest'.
> Could not resolve all files for configuration ':Services:debugAndroidTestRuntimeClasspath'.
   > Failed to transform poi-5.2.5.jar (org.apache.poi:poi:5.2.5) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingNoClasspathTransform: /Users/diego/.gradle/caches/transforms-3/52819773c62ede0f70c689b16da3da7e/transformed/jetified-poi-5.2.5.jar.
         > Error while dexing.
           Increase the minSdkVersion to 26 or above.

   > Failed to transform log4j-api-2.21.1.jar (org.apache.logging.log4j:log4j-api:2.21.1) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingNoClasspathTransform: /Users/diego/.gradle/caches/transforms-3/9a05842052291609defaad6cb51ec0bd/transformed/jetified-log4j-api-2.21.1.jar.
         > Error while dexing.
           Increase the minSdkVersion to 26 or above.

这是我的主要模块(APP)build.gradle:

plugins {
    id('dagger.hilt.android.plugin')
    id('com.android.application')
    id('kotlin-android')
    id("com.google.devtools.ksp")
    id('kotlin-kapt')
}

android {
    compileSdk 34
    def code
    Properties versionProps = new Properties()
    def versionPropsFile = file('version.properties')
    if (versionPropsFile.exists())
        versionProps.load(new FileInputStream(versionPropsFile))
    code = (versionProps['VERSION_CODE'] ?: "0").toInteger()+ 1
    packagingOptions {
        resources {
            pickFirsts += ['META-INF/LICENSE.txt']
            excludes += ['META-INF/NOTICE.md', 'META-INF/LICENSE.md', 'META-INF/INDEX.LIST', 'META-INF/DEPENDENCIES', 'META-INF/io.netty.versions.properties']
        }
    }
    versionProps['VERSION_CODE'] = code.toString()
    versionProps.store(versionPropsFile.newWriter(), null)
    defaultConfig {
        applicationId 'com.xxx.xxx'
        minSdkVersion 26
        targetSdkVersion 34
        multiDexEnabled true
        versionCode code
        versionName "5.0." + code
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17

        }
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_17
        }
        vectorDrawables.useSupportLibrary = true
    }
    bundle {
        density {
            // Different APKs are generated for devices with different screen densities; true by default.
            enableSplit true
        }
        abi {
            // Different APKs are generated for devices with different CPU architectures; true by default.
            enableSplit true
        }
        language {
            // This is disabled so that the App Bundle does NOT split the APK for each language.
            // We're gonna use the same APK for all languages.
            enableSplit false
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    project.ext { appName = 'xxx' }
                    def newName = 'xxx.apk'
                    outputFileName = new File("./build/", newName)
                }
            }
        }
        /*debug {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    project.ext { appName = 'xxx' }
                    def newName = 'xxx.apk'
                    outputFileName = new File("./build/", newName)
                }
            }
        }*/
    }
    productFlavors {
    }
    dataBinding{
        enabled = true
    }
    lint {
        abortOnError false
        checkReleaseBuilds false
    }
    namespace 'com.xxx.xxx'
}

dependencies {
    api files('libs/achartengine-1.2.0.jar')
    implementation 'com.facebook.android:facebook-android-sdk:16.3.0'
    //mail API 16
    implementation 'com.sun.mail:android-mail:1.6.7'
    implementation 'com.sun.mail:android-activation:1.6.7'
    //apache commons text
    implementation group: 'org.apache.commons', name: 'commons-text', version: '1.11.0'
    //Youtube player
    implementation 'com.thefinestartist:ytpa:1.2.1'
    //Font Selector List Preference
    //api 'com.vanniktech:vntfontlistpreference:1.0.0'
    //Rate my app
    implementation 'com.github.hotchemi:android-rate:1.0.1'
    //Support
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.preference:preference-ktx:1.2.1'
    implementation 'androidx.appcompat:appcompat:1.7.0-alpha03'
    implementation 'androidx.activity:activity-ktx:1.8.2'
    implementation 'androidx.fragment:fragment-ktx:1.6.2'
    runtimeOnly('androidx.activity:activity-compose:1.8.2')
    implementation 'androidx.fragment:fragment-ktx:1.6.2'
    //Annotation
    implementation 'androidx.annotation:annotation:1.7.1'
    //AlertDialog
    implementation 'com.github.d-max:spots-dialog:1.1@aar'
    //glide animated gifs
    implementation 'com.github.bumptech.glide:glide:4.16.0'
    implementation 'androidx.window:window:1.3.0-alpha02'
    ksp 'com.github.bumptech.glide:ksp:4.16.0'
    //circular score
    implementation 'com.wssholmes.stark:circular-score:0.1.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'com.github.mejdi14:Flat-Dialog-Android:1.0.5'
    //picasso
    implementation 'com.squareup.picasso:picasso:2.71828'
    //Stream
    implementation 'com.annimon:stream:1.2.2'
    //Multidex
    implementation "androidx.multidex:multidex:2.0.1"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    //Hilt
    implementation 'com.google.dagger:hilt-android:2.50'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
    kapt 'com.google.dagger:hilt-android-compiler:2.50'
    kapt('org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.9.0')
    kapt 'androidx.hilt:hilt-compiler:1.1.0'
    //modelmapper
    implementation 'org.modelmapper:modelmapper:3.2.0'
    //volley
    implementation 'com.android.volley:volley:1.2.1'
    //openai
    implementation 'com.aallam.openai:openai-client:3.7.0'
    implementation('io.ktor:ktor-client-android:2.3.8')
    implementation platform('com.aallam.openai:openai-client-bom:3.7.0')
    //glide animated gifs
    implementation 'com.github.bumptech.glide:glide:4.16.0'
    //audio visualizer
    implementation('io.github.gautamchibde:audiovisualizer:2.2.7')
    //jsoup
    implementation 'org.jsoup:jsoup:1.17.2'
    //moshi
    implementation('com.squareup.moshi:moshi:1.15.1')
    ksp('com.squareup.moshi:moshi-kotlin:1.15.1')
    ksp('com.squareup.moshi:moshi-kotlin-codegen:1.15.1')

    implementation project(':DTO')
    implementation project(':Common')
    implementation project(':Background')
    implementation project(':Core')
    implementation project(':Services')
}

我不知道这是否相关,但在升级Gradle之前,我将Android Studio升级到了Iguana | 2023.2.1

有关于如何让我的应用重新构建的帮助吗?

推荐答案

考虑到在执行:Services:mergeExtDexDebugAndroidTest任务时构建失败,那么很可能Services模块的build.gradle确实具有低于26的minSdkVersion.

请确保所有其他模块的minSdk大于(或等于)26.

Android相关问答推荐

房间打开创建回调java.nio.channels. OverlappingFilLockResponse

Android:MethodHandle. invoke和MethodHandle. invokeExact仅从Android O( - min—api 26)开始支持

Jetpack Compose中的导航找不到NavHost类的名称为:startDestination";的参数

两首合成曲的喷气背包动画

在Jetpack Compose中的隐藏状态栏后面绘制

Kotlin Android VS Kotlin多平台

我想使用代码自动重命名我的Android存储中的文件夹

为什么我有多个Player实例?

Android从已连接的设备获得GATT

从片段导航回来

如何显示具体的商品数量?

当提供非状态对象时,compose 如何进行重组

Gradle在我的Android Compose项目中继续推广依赖版本

如何仅同步 local_manifest.xml?

具有数据库和升级潜力的移动应用程序开发(Android)供朋友使用

如何从包装在泛型中的 retrofit 调用中检索密钥?

Visual Studio 无法在 Android 上编译 .NET MAUI 项目

在 Jetpack Compose 中自动滚动后面的项目

将房间中的实体更新为 isCompleted 并使用 Flow 问题获取所有数据

新的内部测试应用程序版本不适用于测试人员,即使它说它们是