Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/artsoldi/tech.camefrom.space/wp-includes/functions.php on line 6114
Build standalone Android APK from react-native locally (with expo) - Tech from space

Build standalone Android APK from react-native locally (with expo)

My first React Native project (with expo) is now finished. Now I was wondering how can I compile an Android APK from React Native? You can find some tips and tricks online, but these articles refer to an online compilation to the expo server with subsequent publication. The articles that refer to local compilation are long and very detailed.

This guide is short and to the point. It doesn’t give you any background information but the spice for sure 😉 Let’s get started!

Requirements

  • macOS
  • npm or yarn
  • Java SDK 8
    Download from Oracle, alternatively you can find this version via Google.
  • javac in version 1.8.* must be available from CLI.
    I had to extend ~/.zshrc with export PATH="/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/bin:$PATH"
  • XCode from the App Store
    Make sure you agreed to the license after first opening and let XCode install all components.
    If XCode is installed but not linked, use: sudo xcode-select -r
  • After XCode & JDK 8 is installed: Install turtle-cli with npm install -g turtle-cli.

Prepare project for build

  • Generate key store. Replace my-upload-key and my-key-alias.
    keytool -genkeypair -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
  • Run turtle setup:android
  • Make sure to adjust your app.json and also have the “android” required properties:
{
  "expo": {
    ...
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      },
      "package": "com.company.name",
      "versionCode": 1
    }
  }
}

Build Android SDK

  • Export project as compiled version expo export --dev --public-url http://127.0.0.1:8000 --force
  • Run an instance of the project as a server npx http-server -p 8000 dist
  • When server is running build the Android APK with the following CLI command. Note that you exchange my-upload-key and my-key-alias again. Also you have to insert your set password in EXPO_ANDROID_KEYSTORE_PASSWORD and EXPO_ANDROID_KEY_PASSWORD.
EXPO_ANDROID_KEYSTORE_PASSWORD="YOUR-PASSWORD-SET-IN-KEYSTORE" \
EXPO_ANDROID_KEY_PASSWORD="YOUR-PASSWORD-SET-IN-KEYSTORE" \
turtle build:android \
  --type apk \
  --keystore-path ./my-upload-key.keystore \
  --keystore-alias "my-key-alias" \
  --allow-non-https-public-url \
  --public-url http://127.0.0.1:8000/android-index.json

Bundled Android APK

Now you should have a bundled Android APK. The APK is stored in ~/expo-apps/. You can transfer it to your smartphone and install it there. 🎉

Leave a Reply

Your email address will not be published. Required fields are marked *