Generating the Android APK

Building the Android Application Package (APK) is a bit more cryptic than releasing for iOS. There are a few steps that we need to follow before we generate the static bundle, like we did in iOS:

  1. First, we need to generate a key that we can use to sign our application using keytool. Navigate to the android/app folder in a terminal and run this command:
    $ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
    [Storing my-release-key.keystore]
    

    Note

    Note that this is a private file and should never be shared with anyone. Keep it somewhere safe!

  2. Next we have a few configuration files to update. Up a level in the android/ directory open gradle.properties and add these four lines, replacing YOUR_KEY_PASSWORD with the password you used for keytool:
    MYAPP_RELEASE_STORE_FILE=my-release-key.keystore MYAPP_RELEASE_KEY_ALIAS=my-key-alias MYAPP_RELEASE_STORE_PASSWORD=YOUR_KEY_PASSWORD
    MYAPP_RELEASE_KEY_PASSWORD= YOUR_KEY_PASSWORD
  3. Add the following in android/app/build.gradle:
    android {
        ...
    
        signingConfigs {
            release {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
        buildTypes {
            release {
                ...
                signingConfig signingConfigs.release
            }
        }
    }
  4. Now, we can generate the static bundle for Android. Create a new directory android/app/src/main/assets/ and run this modified form of the react-native bundle command:
    react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
    

    This gives the following output:

    $ react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
    Building package...
    transforming [========================================] 100% 326/326
    Build complete
    Successfully saved bundle to android/app/src/main/assets/index.android.bundle
    
  5. Build the final APK in the android/ directory using the gradle command:
    ./gradlew assembleRelease
    

    If you have set up the key signing correctly, you can test your release in the simulator or on a device with the following:

    ./gradlew installRelease
    
  6. With this, we have our final release APK (that can be found in android/app/build/outputs/apk/app-release.apk). Check out the launch checklist on Android developers for more information on the Play Store submission process at https://developer.android.com/distribute/tools/launch-checklist.html.
    Generating the Android APK
    Generating the Android APK
    Generating the Android APK
    Generating the Android APK
    Generating the Android APK
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.182.25