Skip to main content

Android Setup

In order to integrate CodePush into your Android project, please perform the following steps:

  1. In your android/app/build.gradle file, add this line at the end of the file:
apply from: "../../node_modules/@turbopush/react-native-code-push/android/codepush.gradle"
  1. Update the MainApplication file to use CodePush via the following changes:

    For React Native 0.76 and above: update the MainApplication.kt

    import com.facebook.react.ReactHost
    import com.facebook.soloader.SoLoader
    import com.microsoft.codepush.react.CodePush

    class MainApplication : Application(), ReactApplication {
    override val reactNativeHost: ReactNativeHost =
    object : DefaultReactNativeHost(this) {
    override fun getJSBundleFile(): String {
    return CodePush.getJSBundleFile()
    }
    };

    override fun onCreate() {
    super.onCreate()
    val deploymentKey = getString(R.string.CodePushDeploymentKey)
    CodePush.getInstance(deploymentKey, this, BuildConfig.DEBUG)
    loadReactNative(this)
    }
    }
  2. Add the CodePushDeploymentKey key (generated in the create app step) in the file android/app/src/main/res/values/strings.xml

<string name="CodePushDeploymentKey">YOUR_ANDROID_DEPLOYMENT_KEY</string>
tip

npx turbopush deployment list -a <appName> -k
to get the deployment key for your app.

note

If you need to dynamically use a different deployment, you can also override your deployment key in JS code using options.

Code Signing setup (optional)

Starting with CLI version 2.1.0 you can self sign bundles during release and verify its signature before installation of update. For more info about Code Signing please refer to relevant documentation section. In order to use Public Key for Code Signing you need to do following steps:

Add CodePushPublicKey string item to /path_to_your_app/android/app/src/main/res/values/strings.xml. It may looks like this:

<resources>
<string name="app_name">my_app</string>
<string name="CodePushPublicKey">-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtPSR9lkGzZ4FR0lxF+ZA
P6jJ8+Xi5L601BPN4QESoRVSrJM08roOCVrs4qoYqYJy3Of2cQWvNBEh8ti3FhHu
tiuLFpNdfzM4DjAw0Ti5hOTfTixqVBXTJPYpSjDh7K6tUvp9MV0l5q/Ps3se1vud
M1/X6g54lIX/QoEXTdMgR+SKXvlUIC13T7GkDHT6Z4RlwxkWkOmf2tGguRcEBL6j
ww7w/3g0kWILz7nNPtXyDhIB9WLH7MKSJWdVCZm+cAqabUfpCFo7sHiyHLnUxcVY
OTw3sz9ceaci7z2r8SZdsfjyjiDJrq69eWtvKVUpredy9HtyALtNuLjDITahdh8A
zwIDAQAB
-----END PUBLIC KEY-----</string>
</resources>