react-nativebuild.gradlereact-native-svg

Adding react-native-svg gives error - FAILURE: Build failed with an exception


When trying to run react-native app on android, I get this error:

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}

Here's my Android/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"

and here's my settings.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')

I have "react-native": "^0.73.4" and buildToolsVersion = "34.0.0"

I have tried most of the results I get here on StackOverflow. Any help in this will be greatly appreciated.


Solution

  • i faced the same issue . adding maven to the android/build.gradle file solve the issue for me. also ensure that you have the exact ndk installed. you can install it for android studio. react-native require the last jdk 18 so also install that and it must be added to your system path.

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

    to: 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()
        }
    }