Reputation: 1
My react native project fails to build app and gives this error:
Task :@react-native-community_netinfo:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':@react-native-community_netinfo:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.
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 3s
10 actionable tasks: 1 executed, 9 up-to-date
error Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: ./gradlew app:installDebug. Run CLI with --verbose flag for more details.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
It doesn't install app on the emulator device.
Here is the package.json content:
"dependencies": { "@babel/plugin-transform-react-constant-elements": "^7.6.3", "@react-native-community/netinfo": "^4.7.0", "@types/node": "^12.11.1", "aadhaar-validator": "^1.1.0", "babel-plugin-transform-react-pure-class-to-function": "^1.0.1", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", "compare-versions": "^3.6.0", "frisbee": "^1.1.7", "libphonenumber-js": "^1.7.52", "mobx": "^4.9.4", "mobx-react": "^6.1.4", "react": "^16.8.1", "react-native": "^0.59.10", "react-native-appstore-version-checker": "^2.7.2", "react-native-calendar": "^0.13.1", "react-native-check-box": "^2.1.7", "react-native-checkbox": "^2.0.0", "react-native-collapsible": "^1.5.1", "react-native-config": "^0.11.7", "react-native-datepicker": "^1.7.2", "react-native-deprecated-custom-components": "^0.1.2", "react-native-drawer": "^2.5.1", "react-native-element": "^1.2.1", "react-native-fetch-blob": "^0.10.8", "react-native-firebase": "^5.6.0", "react-native-image-picker": "^1.1.0", "react-native-keyboard-aware-scrollview": "^2.0.0", "react-native-loading-spinner-overlay": "^1.0.1", "react-native-material-kit": "0.5.1", "react-native-phone-input": "^0.1.10", "react-native-push-notification": "^7.2.3", "react-native-side-menu": "^1.1.3", "react-native-simple-toast": "^0.1.1", "react-native-splash-screen": "^3.2.0", "react-native-style-tachyons": "^4.0.0", "react-native-swiper": "^1.5.14", "react-native-table-component": "^1.2.1", "react-native-version-number": "^0.3.6", "react-native-webview": "7.5.2", "react-test-renderer": "^16.10.2" }, "devDependencies": { "@babel/core": "^7.6.4", "@babel/plugin-transform-react-inline-elements": "^7.2.0", "@babel/preset-env": "^7.6.3", "@babel/preset-react": "^7.6.3", "@types/jest": "^24.0.18", "@types/react": "^16.9.5", "autobind-decorator": "^1.3.4", "axios": "^0.15.3", "babel-eslint": "^7.1.1", "babel-jest": "18.0.0", "babel-loader": "^7.1.5", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-preset-react-native": "1.9.1", "babel-preset-react-native-stage-0": "^1.0.1", "bluebird": "^3.5.0", "concurrently": "^3.1.0", "eslint": "^3.14.0", "eslint-config-airbnb": "^14.0.0", "eslint-plugin-babel": "^4.0.1", "eslint-plugin-flowtype": "^2.30.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^3.0.2", "eslint-plugin-react": "^6.9.0", "flow-bin": "0.33.0", "jest": "18.1.0", "jetifier": "^1.6.4", "json2csv": "^3.7.3", "markdown-toc": "^1.1.0", "metro-react-native-babel-preset": "^0.56.0", "nodemon": "^1.11.0", "rimraf": "^2.5.4", "tslint": "^4.3.1", "typescript": "^3.6.4" },
Please suggest any hints to rectify this error.
My project used to run fine few weeks back. It is giving errors now, without any changes made to code.
Upvotes: 0
Views: 843
Reputation: 23
I encountered the same problem, and what helped me was setting up the Android development environment correctly. Here’s a step-by-step guide to ensure your environment is configured properly:
Step 1: Set Up Android SDK Path Open your terminal.
Edit your profile file by typing the following command:
vim ~/.profile
If you're using a different shell (e.g., zsh), you might need to edit
~/.zshrc
Add the following lines to set the Android SDK path:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/platform-tools
Save and exit the editor. In vim, you can do this by pressing Esc, typing :wq, and then pressing Enter.
Step 2: Apply the Changes Source the profile file to apply the changes:
source ~/.profile
If you edited a different file (like ~/.zshrc), source that file instead:
source ~/.zshrc
Step 3: Verify JAVA_HOME Check if JAVA_HOME is defined:
echo $JAVA_HOME
If it returns an empty line or is not set, you need to set it up. Set JAVA_HOME if it's not defined:
export JAVA_HOME=$(/usr/libexec/java_home)
Add this line to your profile file as well to ensure it’s set every time you open a terminal.
Step 4: Additional Debugging If you still face issues, you can try running the build command with more detailed logging:
cd android
./gradlew app:installDebug --stacktrace --info --debug
This will provide more information about what went wrong during the build process.
Reference For more details, you can check out this Stack Overflow question: React Native android build failed. SDK location not found
Upvotes: 1