Last active
April 6, 2024 21:22
-
-
Save jamesob/25ac7fd62d05dc66fec5818a5f37d0f7 to your computer and use it in GitHub Desktop.
Getting to Android and react-native development in Arch Linux (2024)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This (very scant) guide allows you to do Android and react-native development on Linux by | |
# running the android emulator in a container. | |
# install yay via AUR | |
git clone https://aur.archlinux.org/yay.git && cd yay && makpkg -si | |
# install all android dev packages per https://wiki.archlinux.org/title/Android | |
yay -Sy android-sdk-cmdline-tools-latest android-sdk-build-tools android-sdk-platform-tools android-platform | |
# add to .zshrc | |
if [ -d /opt/android-sdk ]; then | |
export ANDROID_HOME='/opt/android-sdk' | |
export PATH=${PATH}:"$ANDROID_HOME/tools/bin/" | |
export PATH=${PATH}:"$ANDROID_HOME/platform-tools/" | |
export PATH=${PATH}:"$ANDROID_HOME/cmdline-tools/latest/bin" | |
export PATH=${PATH}:"$ANDROID_HOME/emulator" | |
fi | |
# restart shell | |
cd /opt/android-sdk | |
./tools/bin/sdkmanager 'platforms;android-34' | |
# Unfortunately, we need jdk-8 to sign the licenses, but we need jdk-17 to actually run react-native. | |
# So flip back and forth. | |
sudo pacman -Sy jre8-openjdk | |
sudo archlinux-java set java-8-openjdk/jre | |
# Sign the licenses | |
sdkmanager --licenses | |
sudo pacman -Sy jdk17-openjdk | |
# The "--network" flag is critical to allowing the react dev server | |
# to be accessed by the emulator container. Otherwise you'll get "couldn't hit dev server" errors. | |
docker run -d --network host \ | |
-e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true \ | |
--device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0 | |
adb connect $(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' android-container):5555 | |
# ensure connection | |
adb devices -l | |
# Create the react app | |
npx react-native@latest init YOUR_PROJECT | |
cd YOUR_PROJECT | |
npm start | |
# in another terminal | |
npm start android | |
# Open the emulator interface | |
open http://localhost:6080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment