Cannot open new React-Native project in Android Studio - Gradle sync fails
See original GitHub issueDescription
I am upgrading an existing React-Native project from 0.64.1 to 0.66.3. My project includes java native code for Android, therefore I cannot use Expo and I do a lot of coding in Android Studio to get the intellisense support for Java code and so on that it offers.
After upgrading from RN .64 to .66, I can get it to build and run on Android using the gradlew
wrapper command line tool. The apk that is built installs and works correctly. I use Visual Studio Code for Javascript coding and the metro bundler and debugging tools that come with the React Native Tools extension
However, when it came time to modify the Java Native code, I brought up the Android project in Android Studio and immediately received an error from Gradle sync. It cannot build due to an exception.
After much debugging, I created a blank brand new React-Native project and simply brought it up in Android Studio as soon as it was created without modification and received the same exception:
/home/cschlesiger/Projects/newRN/node_modules/metro/src/Server.js:350 processRequest = (req, res, next) => {
^SyntaxError: Unexpected token =
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/cschlesiger/Projects/newRN/node_modules/metro/src/shared/output/bundle.js:12:16)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
I created a second fresh blank React-Native application using RN 0.64.1 and brought that one up in Android Studio the same way and it synchronized just fine - no errors.
I suppose there could be something wrong with my environment, however the fact that the only thing changing between these two fresh projects is the React-Native version makes me suspicious. If my environment were missing a variable or something like that it would fail for both.
Unless there is some new requirement for Android Studio for 0.66.3 that I missed in the documentation?
NOTE: Looking at the output of react-native info, I notice that it is not finding Android Studio under IDEs. I find that odd, since I know it is installed on this system via Ubuntu Software Center (Arctic Fox 2020.3.1 Patch 2: AI-203.7717.56.2031.7678000).
Version
0.66.3
Output of react-native info
System: OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa) CPU: (4) x64 Intel® Xeon® E-2176M CPU @ 2.70GHz Memory: 387.31 MB / 15.61 GB Shell: 5.8 - /usr/bin/zsh Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node Yarn: 1.22.15 - ~/.nvm/versions/node/v16.13.0/bin/yarn npm: 8.1.3 - ~/.nvm/versions/node/v16.13.0/bin/npm Watchman: Not Found SDKs: Android SDK: API Levels: 25, 28, 29, 30 Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3 System Images: android-26 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: Not Found Languages: Java: 14.0.2 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.66.3 => 0.66.3 npmGlobalPackages: react-native: Not Found
Steps to reproduce
- Create a new blank React-Native project:
npx react-native init newRN
- Open up Android Studio, open the newRN/android folder.
- Observe the exception as it tries to sync the gradle files.
- Create a second blank React-Native project using 0.64.1
npx react-native init newRN64 --version 0.64.1
- Open up Android Studio, open the newRN64/android folder.
- Observe that this second project synchronized with gradle successfully - no errors.
Snack, code example, screenshot, or link to a repository
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top GitHub Comments
Android studio might not be using your current Node version.
Try to use “Run anything” feature from Android Studio then type
node --version
orwhich node
.If you see something different than your
Node: 16.13.0
it might be related to a nvm issue and/or a conflict with a Node system installation.I don’t know if there a better way than this command:
That was it! Android Studio wasn’t using the node version set by nvm. It was instead using a system install of node that was an older version 10.19.0.
I set up the symbolic link you suggested, and I did some other searching to see if this was the preferred way (it is), and that cleared up the problem. Android Studio was successfully gradle syncing again, and can build my project.
Thank you very much!