当我在Android上运行react-native应用程序时,我得到了这个错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-svg:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':react-native-svg: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\Lenovo\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\Lenovo\.gradle\caches\transforms-3\393400499b2af28f59d755a5f301569b\transformed\output\temp\jmod --add-modules java.base --output C:\Users\Lenovo\.gradle\caches\transforms-3\393400499b2af28f59d755a5f301569b\transformed\output\jdkImage --disable-plugin system-modules}

这是我的安卓/build.gradle

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
    }
}

apply plugin: "com.facebook.react.rootproject"

这是我的设置.Gradle

rootProject.name = 'Travls'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

我有"react-native": "^0.73.4"号和buildToolsVersion = "34.0.0"

我已经try 了我在StackOverflow上得到的大部分结果. 在这方面的任何帮助都将受到高度赞赏.

推荐答案

我也面临着同样的问题.将maven添加到android/build.gradle文件中为我解决了这个问题.还要确保安装了准确的NDK.您可以在Android Studio上安装.react native 需要最新版本的JDK 18,因此也要安装该版本,并且必须将其添加到系统路径中.

maven { url 'https://maven.google.com' }

收件人:android/build.gradle

allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        google()
    }
}

React-native相关问答推荐

AWS Amplify处理后端错误

在第二次加载时仅将本机应用程序设置为状态

TextInput 中的大写文本 - react native

React Native 应用程序没有在之前的工作代码中执行任何操作就无法运行

react-native 根据状态隐藏显示按钮

React Native - React Native 架构

Jest 遇到了带有 react-native 的意外令牌

React Native WebView 中的 Javascript console.log()

React-Native:save user preferences

如何在react-native 中加密和解密文本?

文本在 android 中被截断以响应本机

如何在 React Native 中使用断点进行调试

Yarn 在哪里存储离线包?

如何在 React Native 中按住以 Select 文本

React Native STUCK 启动打包器

为什么,确切地说,我们需要 React.forwardRef?

创建新的 react-native 元素时出现Unexpected token import错误

当数据为空时,React-Native FlatList 呈现零状态

如何在样式组件之外获取主题?

使用 React Native 运行 Firebase 3.0 时出错