Search code examples
react-nativekotlinreact-navigationreact-native-gesture-handler

React Native - Execution failed for task ':react-native-gesture-handler:compileDebugKotlin'


I clone a React Native Project and run npm install. After that, I usethe npm start command to run the project. But it was through an error.

----------Error----------

import static com.facebook.react.common.StandardCharsets.UTF_8; ^ Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 warning

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':react-native-gesture->handler:compileDebugKotlin'. A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction Compilation error. See log for more details

  • 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.

BUILD FAILED in 2m 2s


My build.grdle file:

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.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        classpath 'com.android.tools.build:gradle:8.7.1'

    }
}

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

gradle-wrapper.properties file:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Package.json file:

    "react": "18.2.0",
    "react-native": "0.73.0",
    "react-native-gesture-handler": "^2.18.1",
    "react-native-safe-area-context": "^4.4.1",
    "react-native-screens": "^3.18.2",

Please help me to resolve this error.


Solution

  • Check versions of React Native Gesture Handler for React Native versions.

    react-native-gesture-handler/docs

    enter image description here

    So, for node_modules fun this command:

    npm i --legacy-peer-deps
    

    Uninstall react-native-gesture-handler using this command:

    npm uninstall react-native-gesture-handler --legacy-peer-deps
    

    and install react-native-gesture-handler using this command:

    npm install [email protected] --legacy-peer-deps
    

    This will install react-native-gesture-handle of version 2.18.1 recommended for react-native version 0.73.0.

    Hope this will solve your issue.