React Native wont run on Android Device. Missing ANDROID_HOME [duplicate] - react-native

This question already has answers here:
React Native - java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties
(5 answers)
Closed 6 years ago.
When I execute react-native run-android in the terminal, I get the following:
JS server already running.
Running adb -s HT68X0201778 reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd
android && ./gradlew installDebug)... Failed to notify
ProjectEvaluationListener.afterEvaluate(), but primary configuration
failure takes precedence. java.lang.RuntimeException: SDK location not
found. Define location with sdk.dir in the local.properties file or
with an ANDROID_HOME environment variable.
FAILURE: Build failed with an exception.
Where: Build file '........./android/app/build.gradle'
line: 110
What went wrong: A problem occurred evaluating project ':app'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I have already done the following: Installed the Android Studio 2.2.3. I checked the boxes in the installer that it said to on the RN website. I installed Marshmallow SDK, AVD, HAXM, and JDK 1.8. I added ANDROID_HOME to /.bashrc and even executed set ANDROID_HOME=~/Library/Android/sdk on the terminal. (I double-checked the path.) I am running on react-native-cli version 2.0.1. Operating system is Mac OS Sierra.
I'm not sure where to go from here. Any help would be appreciated.
Thanks! --Anthony

Create a file called local.properties and add it to the android folder and then define sdk.dir(The location of your android SDK directory) in my case it is:
NOTE: you do not need to include it in quotes.
sdk.dir = /home/kbuhiire/Android/Sdk

I changed the ANDROID_HOME path from ~/Library/Android/sdk to /Users/myusername/Library/Android/sdk. That did the trick. Refer to React Native android build failed. SDK location not found

Related

React Native not working

I am working on react native and building my app on android pyhsical device but it throws an error.
I have set my JAVA_HOME and ANDROID_HOME variabes but still not working.
This is exactly what it is returning :-
Scanning folders for symlinks in /home/harsh/Desktop/App/node_modules (9ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
Could not determine java version from '10.0.1'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
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
Your error may come from the fact that you have 2 differents jdk installed and, since react should not be used with a jdk > 9 yet, check your Java installation with java -v in order to get the version.

Failed to download any source lists! (node.js v10.7.0 | yarn 1.7.0 | react-native: 0.56.0 | Windows 10)

I am trying to run a hello world application using the steps clarified hear. I am pretty sure I have done all the steps. but when I try to react-native run-android I get the below error.
react-native run-android ouput
C:\Users\Mike-laptop\AwesomeProject>react-native run-android
Scanning folders for symlinks in C:\Users\Mike-laptop\AwesomeProject\node_modules (43ms)
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\Mike-laptop\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
Failed to download any source lists!
java.io.FileNotFoundException: https://dl.google.com/android/repository/repository2-1.xml
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to find Build Tools revision 26.0.3
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.602 secs
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
Please note that I am running everything behind proxy... it is most likely due to the fact that react-native is not using proxy I have setup. I have tried to configure things in different ways.
Internet options
yarn config set proxy http://host:port
yarn config set h t t p s-proxy h t t p://host:port
npm config set proxy h t t p://host:port
npm config set h t t p s-proxy h t t p://host:port
set environment variable
set h t t p s_proxy=h t t p s://127.0.0.1:8123
set h t t p _proxy=h t t p://127.0.0.1:8123
set proxy=h t t p://127.0.0.1:8123
Still no luck :(
Much appreciate any comments.
First, you need to configure your Android env to run Android apps.
Please, take the steps in this link, in the Building Projects with Native Code tab, choose Windows and Android.:
https://facebook.github.io/react-native/docs/getting-started.html
Make sure you install Android SDK build tools 26.0.3 inside Android Studio.

react-native run-android gives an exception about the PATH connection

I am trying to run the react-native run-android command in window 10. I set up the path to the SDK folder using ANDROID_HOME in System Variables of Environment Variables
ANDROID_HOME | C:\Users\owner\AppData\Local\Android\Sdk
And I also set up sdk.dir in the local.properties file
sdk.dir=C\:\\Users\\owner\\AppData\\Local\\Android\\Sdk
However, when I run the command lines
react-native run-android
in my project folder C:\Users\owner\Documents\React_Native\MyApplication> It gave me an exception as follow.
C:\Users\owner\Documents\React_Native\MyApplication>react-native run-android
Scanning folders for symlinks in C:\Users\owner\Documents\React_Native\MyApplication\node_modules (34ms)
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.305 secs
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/android-setup.html

ReactNative assembleRelease apk fails to find index.android.js

node 6.11.2
npm 4.6.1
react-native-cli: 2.0.1
react-native: n/a - not inside a React Native project directory (???)
macOS 10.12.6
Used React Native to create a new app from scratch. npm start works like a charm when using the expo app on my Android and iOS Devices. I'm having troubles to build a release apk for Android. (iOS will be next step.)
I did eject the app and followed the instructions to create a keystore file etc. Everything like it is documented here: https://facebook.github.io/react-native/docs/signed-apk-android.html
In android folder: running ./gradlew assembleRelease results to:
...
:app:bundleReleaseJsAndAssets
Scanning 748 folders for symlinks in /Users/xy/myApp_ReactNative/node_modules (13ms)
Scanning 748 folders for symlinks in /Users/xy/myApp_ReactNative/node_modules (16ms)
Loading dependency graph, done.
Cannot find entry file index.android.js in any of the roots: ["/Users/xy/myApp_ReactNative"]
:app:bundleReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 26.813 secs
After days of trying out different versions and going back and forward, using commands with sudo and looking up alternatives, I'm getting completly lost. Also wondering why it scans twice... how to solve this?
Solved it myself like so: after trying on a Windows10 machine I realized that I might not have setup NDK. Started Android Studio on my mac and in the SDK Manager installed "NDK". Add a local.properties file in the 'app' folder with sdk.dir=pathtoyourSDK. After that: it worked!

Android build error: Cannot evaluate module RCTVideo : Configuration with name 'default' not found

I'm trying to get set up using https://github.com/brentvatne/react-native-video for an android version of a react-native app. After making all the changes to the various gradle files I'm running into this issue below.
I'm a bit of a novice with Android development, and I think I'm just making a silly mistake which is why I'm asking the question here rather than raising an issue. Any advice would be appreciated!
$ react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Cannot evaluate module RCTVideo : Configuration with name 'default' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 0.851 secs
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/android-setup.html
Edit, settings.gradle looks like this:
rootProject.name = 'app_name'
include ':RCTVideo', ':app'
project(':RCTVideo').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android')
Without seeing the Settings.gradle my guess would be that the project location isn't going into the folder that has the gradle for the android version of the library. I would recommend added /android at the end of the path if it isn't there already.
I will update this answer when the Settings.gradle is provided.
-- Edit after additional information provided --
The version available on NPM is from 3 months ago. It looks like they didn't start adding Android support till Oct 30th and have continued working on it. As such you likely don't actually have the Android code in your node_modules folder. You can either wait till they push an update to NPM or install directly from the git repo. If you go the route of installing directly from the git repo you might want to tag it with a specific commit so you don't keep getting the latest every time you do a npm install.