21

When ever i install any dependency in my react native project and when ever i use link command for e.g react-native link react-native-gesture-handler this causes me an error shown in the image [1]. It doesn't build the project shows the error gradlew.bat

The following code shows my package.json file

{
  "name": "navigations",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.3",
    "react-native": "0.58.3",
    "react-native-gesture-handler": "^1.0.15",
    "react-navigation": "^3.0.9"
  },
  "devDependencies": {
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.0.0",
    "jest": "24.0.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  },
  "jest": {
    "preset": "react-native"
  }
}
ketaki Damale
  • 634
  • 7
  • 25
Ovais Butt
  • 243
  • 1
  • 2
  • 9

10 Answers10

42

If you have WINDOWS machine, please follow these steps:

Optional (
  Delete iOS, Android folders

  Run `react-native eject` ( that command will rebuild deleted folders for you )
)

Then :

1) cd ./android

2) ./gradlew.bat installDebug ( with dot at the beggining )

Once it's successfully finished

3) cd ../ ( go back to root folder )

4) react-native run-android

And fingers crossed for it to work as expected :) [for me it does]

Alex K - JESUS first
  • 1,883
  • 14
  • 13
3

Here is how I resolved this problem.

Step 1: Open Android Studio -> File -> Invalided caches.. [ select all -> click Invalidated and Restart]

Android Studio -> File -> Invalided caches

Step 2: Open device manager -> select device -> use Wipe data and cold boot now

use Wipe data and cold boot now

Step 3: run npx react-native run-android in power shell

If not build successfully. Then use the following step.

Step 3.1: Open 2 PowerShell command plates then

  1. start metro bundler: npx react-native start --reset-cache --port 8084
  2. run-android : npx react-native run-android

Or If still not built successfully. Then try following step.

Step 4: Create another device with a supported API level. I used API 33 -> R 30 (API lavel). Now use Step 3.

Enjoy and Happy Coding...

Shapon Pal
  • 1,098
  • 3
  • 16
  • 27
2
cd ./android
create file file local.properties

then past this code sdk.dir=C\:\\Users\\muhammad ali\\AppData\\Local\\Android\\Sdk change location to as per your sdk is located Done. you already have local.properties file good. find similar file of code sdk.dir=C\:\\Users\\muhammad ali\\AppData\\Local\\Android\\Sdk change location to as per your sdk is located Done.

1

I had the same issue today... Wondering if you solved it?

go to android folder then settings.gradle file

You may find it on line 3

'..\node_modules\react-native-gesture-handler\android'

and replace all these backward slashes with forward like this

'../node_modules/react-native-gesture-handler/android'

Let me know if this helps...

Basit
  • 327
  • 3
  • 8
  • 19
  • Yes this helped I replaced all the "\" with "/" and cleaned the gradlew by command gradlew clean and the code run fine – Ovais Butt Feb 12 '19 at 06:49
  • @OvaisButt thanks for reminding me to gradlew clean. I forgot to do that after running gradlew.bat installDebug – Bipin Sep 23 '20 at 14:47
0

Make sure you already have installed python 2 and last version of jdk And make sure you have already set ANDROID_HOME

0

I got this same issue in when creating splash screen set to the MainActivity.java. Then I downgrade the react native version (0.59.8). I didn't change the gradle version.

chamila
  • 47
  • 1
  • 7
0

To solve this issue just change the compileSdkVersion in your build.gradle file.

Open android > build.gradle file. Change compileSdkVersion from 29 to 30. Change targetSdkVersion from 29 to 30. now run again.

/if this not working then checkout this link

Sumj25
  • 129
  • 1
  • 2
0

I had the same problem and used unusual solution but is helped me. after create your react-native project, open android folder by android studio, it will config your gradle Correctly and then you can run your app on simulator

amin
  • 561
  • 6
  • 18
0

Sometimes this error is caused by the debug keystore at least in my case that was the issue.

What I Did:

I ran this command to generate a new debug keystore

Windows Users:

keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

MAC / Linux Users:

$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Answer the prompt questions.

When the keystore is generated successfully go to android/app and place the keystore file there while updating your android/app/build.gradle file with:


  signingConfigs {
        debug {
            storeFile file('the-keystore-name.keystore')
            storePassword 'the-keystore-prompt-password'
            keyAlias 'the-keystore-alise-name'
            keyPassword 'the-keystore-promtp-password'
        }

    }

Thanks it! Just run yarn android again it should build now.

GOOD LUCK!

ObiTech Invents
  • 408
  • 3
  • 6
-1

I went into android studio and edited my emulated devices' storage capacity (RAM, VM heap, Internal Storage, removed SD card) in advanced settings. I believe I bumped every setting up. Virtual Device settings I'm not sure if this will solve your issue, however, it did resolve mine.

After that, I recreated a new project (npx react-native ...) then it worked like a charm.

As far as my computer goes, it has plenty of storage and ram so I wasn't too concerned with those limitations. Good luck

API = 33
Android Studio Version = 2021.2

Erksterx
  • 5
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 20 '22 at 14:57