Hello, I’m new to react-native and i keep getting this error everytime i try to run: react-native run-android
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> java.io.IOException: The filename, directory name, or volume label syntax is incorrect
* 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.
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 14s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
What’s wrong? is there something missing?
How I solved this problem:
First, make sure that I have %java_home% variable set and also %path% has the java sdk included.
How to setup Java environment variables
Second, Go to your android folder and run this command:
C:Projectsmyprojectandroid>gradlew.bat app:installDebug.
Unzipping
C:Userscodeb.gradlewrapperdistsgradle-4.10.2-all9fahxiiecdb76a5g3aw9oi8rvgradle-4.10.2-all.zip
to
C:Userscodeb.gradlewrapperdistsgradle-4.10.2-all9fahxiiecdb76a5g3aw9oi8rv
Exception in thread «main» java.util.zip.ZipException: error in
opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(ZipFile.java:225)
at java.util.zip.ZipFile.(ZipFile.java:155)
at java.util.zip.ZipFile.(ZipFile.java:169)
at org.gradle.wrapper.Install.unzip(Install.java:215)
at org.gradle.wrapper.Install.access$600(Install.java:27)
at org.gradle.wrapper.Install$1.call(Install.java:75)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
As you can see that my gradle download is corrupt. All you have to do is delete this folder and rerun the command.
C:Projectsmyprojectandroid>gradlew.bat app:installDebug
Downloading
https://services.gradle.org/distributions/gradle-4.10.2-all.zip
…………………………………………………………………………………………………
Unzipping
C:Userscodeb.gradlewrapperdistsgradle-4.10.2-all9fahxiiecdb76a5g3aw9oi8rvgradle-4.10.2-all.zip
to
C:Userscodeb.gradlewrapperdistsgradle-4.10.2-all9fahxiiecdb76a5g3aw9oi8rvWelcome to Gradle 4.10.2!
Here are the highlights of this release:
— Incremental Java compilation by default
— Periodic Gradle caches cleanup
— Gradle Kotlin DSL 1.0-RC6
— Nested included builds
— SNAPSHOT plugin versions in theplugins {}blockFor more details see https://docs.gradle.org/4.10.2/release-notes.html
Now, you can go back to your react native project and run
react-native run-android
info JS server already running. info Building and installing the app
on the device (cd android && gradlew.bat app:installDebug)…Task :app:installDebug 01:03:18 V/ddms: execute: running am get-config 01:03:18 V/ddms: execute ‘am get-config’ on ’emulator-5554′
: EOF hit. Read: -1 01:03:18 V/ddms: execute: returning Installing APK
‘app-debug.apk’ on ‘Pixel_2_API_28(AVD) — 9′ for app:debug 01:03:18
D/app-debug.apk: Uploading app-debug.apk onto device ’emulator-5554′
01:03:18 D/Device: Uploading file onto device ’emulator-5554′ 01:03:18
D/ddms: Reading file permision of
C:Projectsxxandroidappbuildoutputsapkdebugapp-debug.apk
as: rwx—— 01:03:18 V/ddms: execute: running pm install -r -t
«/data/local/tmp/app-debug.apk» 01:03:19 V/ddms: execute ‘pm install
-r -t «/data/local/tmp/app-debug.apk»‘ on ’emulator-5554′ : EOF hit. Read: -1 01:03:19 V/ddms: execute: returning 01:03:19 V/ddms: execute:
running rm «/data/local/tmp/app-debug.apk» 01:03:19 V/ddms: execute
‘rm «/data/local/tmp/app-debug.apk»‘ on ’emulator-5554′ : EOF hit.
Read: -1 01:03:19 V/ddms: execute: returning Installed on 1 device.BUILD SUCCESSFUL in 9s 27 actionable tasks: 1 executed, 26 up-to-date
info Running
C:UserscodebAppDataLocalAndroidSdk/platform-tools/adb -s
emulator-5554 reverse tcp:8081 tcp:8081 info Starting the app on
emulator-5554
(C:UserscodebAppDataLocalAndroidSdk/platform-tools/adb -s
emulator-5554 shell am start -n
com.myproject/com.myproject.MainActivity)… Starting:
Intent { cmp=com.myproject/.MainActivity }
Hello Guys, How are you all? Hope You all Are Fine. Today when I am trying to run my app on android it gives me the following Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 in React Native. So Here I am Explain to you all the possible solutions here.
Without Wasting your time, Lets start This Article to Solve This Error.
Contents
- How This Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 Occurs ?
- How To Solve Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 ?
- Solution 1: change the
compileSdkVersion - Solution 2: add ResolutionStrategy
- Solution 3: add 1.7.0-alpha01
- Summery
I am trying to run my app in android by react-native run-android this command and I am getting below error:
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
How To Solve Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 ?
- How To Solve Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 ?
To Solve the error Failed to install the app. Make sure you have the Android development environment set up just change the
compileSdkVersionin your build.gradle file. Open android > build.gradle file. Change compileSdkVersion from 29 to 30. Change targetSdkVersion from 29 to 30. now run again. - Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
To Solve the error Failed to install the app. Make sure you have the Android development environment set up just change the
compileSdkVersionin your build.gradle file. Open android > build.gradle file. Change compileSdkVersion from 29 to 30. Change targetSdkVersion from 29 to 30. now run again.
Solution 1: change the compileSdkVersion
To solve this issue just change the compileSdkVersion in your build.gradle file.
- Open android > build.gradle file.
- Change
compileSdkVersionfrom 29 to 30. - Change
from 29 to 30.targetSdkVersion - now run again.
Solution 2: add ResolutionStrategy
add ResolutionStrategy in your build.gradle file to resolve this issue. here is example. add this following line to build.gradle file:
configurations.all {
resolutionStrategy { force 'androidx.core:core-ktx:1.6.0 }
}
Solution 3: add 1.7.0-alpha01
add the below code in build.gradle inside android.
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
}
}
and then apply this
implementation 'androidx.core:core-ktx:1.7.0-alpha01'
Summery
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also Read
- SyntaxError: invalid syntax to repo init in the AOSP code.
React Native is one of the most used JavaScript mobile frameworks today. React Native enables developers who are familiar with JavaScript and the React web framework to develop mobile applications using similar methods and principles.
As a React Native developer, you’re bound to run into some errors when developing your application. When an error is detected by the compiler when running the code, it terminates the process and displays an error message.
Error messages in React Native are very descriptive. They tell the developer what error occurred and where the error was detected. In addition, they often provide clear instructions or at least a clue on how to resolve the issue.
Some errors are inherently easier to debug than others. For example, errors that happen as a result of using the wrong syntax or accessing undefined variables or components are easier to debug than errors caused by misconfigurations or incompatible dependencies.
Regardless of the nature of the error, you’ll often need help to resolve them.
In this post, I’ll cover some common React Native errors and their solutions. Some of these errors will have different solutions depending on what causes the error in the first place. For such errors, go through the solutions one after another.
Feel free to skip to any of the following sections using the links below:
- Failed to install the app
- Unable to load script
- React Native
run-androidcommand is unrecognized react-nativecommand not found- Unrecognized command: “link”
- Duplicate resources
Failed to install the app
After creating a new React Native project, when attempting to run the app for the first time with the command react-native run-android, you might encounter the following error:
BUILD FAILED in 13s error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. ...
This error message says that the build process wasn’t successful and also specifies the particular command that failed. Sometimes you can get rid of the error by simply using new command prompts and restarting the virtual devices.
Oftentimes, however, the error is caused by using an incompatible Gradle version to build the app.
The Android studio build system requires the right version of Gradle to successfully build Android apps. In this case, you’ll need to upgrade the Gradle version used in your app to one that is compatible with your Android studio build system.
Follow these steps:
- Open your React Native application in a text editor like VS Code
- In the application’s root folder, navigate to
android > gradle > wrapper - Edit the
gradle-wrapper.propertiesfile - Update the
distributionUrlvariable with the URL for a compatible version of Gradle - Run
react-native run-androidagain to build the app using the new version.
Here’s the full path for steps two and three:
{your-project-folder}androidgradlewrappergradle-wrapper.properties
To get the accurate version of Gradle for step four, go to Gradle’s distributions list and check for the latest -all.zip Gradle version. Then, update the distributionUrl variable as follows:
distributionUrl=https://services.gradle.org/distributions/gradle-{latest version}.zip
To learn more about Gradle and Android studio, read the Android Gradle plugin and Android Studio compatibility article.
Unable to load script
Another error that developers commonly encounter when attempting to run their React Native application is shown below:
Unable to load script. Make sure you're either running a metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
This error is always displayed on the connected Android device. There are several causes for this error. As such, there are different solutions too.
Solution 1: Package the bundle correctly
All of your app’s JavaScript is bundled into the index.android.bundle file. If the bundle file is unavailable or not correctly packaged, you’ll get the Unable to load script error. Follow the instructions below to fix it.
Go into {your-project-folder}/android/app/src/main/ folder and check if an assets folder exists within it. If the assets folder isn’t already there, create it.
Next, directly from your root folder, run this:
cd android ./gradlew clean
Next, open a command terminal and make sure it’s pointed to your project’s root folder. If your project has just one file (i.e index.js), run the following command:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
If there are two files (i.e. index.android.js and index.ios.js) then run the following instead:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
Note that both are single commands.
After the bundle has been generated, run react-native run android.
To execute all the above steps at once, you can place them in the scripts section of package.json like so:
"android-script": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-android"
The command for the above is npm run android-script.
Solution 2: Use adb reverse
If you keep getting the same error after implementing the first solution, then you need to consider other causes. Another common cause is that the port wasn’t exposed. This happens if you’re running your app on a physical device.
The adb reverse command lets you to expose a TCP port on your Android device with a TCP port on your computer. To try fixing the error, run the following command:
adb reverse tcp:8081 tcp:8081
Here you are exposing TCP port 8081 on the phone via port 8081 on your computer.
If you do not have the Android platform tools component in your Windows PATH variable, then the adb executable is found at the following path:
C:Users{your-username}AppDataLocalAndroidsdkplatform-tools
Solution 3: Add cleartext support
If the first two options don’t solve React Native’s inability to load the script, then it’s likely that the error is coming from a network communication problem.
Specifically, it’s likely that the app is inaccessible from the development server due to cleartext support being disabled, as is the case from Android 9.0 (API level 28) onwards.
To fix this, modify the AndroidManifest.xml file and add cleartext support as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
You can find your AndroidManifest.xml file in:
{your-project-folder}/android/app/src/main/AndroidManifest.xml
Restart your application for the change to be applied.
React Native run-android command is unrecognized
Sometimes when you attempt to run your React Native app on Android, you might get the following error message on the command prompt:
Command run-android unrecognized. Did you mean to run this inside a react-native project?
The error message already hints at the most common cause of the error: you’re not running the command in a React Native folder. In this case, the solution is to simply ensure that you navigate to your application’s root folder before running the app. This is what I mean:
// After initializing a project: react-native init AwesomeProject // Make sure to navigate to the project folder: cd AwesomeProject // Before you run the app: react-native run-android
Otherwise, if the error wasn’t a result of using the wrong folder, then it’s possible that you didn’t install the contents of the project. To do that, run:
npm install or yarn install
It’s also possible that your global installation of react-native or react-native-cli is old or broken. In this case, simply reinstall your libraries globally using one of the following commands:
npm:
npm install -g react-native && npm install -g @react-native-community/cli
Yarn:
yarn global add react-native && yarn global add @react-native-community/cli
As a note, I recommend using npx (included in npm v5.0+) to install libraries on demand.
This means that whenever you run npx react-native init <your-project-name> or any other React Native CLI command, it’ll first ask for your permission to install react-native before creating the project. This ensures that you always use the latest version at all times!
Lastly, if all of the above fails to work, you might need to upgrade your npm with the following command:
npm install [email protected] -g
Ensure that you run each of these commands using a new terminal. This is to prevent using outdated path sources in your .bashrc file.
react-native command not found
command not found: react-native is another common error in React Native. You encounter this error when attempting to run any react-native command, such as when you try to initialize a React Native project, like so:
react-native init MyProject
The command not found error has two potential causes: either you do not have the CLI installed on your local machine, or you do, but it’s not properly configured.
Both of these scenarios can be avoided by using npx for all npm executables. For example, to create a new React Native app, run it with npx as follows:
npx react-native init MyProject
This will install the latest available version of the react-native package before initializing the project.
Unrecognized command: “link”
When attempting to link assets like custom fonts or icons in a React Native project, you might get the following error on your command terminal:
error Unrecognized command "link". info Run "react-native --help" to see a list of all available commands.
This error occurs when you attempt to use the manual linking feature (i.e. react-native link and react-native link unlink commands), which have been removed in React Native 0.69 and replaced with autolinking.
To avoid this error, you’ll need to use a third-party asset linking library such as react-native-asset to link assets automatically.
First, install the library with one of the following commands:
npm install -g react-native-asset # or if you're using yarn: yarn global add react-native-asset
Then create a react-native.config file at the root level of the project folder and add the below code snippet:
module.exports = {
project: {
ios: {},
android: {}
},
"assets": [
"./src/assets/font",
"./src/assets/mp3",
"./src/assets/icons"
]
};
Run one of the below commands to enable automatic linking and unlinking in your codebase.
npm:
npx react-native-asset
yarn:
yarn react-native-asset
Now you can use any of the specified assets in your code. For example, you can use a custom font in your stylesheet:
fontFamily: 'my-custom-font'
Duplicate resources
Another common error that you might face when attempting to generate a release APK using Generate Signed APK from Android Studio is the Duplicate Resource error:
[drawable-mdpi-v4/jumper] /Users/admin/Projects/testApp/android/app/src/main/res/drawable-mdpi/jumper.png [drawable-mdpi-v4/jumper] /Users/admin/Projects/testApp/android/app/build/generated/res/react/release/drawable-mdpi-v4/jumper.png: Error: Duplicate resources :app:mergeReleaseResources FAILED FAILURE: Build failed with an exception. ...
The build failure occurred because duplicated resources were found in the Android project inside the Android folder. There are various solutions for this depending on the cause.
Solution 1: Cleaning the drawable folder from the terminal
Oftentimes you can get rid of the error simply by cleaning the drawable folder from the terminal using Gradle. To do this, cd into the android folder, then run ./gradlew clean before attempting to run the app again:
react-native run android
If it fails, try the next solution.
Solution 2: Add some helper code
Most times, simply cleaning the drawable folder won’t resolve the issue. If that’s the case, then you’ll need to make a slight modification in the react.gradle file to prevent duplicate resource collisions.
Add the following helper code in the react.gradle file found in node_modules/react-native/react.gradle. The code should be placed right after the doFirst block:
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
if (originalDir.exists()) {
File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
ant.move(file: originalDir, tofile: destDir);
}
}
moveFunc.curry("ldpi").call()
moveFunc.curry("mdpi").call()
moveFunc.curry("hdpi").call()
moveFunc.curry("xhdpi").call()
moveFunc.curry("xxhdpi").call()
moveFunc.curry("xxxhdpi").call()
}
This error was solved in 2018 by GitHub user echaso, who provided the code above.
Conclusion
In this article, we looked at six common errors in React Native and how each of these errors can be debugged. If the error you encountered isn’t included here, do not hesitate to check this article for possible solutions.
Anyways, thanks for reading and see you next time!
LogRocket: Instantly recreate issues in your React Native apps.
LogRocket is a React Native monitoring solution that helps you reproduce issues instantly, prioritize bugs, and understand performance in your React Native apps.
LogRocket also helps you increase conversion rates and product usage by showing you exactly how users are interacting with your app. LogRocket’s product analytics features surface the reasons why users don’t complete a particular flow or don’t adopt a new feature.
Start proactively monitoring your React Native apps — try LogRocket for free.
Issue
I am new to react native, I was trying to follow an example on how to launch react native app with react native CLI but I keep getting this error in my CMD.
C:React Native WorkspaceRN-CLIFirstCli>npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 863 file(s) to forward-jetify. Using 12 workers...
info Starting JS server...
'adb' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:React Native WorkspaceRN-CLIFirstCliandroidlocal.properties'.
* 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 10s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at 'C:React Native WorkspaceRN-CLIFirstCliandroidlocal.properties'.
* 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 10s
at makeError (C:React Native WorkspaceRN-CLIFirstClinode_modulesexecaindex.js:174:9)
at C:React Native WorkspaceRN-CLIFirstClinode_modulesexecaindex.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (C:React Native WorkspaceRN-CLIFirstClinode_modules@react-native-communitycli-platform-androidbuildcommandsrunAndroidrunOnAllDevices.js:109:5)
at async Command.handleAction (C:React Native WorkspaceRN-CLIFirstClinode_modules@react-native-communityclibuildindex.js:192:9)
info Run CLI with --verbose flag for more details.
I need help with resolving these issues.
Solution
Assuming that you already have the Android SDK installed, you need to create a file named local.properties at the root of you Android project your-react-native-project-android/ and you should also add it to .gitignore if you are using git.
The file must indicate the path of the SDK on your computer, for macOS for example
local.properties
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Oct 26 14:02:40 CEST 2021
sdk.dir=/Users/username/Library/Android/sdk
If you never installed the SDK, you need to start here
Answered By — yemd
This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with –verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Unable to install C:UsersyouDesktopYourAppandroidappbuildoutputsapkdebugapp-debug.apk
com.android.ddmlib.InstallException: INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.yourapp signatures do not match previously installed version; ignoring!
O man, what a doozy!?! Okay so here’s what’s probably going on, or at least what has been going on the several times I’ve run into this error. I happen to do development on several different computers, but use the same physical android device to test my app. So what happens is, the signature attached to the app installed on our physical android device, doesn’t match the signature of the computer that we’ve moved to and are now working.
However, the fix is fairly simple. All you need to do is delete the app from your physical device, then re-build/run your app again and all shall be well!
$ npx react-native run-android
or…
$ react-native run-android



