I recently updated my React Native project from version 0.67.3
to 0.75.4
, following the instructions provided by the React Native upgrade helper. After running npm install
, everything worked as expected. However, when I attempted to build the project using Gradle with the following commands:
./gradlew clear
./gradlew build
I encountered the following errors during the ./gradlew clear
command:
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file 'MyProject/android/app/build.gradle' line: 84
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not read script 'MyProject/node_modules/react-native/react.gradle' as it does not exist.
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle
Here’s my android/build.gradle
configuration:
buildscript {
ext {
kotlinVersion = "1.6.20"
buildToolsVersion = "33.0.3"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 34
ndkVersion = "21.4.7075529"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath('com.android.tools.build:gradle:7.3.0')
classpath 'com.google.gms:google-services:4.3.15'
}
}
allprojects {
repositories {
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
url("$rootDir/../node_modules/jsc-android/dist")
}
mavenCentral {
content {
excludeGroup "com.facebook.react"
}
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
}
}
My gradle-wrapper.properties
file:
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Issues:
- Missing
react.gradle
file: It seems like thereact.gradle
file is missing fromnode_modules/react-native
. - SDK version not recognized: Even though I’ve set
compileSdkVersion = 33
in mybuild.gradle
file, the error suggests that it’s not specified.
Questions:
- Do I need to update the Gradle version, Kotlin version, or SDK versions (
buildToolsVersion
,minSdkVersion
,compileSdkVersion
,targetSdkVersion
,ndkVersion
) to fix these issues? - How do I resolve the missing
react.gradle
file? - Is there any additional configuration required after upgrading React Native to version
0.75.4
?
I’m fairly new to React Native and would appreciate any help or guidance!