How to Build apk in react native

How to Generate a React Native Release Build APK for Android in react native
How to Generate a React Native Release Build APK for Android

07 Apr 2020

Follow This STEP TO Build Apk for android In Your Project Directory RUN Below Commands 

STEP 1: (Generate Release Key)

You may like these posts


keytool -genkey -v -keystore mykeystore.keystore -alias mykeyalias -keyalg RSA -keysize 2048 -validity 10000


STEP 2:
Now Move Above Created Key to This Path: android\app
Than Go To This Path: android/gradle.properties  Paste Below Line

MYAPP_RELEASE_STORE_FILE=mykeystore.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=your_key_password
MYAPP_RELEASE_KEY_PASSWORD=your_key_password

STEP 3:
Add signing config to This Path: android/app/build.gradle

android {

signingConfigs {
        
         debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }

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


buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.

            
            minifyEnabled true                               // For Less Apk Size (Optional)
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release               //Add This Line
        }
    }
}


STEP 4:

Now Time To Generate an Apk
Go to Android Directory

cd android && ./gradlew assembleRelease 

STEP 5: 

After Following Step 4 Completion Your Apk is Generated in This Path Check Out

Path:   android\app\build\outputs\apk\debug\app-debug.apk


Note: If You want to Re-generate an apk Again First You need to clean Gradle using this Command

1. cd android &&./gradlew clean              //For Clean a Gradle

2. cd .. && npx react-native run-android

how to build apk in react native
Add caption