casper's Profile Image

Full Stack Web/Mobile Developer

Dec, 15, 2024

How To Run React Native App On Physical Android Device

You can run your react native app on your android device with a few easy steps.

How To Run React Native App On Physical Android Device Image

Configure Your App for Release

To generate a release APK, you need to configure your app’s release settings.

Create a Keystore (for signing the APK):

Open a terminal and run the following command to generate a keystore:

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

Store the my-release-key.keystore file in your React Native project’s android/app directory.

Update gradle.properties: Add your keystore information to android/gradle.properties:

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=<your-keystore-password>
MYAPP_RELEASE_KEY_PASSWORD=<your-key-password>

Configure build.gradle: Update the android/app/build.gradle file to reference your keystore. In the android section, make sure the signing configurations are set:

android {
    ...
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

signingConfigs {
    release {
        storeFile file(MYAPP_RELEASE_STORE_FILE)
        storePassword MYAPP_RELEASE_STORE_PASSWORD
        keyAlias MYAPP_RELEASE_KEY_ALIAS
        keyPassword MYAPP_RELEASE_KEY_PASSWORD
    }
}

Build the APK: Now, run the following command to generate the release APK:

cd android
./gradlew assembleRelease

Find the APK: After the build completes, you will find the generated APK in the following directory:

android/app/build/outputs/apk/release/app-release.apk

Install the APK on Your Android Device:

  • Enable Developer Options and USB Debugging on your Android phone.

  • Connect your device to your computer via USB.

  • Run the following command to install the APK on your device:

adb install android/app/build/outputs/apk/release/app-release.apk

Alternatively, you can manually transfer the APK to your phone and install it by opening the APK file on your device.

You can also use the generated apk to publish your app on Google Play Store.

0
0

Comments (0)