How do you generate an APK or IPA file in React Native?

Generating an APK (Android) & IPA (iOS) in React Native

To distribute your React Native app, you need to generate an APK (Android) or IPA (iOS) file. Below is a step-by-step guide for both platforms.


Generating an APK (Android)

You can generate an APK using either React Native CLI or Expo.


1. Using React Native CLI (Bare Workflow)
Step 1: Prepare Your App for Release
  • Open android/app/build.gradle
  • Change:
    signingConfig signingConfigs.debug
    
    To:
    signingConfig signingConfigs.release
    
Step 2: Generate a Keystore (For Signing)

Run this command in the android folder:

keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

? This will create a my-release-key.keystore file.

Move it to android/app/.

Step 3: Add Keystore Information

Edit android/gradle.properties and add:

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=your-password
MYAPP_RELEASE_KEY_PASSWORD=your-password
Step 4: Build the APK

Run:

cd android
./gradlew assembleRelease

* Your APK is generated at:
android/app/build/outputs/apk/release/app-release.apk


2. Using Expo (Managed Workflow)

Expo makes it easier to generate an APK.

Step 1: Install Expo CLI
npm install -g expo-cli
Step 2: Build the APK
eas build -p android --profile production

* Expo will generate the APK and provide a download link.


Generating an IPA (iOS)

iOS apps require a Mac and an Apple Developer Account.

1. Using React Native CLI
Step 1: Install Xcode & CocoaPods
sudo gem install cocoapods
cd ios
pod install
Step 2: Archive the App in Xcode
  1. Open ios/App.xcworkspace in Xcode.
  2. Select Generic iOS Device or a real iPhone.
  3. Go to Product > Archive.
  4. After archiving, click Distribute App to export the .ipa file.
2. Using Expo
Step 1: Install Expo CLI
npm install -g expo-cli
Step 2: Build the IPA
eas build -p ios --profile production

Expo will generate an .ipa file and provide a link.