React Native Tech Blog

supported by maricuru (旧maricuru tech blogです)

【Expo】【React Native】productionとstagingを分けて配布したい

異なるバージョンのアプリケーションを配布したい、
たとえばproductionとstaging環境があって、productionユーザーに届ける前に、stagingで動作確認したい、といった状況はよくあると思います。

こういった場合に対応するため、Expoでは"Release Channel"という仕組みが用意されています。

f:id:wasan:20180415220804p:plain

Release Channelを指定してpublishする

以下のようなコマンドでpublishします。

exp publish --release-channel <your-channel>

https://exp.host/@username/yourApp?release-channel=<your-channel>のようなURLにJSバンドルが反映されます。

Release Channelを指定してビルドする

先ほどpublishしたChannelと紐づくビルドを作成します。
こちらも先ほど同様に、オプションを指定してあげればOKです。

exp build:ios --release-channel <your-channel>
exp build:android --release-channel <your-channel>

Release Channelsで処理を変えたい場合

今どのRelease Channelsなのかをコードからも知ることができます。
Expo.Constants.manifest.releaseChannelという変数に格納されています。

if(Expo.Constants.manifest.releaseChannel === 'production'){
  // productionの場合
}else if(Expo.Constants.manifest.releaseChannel === 'staging'){
  // stagingの場合
}

ちなみにdevelopmentかどうかの判定はReact Nativeの__DEV__で判定できます。