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

Expo构建React Native应用启动闪退,开发构建遇jlink执行错误

问题:Expo构建React Native应用安装后启动崩溃,开发构建模式下JDK编译错误

问题详情

我是React Native新手,使用Expo开发移动端应用。通过eas build构建应用时过程正常,但将APK安装到手机后,应用在启动页停止运行。切换到开发构建模式后,出现以下编译错误:

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':react-native-community_slider:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':react-native-community_slider:androidJdkImage'.
   > Failed to transform core-for-system-modules.jar to match 
attributes {artifactType=_internal_android_jdk_image, 
org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JdkImageTransform: 
C:\Users\thara\AppData\Local\Android\sdk\platforms\android-34\core-
for-system-modules.jar.
         > Error while executing process C:\Program Files\Java\jdk-21\bin\jlink.exe with arguments {--module-path C:\Users\thara\.gradle\
caches\transforms-
3\89db9bcd56ab5312cc04ec9440ec4d21\transformed\output\temp\jmod --add-
modules java.base --output C:\Users\thara\.gradle\caches\transforms-3\89db9bcd56ab5312cc04ec9440ec4d21\transformed\output\jdkImage --
disable-plugin system-modules}

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

已尝试的无效方法

  • 修改根目录android/build.gradle中的minSdkVersion为21
  • 删除build文件后重新执行npx expo build:android

相关配置文件

android/app/build.gradle

android {
    ndkVersion rootProject.ext.ndkVersion

    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace 'com.tharanga_sandun.MonkeyRepellent'
    defaultConfig {
        applicationId 'com.tharanga_sandun.MonkeyRepellent'
        minSdkVersion rootProject.ext.minSdkVersion
        multiDexEnabled true
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0.0"

        buildConfigField("boolean", "REACT_NATIVE_UNSTABLE_USE_RUNTIME_SCHEDULER_ALWAYS", (findProperty("reactNative.unstable_useRuntimeSchedulerAlways") ?: true).toString())
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            signingConfig signingConfigs.debug
            shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    packagingOptions {
        jniLibs {
            useLegacyPackaging (findProperty('expo.useLegacyPackaging')?.toBoolean() ?: false)
        }
    }
}

// Apply static values from `gradle.properties` to the `android.packagingOptions`
// Accepts values in comma delimited lists, example:
// android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
    // Split option: 'foo,bar' -> ['foo', 'bar']
    def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
    // Trim all elements in place.
    for (i in 0..<options.size()) options[i] = options[i].trim();
    // `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
    options -= ""

    if (options.length > 0) {
        println "android.packagingOptions.$prop += $options ($options.length)"
        // Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
        options.each {
            android.packagingOptions[prop] += it
        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation 'com.android.support:multidex:1.0.3'
    implementation("com.facebook.react:react-android")

    def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";;
    def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";;
    def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";;

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0'
        minSdkVersion = 21
        compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '34')
        targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '34')
        kotlinVersion = findProperty('android.kotlinVersion') ?: '1.8.10'

        ndkVersion = "25.1.8937393"
        
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle')
        classpath('com.facebook.react:react-native-gradle-plugin')
    }
}

解决方案

错误根源是JDK 21与Android Gradle Plugin、react-native-community/slider库的兼容性问题,以下是可行修复步骤:

  1. 降级JDK到17版本
    Android Gradle Plugin 8.x(对应compileSdk 34)官方推荐使用JDK 17,JDK 21存在未适配的问题:

    • 下载安装OpenJDK 17
    • 配置系统环境变量JAVA_HOME指向JDK17安装路径,执行java -version确认版本为17.x
  2. 清理Gradle缓存与项目构建文件

    • Windows:执行gradlew clean,然后删除C:\Users\thara\.gradle\caches文件夹
    • macOS/Linux:执行./gradlew clean && rm -rf ~/.gradle/caches
  3. 更新或替换react-native-community/slider库

    • 检查package.json中该库版本,更新到与当前React Native/Expo版本兼容的最新版
    • 若旧版本仍有问题,替换为官方维护分支@react-native-slider/slider,执行npm uninstall @react-native-community/slider && npm install @react-native-slider/slider
  4. 验证Android SDK完整性
    打开Android Studio SDK Manager,确保安装了:

    • Android 34的SDK Platform
    • Build Tools 34.0.0
    • 对应系统镜像(若使用模拟器测试)
  5. 重新构建项目
    执行以下命令重置并构建:

    npx expo prebuild --clean
    npx expo run:android
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 02:36:00