coinpayu

 
    You can simply able to solve your generated APK installation error in test devices or Android Emulator. The following worked for me: Lets see how to do it,

NOTE: you can simply drag and drop the Android apk to the emulator and it will automatically starts installing.



Generate a upload key


 keytool -genkeypair --storetype PKCS12 -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000  

Place the my-upload-key.keystore file under the android/app directory in your project folder. Then edit the file android/gradle.properties and add the following (replace **** with the correct keystore password, alias and key password)

 
    MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
    MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
    MYAPP_UPLOAD_STORE_PASSWORD=****
    MYAPP_UPLOAD_KEY_PASSWORD=****
 

Adding signing config to your app's Gradle config

In your app/build.gradle

...
android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...

Generating the release

Run the following in a terminal from root folder of your React Native Project

     
    cd android
    ./gradlew assembleRelease


NOTE: If ./gradlew assembleRelease is showing not your internal command. Just remove "./" and run gradlew assembleRelease only.

Which Build command line should I Use

assembleDebug

  • This builds an apk for your project using the debug variant.
  • This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/. The file is already signed with the debug key and aligned with zipalign, so you can immediately install it on a device.

installDebug

  • This builds an apk for your project using the debug variant and then installs it on a connected device
  • Or to build the APK and immediately install it on a running emulator or connected device, instead invoke installDebug.

assembleRelease

  • This creates a release apk of your app. You would then need to sign it using the command line or by setting the signing details in your build.gradle (see above instructions) and then you can install it on your device using adb.

bundleRelease

  • This creates a release aab, this is Google's preferred format for uploading to the Play Store.
  • Android App Bundles include all your app’s compiled code and resources, but defer APK generation and signing to Google Play. Unlike an APK, you can't deploy an app bundle directly to a device. So, if you want to quickly test or share an APK with someone else, you should instead build an APK.

installRelease

  • You will have to set up the signing above for this to work for a release build. It is the same as the installDebug but it creates a signed release variant and installs it on a connected device.

Usage

  • I use assembleRelease to build an apk that I want to share with other people.
  • I use installRelease when I want to test a release build on a connected device.
  • I use bundleRelease when I am uploading my app to the Play Store.
 
Before uploading the release build to the Play Store, make sure you test it thoroughly. First uninstall any previous version of the app you already have installed. Install it on the device using the following command in the project root: 

 
    npx react-native run-android --variant=release 
 

NOTES: --variant release is only available if you've set up signing as described above.

You can create an APK for each CPU by changing the following line in android/app/build.gradle:

 
    def enableSeparateBuildPerCPUArchitecture = false
    universalApk false  // If true, also generate a universal APK
 

Which is helpfull to upload your app without error on other App stores like Amazon AppStore and  APKFiles.

 See this final example APK HERE.

Thanks for reading this and leave your comments.