12

I'm trying to configure my RN android project according to this section of the react-native-code-push docs

My build.gradle file has this configuration:

buildTypes {
        debug {
        }
        releaseStaging {
            buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING
        }
        release {
            buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_PRODUCTION
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }

but when i run: react-native run-android --variant releaseStaging

I get the error: Task 'installReleaseStagingDebug' not found in root project 'MyAppName'.

Also tried running react-native run-android --configuration releaseStaging

Which gave me a slightly better error:

Task 'installReleaseStaging' not found in root project 'MyAppName'. Some candidates are: 'uninstallReleaseStaging'.

Any idea what i'm missing?
Thanks!
Uri

Uri Klar
  • 3,800
  • 3
  • 37
  • 75

2 Answers2

24

You have to add signingConfig to the releaseStaging.

    releaseStaging {
        signingConfig signingConfigs.release
        buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING
    }

Then you can install it to your device. I have react-native version 0.38 so I installed it with react-native run-android --variant=releaseStaging , but this might be different for other react-native versions. If you have a newer version of react-native, you can do react-native run-android --configuration=releaseStaging instead.

jakobinn
  • 1,832
  • 1
  • 20
  • 20
-2

The Android Gradle plugin allows you to define custom config settings for each "build type" (e.g. debug, release)

To set this up, Modify android/app/build.gradle in standard React Native projects

android {
...
buildTypes {
    debug {
        ...
        // Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
        buildConfigField "String", "CODEPUSH_KEY", '""'
        ...
    }

    releaseStaging {
        ...
        buildConfigField "String", "CODEPUSH_KEY", '"<INSERT_STAGING_KEY>"'
        signingConfig signingConfigs.release
        ... 
    }

    release {
        ...
        buildConfigField "String", "CODEPUSH_KEY", '"<INSERT_PRODUCTION_KEY>"'
        signingConfig signingConfigs.release
        ...
    }
}
...

}

Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.

buildConfigField "String", "CODEPUSH_KEY", '""'

For latest react-native; you can build with

`react-native run-android --variant releaseStaging`
Rajan Maharjan
  • 4,398
  • 2
  • 16
  • 26
  • 1
    This does not answer the question and seems to be mostly just copied from the CodePush docs. – NiFi Sep 05 '18 at 07:50