skip to Main Content

I am trying to learn react native. I have a react native project using metro. Doing ./gradlew build but getting error Could not find com.facebook.react:react-native:0.74.4. I tried adding exclusiveContent as suggested in one SO article but didn’t helped. I am getting this error after I have added react-native-safe-area-context and react-native-screens. Any help to fix this error would be much appreciated.

{
  "name": "myreactnative",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",
    "react": "18.2.0",
    "react-native": "0.74.4",
    "react-native-safe-area-context": "^4.10.8",
    "react-native-screens": "^3.33.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.74.86",
    "@react-native/eslint-config": "0.74.86",
    "@react-native/metro-config": "0.74.86",
    "@react-native/typescript-config": "0.74.86",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "[email protected]"
}
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

react {
    
}

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.myreactnative"
    defaultConfig {
        applicationId "com.myreactnative"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    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.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

dependencies {
    implementation("com.facebook.react:react-android:0.74.4")
    implementation("com.android.support:appcompat-v7:28.0.0")
    implementation("com.android.tools.lint:lint-gradle:31.5.1")
    implementation 'com.facebook.react:react-native:0.74.4'

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android:0.74.4")
    } else {
        implementation jscFlavor
    }
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
//project level build.gradle

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 23
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.22"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.5.1")
        classpath("com.facebook.react:react-native-gradle-plugin:0.71.19") 
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
    //     exclusiveContent {
    //        filter {
    //            includeGroup "com.facebook.react"
    //        }
    //        forRepository {
    //            maven {
    //                url "$rootDir/../node_modules/react-native/android"
    //            }
    //        }
    //    }
       maven {
            url "$rootDir/../node_modules/react-native/android"
       }
    }
}
apply plugin: "com.facebook.react.rootproject"

2

Answers


  1. Why are you adding react-native in build.gradle? Remove it from there.

    dependencies {
        implementation("com.facebook.react:react-android:0.74.4")
        implementation("com.android.support:appcompat-v7:28.0.0")
        implementation("com.android.tools.lint:lint-gradle:31.5.1")
    
        if (hermesEnabled.toBoolean()) {
            implementation("com.facebook.react:hermes-android:0.74.4")
        } else {
            implementation jscFlavor
        }
    

    The React native dependency is automatically added to the package.json.

    "dependencies": {
        "@react-navigation/native": "^6.1.18",
        "@react-navigation/native-stack": "^6.11.0",
        "react": "18.2.0",
    
        //Here it is added automatically hence you do not need to add it in `build.gradle`.
    
        "react-native": "0.74.4",
        "react-native-safe-area-context": "^4.10.8",
        "react-native-screens": "^3.33.0"
      },
    
    Login or Signup to reply.
  2. Remove this line:

    implementation 'com.facebook.react:react-native:0.74.4'
    

    Meanwhile there’s version 0.74.5.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search