Closed Malik-Usman17 closed 1 year ago
When I am building my react-native project through command prompt, I am running this line npx react-native run-android.
Does the issue happens also from PowerShell?
@cortinico yes I also tried on power shell, gives me same errors.
That's a odd issue.
One question to help me understand: is this file existing in your setup?
./node_modules/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt
What's the content of it?
@cortinico yes the file exist and the content is this: `/*
package com.facebook.react
import com.android.build.api.variant.AndroidComponentsExtension import com.android.build.gradle.AppExtension import com.android.build.gradle.internal.tasks.factory.dependsOn import com.facebook.react.tasks.BuildCodegenCLITask import com.facebook.react.tasks.GenerateCodegenArtifactsTask import com.facebook.react.tasks.GenerateCodegenSchemaTask import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFields import com.facebook.react.utils.AgpConfiguratorUtils.configureDevPorts import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap import com.facebook.react.utils.DependencyUtils.configureDependencies import com.facebook.react.utils.DependencyUtils.configureRepositories import com.facebook.react.utils.DependencyUtils.readVersionString import com.facebook.react.utils.JsonUtils import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson import com.facebook.react.utils.findPackageJsonFile import java.io.File import kotlin.system.exitProcess import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task import org.gradle.internal.jvm.Jvm
class ReactPlugin : Plugin
// App Only Configuration
project.pluginManager.withPlugin("com.android.application") {
project.afterEvaluate {
val reactNativeDir = extension.reactNativeDir.get().asFile
val propertiesFile = File(reactNativeDir, "ReactAndroid/gradle.properties")
val versionString = readVersionString(propertiesFile)
configureDependencies(project, versionString)
configureRepositories(project, reactNativeDir)
}
configureReactNativeNdk(project, extension)
configureBuildConfigFields(project)
configureDevPorts(project)
configureBackwardCompatibilityReactMap(project)
project.extensions.getByType(AndroidComponentsExtension::class.java).apply {
onVariants(selector().all()) { variant ->
project.configureReactTasks(variant = variant, config = extension)
}
}
// This is a legacy AGP api. Needed as AGP 7.3 is not consuming generated resources correctly.
// Can be removed as we bump to AGP 7.4 stable.
// This registers the $buildDir/generated/res/react/<variant> folder as a
// res folder to be consumed with the old AGP Apis which are not broken.
project.extensions.getByType(AppExtension::class.java).apply {
this.applicationVariants.all { variant ->
val isDebuggableVariant =
extension.debuggableVariants.get().any { it.equals(variant.name, ignoreCase = true) }
val targetName = variant.name.replaceFirstChar { it.uppercase() }
val bundleTaskName = "createBundle${targetName}JsAndAssets"
if (!isDebuggableVariant) {
variant.registerGeneratedResFolders(
project.layout.buildDirectory.files("generated/res/react/${variant.name}"))
variant.mergeResourcesProvider.get().dependsOn(bundleTaskName)
}
}
}
configureCodegen(project, extension, isLibrary = false)
}
// Library Only Configuration
project.pluginManager.withPlugin("com.android.library") {
configureCodegen(project, extension, isLibrary = true)
}
}
private fun checkJvmVersion(project: Project) { val jvmVersion = Jvm.current()?.javaVersion?.majorVersion if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) { project.logger.error( """
********************************************************************************
ERROR: requires JDK11 or higher.
Incompatible major version detected: '$jvmVersion'
********************************************************************************
"""
.trimIndent())
exitProcess(1)
}
}
/**
information: https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html */ @Suppress("UnstableApiUsage") private fun configureCodegen(project: Project, extension: ReactExtension, isLibrary: Boolean) { // First, we set up the output dir for the codegen. val generatedSrcDir = File(project.buildDir, "generated/source/codegen")
val buildCodegenTask = project.tasks.register("buildCodegenCLI", BuildCodegenCLITask::class.java) { it.codegenDir.set(extension.codegenDir) val bashWindowsHome = project.findProperty("REACT_WINDOWS_BASH") as String? it.bashWindowsHome.set(bashWindowsHome)
// Please note that appNeedsCodegen is triggering a read of the package.json at
// configuration time as we need to feed the onlyIf condition of this task.
// Therefore, the appNeedsCodegen needs to be invoked inside this lambda.
val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension)
it.onlyIf { isLibrary || needsCodegenFromPackageJson }
}
// We create the task to produce schema from JS files. val generateCodegenSchemaTask = project.tasks.register( "generateCodegenSchemaFromJavaScript", GenerateCodegenSchemaTask::class.java) { it -> it.dependsOn(buildCodegenTask) it.nodeExecutableAndArgs.set(extension.nodeExecutableAndArgs) it.codegenDir.set(extension.codegenDir) it.generatedSrcDir.set(generatedSrcDir)
// We're reading the package.json at configuration time to properly feed
// the `jsRootDir` @Input property of this task & the onlyIf. Therefore, the
// parsePackageJson should be invoked inside this lambda.
val packageJson = findPackageJsonFile(project, extension)
val parsedPackageJson = packageJson?.let { JsonUtils.fromCodegenJson(it) }
val jsSrcsDirInPackageJson = parsedPackageJson?.codegenConfig?.jsSrcsDir
if (jsSrcsDirInPackageJson != null) {
it.jsRootDir.set(File(packageJson.parentFile, jsSrcsDirInPackageJson))
} else {
it.jsRootDir.set(extension.jsRootDir)
}
val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension)
it.onlyIf { isLibrary || needsCodegenFromPackageJson }
}
// We create the task to generate Java code from schema. val generateCodegenArtifactsTask = project.tasks.register( "generateCodegenArtifactsFromSchema", GenerateCodegenArtifactsTask::class.java) { it.dependsOn(generateCodegenSchemaTask) it.reactNativeDir.set(extension.reactNativeDir) it.nodeExecutableAndArgs.set(extension.nodeExecutableAndArgs) it.generatedSrcDir.set(generatedSrcDir) it.packageJsonFile.set(findPackageJsonFile(project, extension)) it.codegenJavaPackageName.set(extension.codegenJavaPackageName) it.libraryName.set(extension.libraryName)
// Please note that appNeedsCodegen is triggering a read of the package.json at
// configuration time as we need to feed the onlyIf condition of this task.
// Therefore, the appNeedsCodegen needs to be invoked inside this lambda.
val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension)
it.onlyIf { isLibrary || needsCodegenFromPackageJson }
}
// We update the android configuration to include the generated sources. // This equivalent to this DSL: // // android { sourceSets { main { java { srcDirs += "$generatedSrcDir/java" } } } } project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext -> ext.sourceSets.getByName("main").java.srcDir(File(generatedSrcDir, "java")) }
// preBuild
is one of the base tasks automatically registered by AGP.
// This will invoke the codegen before compiling the entire project.
project.tasks.named("preBuild", Task::class.java).dependsOn(generateCodegenArtifactsTask)
}
}
`
Have you tried deleting gradle caches?
Yes, please try to delete the .gradle
folder inside your home and try again
Yes, please try to delete the .gradle
folder inside your home and try again
@cortinico if your guyz talking about the .gradle which lie under my project android folder then yes , i tried it also , then again run my project
with command npx react-native run-android
but no luck, still same errors.
@cortinico , i also tried by deleting .gradle but getting this error Could not resolve com.facebook.react:react-android:0.71.0
Could not determine the dependencies of task ':app:mergeReleaseNativeLibs'.
Could not resolve all task dependencies for configuration ':app:releaseRuntimeClasspath'. Could not find com.facebook.fresco:fresco:2.2.0. Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/facebook/fresco/fresco/2.2.0/fresco-2.2.0.pom
- https://oss.sonatype.org/content/repositories/snapshots/com/facebook/fresco/fresco/2.2.0/fresco-2.2.0.pom node_modules/jsc-android/dist/com/facebook/fresco/fresco/2.2.0/fresco-2.2.0.pom
- https://dl.google.com/dl/android/maven2/com/facebook/fresco/fresco/2.2.0/fresco-2.2.0.pom
- https://www.jitpack.io/com/facebook/fresco/fresco/2.2.0/fresco-2.2.0.pom Required by: project :app Could not find com.facebook.react:react-android:0.71.0. Searched in the following locations: node_modules/react-native/android/com/facebook/react/react-android/0.71.0/react-android-0.71.0.pom If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. Required by: project :app Could not find com.facebook.react:hermes-android:0.71.0. Searched in the following locations: node_modules/react-native/android/com/facebook/react/hermes-android/0.71.0/hermes-android-0.71.0.pom If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. Required by: project :app Could not find com.facebook.react:react-android:0.71.0. Searched in the following locations: react-native/android/com/facebook/react/react-android/0.71.0/react-android-0.71.0.pom If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. Required by: project :app > project :react-native-splash-screen project :app > project :react-native-restart project :app > project :@react-native-firebase_analytics project :app > project :@react-native-community_art project :app > project :@react-native-firebase_app project :app > project :@react-native-firebase_database project :app > project :@react-native-firebase_messaging project :app > project :@react-native-community_clipboard project :app > project :react-native-add-calendar-event project :app > project :intercom-react-native project :app > project :@react-native-community_toolbar-android project :app > project :@react-native-community_blur project :app > project :react-native-gesture-handler project :app > project :react-native-device-info project :app > project :react-native-background-timer project :app > project :lottie-react-native project :app > project :react-native-picker project :app > project :react-native-maps project :app > project :rn-fetch-blob project :app > project :react-native-permissions project :app > project :react-native-geolocation-service project :app > project :react-native-navigation project :app > project :@react-native-firebase_crashlytics project :app > project :react-native-orientation project :app > project :react-native-pager-view project :app > project :@react-native-community_async-storage project :app > project :react-native-keychain project :app > project :intercom_intercom-react-native project :app > project :invertase_react-native-apple-authentication project :app > project :react-native-community_art project :app > project :react-native-community_async-storage project :app > project :react-native-community_blur project :app > project :react-native-community_cameraroll project :app > project :react-native-community_checkbox project :app > project :react-native-community_clipboard project :app > project :react-native-community_datetimepicker project :app > project :react-native-community_netinfo project :app > project :react-native-community_picker project :app > project :react-native-community_toolbar-android project :app > project :react-native-firebase_analytics project :app > project :react-native-firebase_app project :app > project :react-native-firebase_crashlytics project :app > project :react-native-firebase_database project :app > project :react-native-firebase_dynamic-links project :app > project :react-native-firebase_messaging project :app > project :react-native-google-signin_google-signin project :app > project :bugsnag-react-native project :app > project :react-native-device-country project :app > project :react-native-fast-image project :app > project :react-native-fs project :app > project :react-native-image-crop-picker project :app > project :react-native-inappbrowser-reborn project :app > project :react-native-linear-gradient project :app > project :react-native-localization project :app > project :react-native-month-year-picker project :app > project :react-native-snackbar project :app > project :react-native-spinkit project :app > project :react-native-vector-icons project :app > project :react-native-video project :app > project :react-native-webview project :app > project :rn-sms-retriever Could not find com.eightbitlab:blurview:1.6.3. Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/eightbitlab/blurview/1.6.3/blurview-1.6.3.pom
- https://oss.sonatype.org/content/repositories/snapshots/com/eightbitlab/blurview/1.6.3/blurview-1.6.3.pom
- /node_modules/jsc-android/dist/com/eightbitlab/blurview/1.6.3/blurview-1.6.3.pom
- https://dl.google.com/dl/android/maven2/com/eightbitlab/blurview/1.6.3/blurview-1.6.3.pom
- https://www.jitpack.io/com/eightbitlab/blurview/1.6.3/blurview-1.6.3.pom Required by: project :app > project :@react-native-community_blur project :app > project :react-native-community_blur Could not find com.facebook.react:react-android:0.71.0. Searched in the following locations:
- node_modules/react-native/android/com/facebook/react/react-android/0.71.0/react-android-0.71.0.pom If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. Required by: project :app > project :react-native-mmkv
Possible solution:
Getting these errors, anybody help to resolve these.
Don't know how but I just solved it, by deleting the node_modules folder of my project and then re-running the project, it worked perfectly fine. Lastly thank you all for your involvement.
@cortinico
In case this helps someone - I followed the manual upgrade guide, but missed removing the following line in android/app/build.gradle
:
def enableHermes = project.ext.react.get("enableHermes", false);
Removing it resolved the issue for me π
Don't know how but I just solved it, by deleting the node_modules folder of my project and then re-running the project, it worked perfectly fine. Lastly thank you all for your involvement.
@cortinico
I'm having the same error but even after deleting node modules, it doesn't work. Throwing the same error.
@Azharul-Raj try to delete .gradle caches folder inside your home
@Azharul-Raj try running project using "yarn start" command.
Don't know how but I just solved it, by deleting the node_modules folder of my project and then re-running the project, it worked perfectly fine. Lastly thank you all for your involvement. @cortinico
I'm having the same error but even after deleting node modules, it doesn't work. Throwing the same error.
The first thing you need to do is try to delete your .gradle folder and then run your project again.
If you still face the same error, then try to delete your node_modules folder and then add your packages again by running yarn install
or npm install
whatever package manager you are using and after that run your project again.
I had an environment setup issue. Now it's ok
delete node_module folder and then install the libraries. i have followed the above steps and now my app is working
worked for me by deleting .gradle folder and node_modules
I deleted to node_modules and command npm install just worked for me
Deleting ".gradle" and "node_modules" folders worked for me. Thanks to all πππ
which .gradle folder you are talking about ??
the folder inside android directory or in users/zohaib/gradle
please tell me asap Thanks
which .gradle folder you are talking about ??
the folder inside android directory or in users/zohaib/gradle
yes, you have a folder named .gradle folder in your android folder (and not gradle folder)
I have resolved this with simple solution
just do rm -rf node_modules
then do yarn install
after that it will work
delete android/.gradle and node_modules and again run npm I and run android command it will work fine!
For this to work, you need to delete the "node_modules" folder and the android/.gradle file, and finally, you need to do a "npm i" and a ./gradlew clean in the android folder.
cleaning .gradle and node modules didnt worked on my case
cleaning .gradle and node modules didnt worked on my case
Try chmod +x .gradlew Could be you have cloned project from someone else and this file is throwing error coz it doesn't have exec permission
Try this boises
rm -rf node_modules && npm cache clean --force && yarn install && watchman watch-del-all && rm -rf $TMPDIR/haste-map-* && rm -rf $TMPDIR/metro-cache
Description
When I am running newly build project it gives me these errors:
Version
0.71.0
Output of
npx react-native info
info Fetching system and libraries information... error Unable to print environment info. Error: Command failed: wmic os get Caption 'wmic' is not recognized as an internal or external command, operable program or batch file.
Steps to reproduce
When I am building my react-native project through command prompt, I am running this line npx react-native run-android.
Snack, code example, screenshot, or link to a repository
npx react-native run-android