You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AndroidX迁移后Jetifier转换失败问题求助

问题:AndroidX项目Jetifier转换失败+Java版本兼容问题

问题背景

我有三个Android项目版本v4、v6、v7,将IDE从ArcticFox升级到Giraffe后项目出现异常,卸载重装ArcticFox后,v4、v6能正常运行,但采用AndroidX替代AppCompat库的v7版本无法启动。

报错信息

Jetifier转换失败报错

Failed to transform 'C:\Users\mattheww.gradle\caches\modules-2\files-2.1\androidx.activity\activity\1.6.0\4bee9777c02790cb99e68cd397036b1d5508a630\activity-1.6.0.aar' using Jetifier. Reason: null. (Run with --stacktrace for more details.) To disable Jetifier, set android.enableJetifier=false in your gradle.properties file.

升级Gradle后的Java版本不兼容报错

  • Exception is:
    org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
    ...
    Caused by: java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    ...

已尝试操作

  • 修改gradle.properties中android.enableJetifier为false,并在manifest标签添加tools:replace="android:appComponentFactory"
  • 确认项目无AppCompat库引用
  • 执行gradlew clean :app:processDebugResources,仍出现多个Jetifier转换失败报错
  • 将Gradle工具版本升级到8.1.1后,触发Java版本不兼容错误

当前项目配置

gradle.properties中已设置:

android.enableJetifier=true
android.useAndroidX=true

未引入classpath 'io.fabric.tools:gradle:1.25.1'

项目app模块build.gradle代码

apply plugin: 'com.android.application'

android {
    compileSdkVersion 31
    buildToolsVersion '28.0.3'


    useLibrary 'org.apache.http.legacy'

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }

    defaultConfig {
        applicationId "xxxxxxxx.xxxxxxx.rr3"
        minSdkVersion 24
        targetSdkVersion 31
        versionName "7.0"
        setProperty("archivesBaseName", "RR7v$versionName" + "DEV")
        multiDexEnabled true

    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            multiDexKeepProguard file('multidex-config.pro')
        }
    }
}

dependencies {
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'

    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    //compile files('libs/core.jar')
    compile files('libs/mail.jar')
    compile files('libs/ndeftools-1.2.3.jar')




    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'com.google.android.gms:play-services-base:16.0.1'

    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.4'


    implementation 'joda-time:joda-time:2.1'
    implementation 'net.zetetic:android-database-sqlcipher:4.5.4@aar'

    implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'

    implementation 'com.android.volley:volley:1.1.0'



    implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
    implementation 'com.google.zxing:core:3.3.0'

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.github.florent37:singledateandtimepicker:2.1.4' //https://github.com/florent37/SingleDateAndTimePicker
    implementation 'androidx.drawerlayout:drawerlayout:1.0.0'
    implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'


}


apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

可行解决办法

1. 清理Gradle缓存并刷新依赖

  • 删除本地Gradle缓存目录:C:\Users\mattheww\.gradle\caches
  • 执行命令gradlew clean build --refresh-dependencies强制刷新所有依赖

2. 匹配Gradle、AGP与Java版本

ArcticFox兼容的Android Gradle Plugin(AGP)版本为7.0.x-7.4.x,对应Java 11版本,调整步骤:

  • 修改项目根目录build.gradle中的AGP版本:
    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.0.4'
            classpath 'com.google.gms:google-services:4.3.10' // 适配现有firebase版本
        }
    }
    
  • 在Android Studio中打开File > Project Structure > SDK Location,将JDK location设置为Android Studio自带的Java 11(路径一般为C:\Program Files\Android\Android Studio\jbr)

3. 替换遗留Support库依赖

将com.android.support:multidex:1.0.3替换为AndroidX版本:

implementation 'androidx.multidex:multidex:2.0.1'

4. 修复Jetifier冲突

保持android.enableJetifier=true,同时升级androidx.activity版本:

implementation 'androidx.activity:activity:1.7.2'

或在gradle.properties中添加黑名单规则:

android.jetifier.blacklist=activity-1.6.0.aar

5. 替换本地jar包为AndroidX兼容版本

将邮件相关的本地jar包替换为官方AndroidX兼容依赖:

implementation 'com.sun.mail:android-mail:1.6.7'
implementation 'com.sun.mail:android-activation:1.6.7'

内容的提问来源于stack exchange,提问作者turtleboy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 22:24:51