shared/docs/android.md
brew install watchman (install file watcher)adb devices (should list exactly one device)yarn rn-gobuild-androidyarn android-debugFollow instructions for running an android project at https://reactnative.dev/
Additionally an NDK version needs to be installed for yarn rn-gobuild-android to work.
With Android Studio
You will already have the sdkmanager command line tool installed. So run:
sdkmanager --install "ndk-bundle" which should write to $HOME/Library/Android/sdk/ndk-bundle on macOS.
Without Android Studio
You will need the Android Studio Command Line Tools to use sdkmanager without Android Studio.
Download Command Line Tools here.
Then run sdkmanager --install "ndk-bundle" which should write to $HOME/Library/Android/sdk/ndk-bundle on macOS.
If you're installing on Linux, you'll want to get KVM set up. Otherwise, you'll see this message:
> ./emulator @Nexus_5X_API_28_x86
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: This user doesn't have permissions to use KVM (/dev/kvm)
Normally, /dev/kvm can only be used by root, but you don't
want to run things as root regularly. Instead, make a kvm group and
add your current user in it:
# As root
addgroup kvm
usermod -a -G kvm $USER
You may have to log out and re-log in, or even reboot, for this to
take effect. Then you'll want to configure the right group and permissions
for /dev/kvm. From this StackExchange answer,
/etc/udev/rules.d/65-kvm.rules as rootKERNEL=="kvm", NAME="%k", GROUP="kvm", MODE="0660"
udevadm control --reload-rules && udevadm triggeryarn android-debug
Unless you're modifying the Java files or you're modifying Go files
(and thus re-running run-gobuild-android), you likely have to only
run this occasionally.
Then make sure you either have an emulator running, or you have your Android device connected (but not both). To check, run
adb devices
It should list exactly one device.
Either use the avd manager in Android Studio or use the raw commands below. Setting up an avd is much easier in Android Studio, so it's recommended to do that for the inital setup at least
# Even though emulator should be in your path, it
# seems to require you to be in this directory.
cd $ANDROID_HOME/emulator
emulator -list-avds
# Nexus_5X_API_27_x86 is an example avd.
#
# The leading './' is needed on Linux.
./emulator @Nexus_5X_API_27_x86
assuming you've set the $ANDROID_HOME variable and added
$ANDROID_HOME/tools to your PATH, per
https://facebook.github.io/react-native/docs/getting-started.html .
To run on your Android device, make sure USB debugging is enabled; see
these
instructions. Then
plug in your device via USB and tap 'OK' on the 'Allow USB debugging?'
prompt if it appears. After that, adb devices should list your
device. If it says 'unauthorized' next to your device, then you likely
haven't tapped 'OK' on the prompt yet. If you saw no prompt, try
revoking (https://stackoverflow.com/a/25546300/670659).
Turn off Instant Run
To turn off Instant Run go to Android Studio | Settings | Build, Execution, Deployment | Instant Run | Uncheck the box.
If you see the errors including Failed to execute aapt or transformDexWithInstantRunDependenciesApkForDebug the problem might be that Instant Run is enabled.
You need to port forward 8081 so react-native can react its packager.
On your computer run:
adb reverse tcp:8081 tcp:8081
To recap, you should have run:
adb devices (should list exactly one device)yarn rn-gobuild-androidyarn android-debugHappy developing!
can you see the packager in your computer's browser if you go to localhost:8081?
no -> You aren't runnning the packager, run yarn rn-start2
yes: can you see the packager in android's browser if you go to localhost:8081?
no -> You didn't port forward 8081 run adb reverse tcp:8081 tcp:8081
yes: Did you set debug server host & port to localhost:8081?
no:
localhost:8081 (See [#could-not-connect-to-development-server-error] for more info)yes: You're in uncharted territories. Try using the java debugger in android studio and setting a break point in react-native's BundleDownloader and reading the actual error since it might be more informative than rn's generic handler. After you fix it, come back and update this page!
yarn rn-build-clean-android
$HOME/.../Android/sdk/ndk-bundle Does not point to an Android NDKIf you're hitting this issue, it is because you either do not have an NDK installed or installed an NDK with an older version of Android Studio that created an old directory path.
Android Studio 3.5.0 and later seem to install ndk versions at the following path: ~/Library/Android/sdk/ndk/{version}
To resolve this issue, use the sdkmanager to re-install ndk-bundle at the correct directory path.
On Android 28 and above HTTP traffic is disabled by default which can block
Metro Bundler from running properly. We have manually allowed 127.0.0.1 to
have HTTP traffic, so if you see an error about connecting to the bundler
server you should manually change the dev server URL and then kill and restart
the app:
# Enable loopback
adb reverse tcp:8081 tcp:8081
# Additionally, if running storybook
adb reverse tcp:7007 tcp:7007
127.0.0.1:8081react-devtools is running on:# React devtools standalone port
adb reverse tcp:8097 tcp:8097