CodePush iOS與Android完美集成

1、環境準備

ps:命令在終端默認目錄下java

1.安裝Code-push cli   --      $ npm install -g code-push-clireact

2.註冊CodePush帳戶  --     $ code-push register (點擊彈出的網頁的github註冊,記錄好返回的access token)android

3.終端輸入access token  ios

4.添加CodePush應用  --  $ code-push app add XXX  //xxx   爲你要熱部署的app namegit

    成功後咱們能夠看到有兩個發佈鍵值。一個Production是對應生產環境的,二Staging是對應開發環境的github

│ Name       │ Deployment Key                        │
├────────────┼───────────────────────────────────────┤
│ Production │ xxxxx │
├────────────┼───────────────────────────────────────┤
│ Staging    │ xxxxx

 

2、集成code-push 到工程文件

ps:之後命令在項目的根目錄下npm

1.在應用中安裝react-native插件 -- npm install --save react-native-code-pushreact-native

2.npm i rnpm服務器

3.rnpm link react-native-code-pushapp

4.命令行這個時候須要輸入咱們以前得到的key,相應輸入,便可配置完環境(注意這裏要選擇是正式版的key--Production仍是測試版的key--Staging,不是發佈到appstore能夠用Staging的key)

5.xocde -> info.plist ->  Bundle versions string, short   以及 studio -> build.gradle -> versionName 均將1.0 改成1.0.0

6.在studio的MainApplication.java還須要另外加上staging

import com.microsoft.codepush.react.CodePush;

public class MainApplication extends Application implements ReactApplication {
        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
//*************只改動這裏,添加這行代碼 ******************/
                new CodePush("你的staging", MainApplication.this, BuildConfig.DEBUG)
//*******************************/
            );
        }
    };
}

7.js入口處 加上 

import codePush from "react-native-code-push";

//後臺自動下載更新,從新進入app的時候更新
  componentDidMount(){
    codePush.sync();
  }

//點擊肯定的時候 更新
    codePush.sync({ 
      updateDialog: true, 
      installMode: codePush.InstallMode.IMMEDIATE 
    });

 

 

3、測試

ps:如下命令均在工程根目錄下:

   1. react-native bundle --platform(platform) --entry-file (入口) --bundle-output codepush.js --dev false

模板:
react-native bundle --platform android --entry-file index.android.js --bundle-output codepush.js --dev false

react-native bundle --platform ios --entry-file index.ios.js --bundle-output codepush.js --dev false

    2.code-push release(項目名稱) codepush.js (版本號)

模板:
簡單:code-push release MyProject codepush.js 1.0.0

默認生產環境: mandatory表明是否強制更新
code-push release MyProject codepush.js 1.0.0 --mandatory true

生產環境:
code-push release MyProject codepush.js 1.0.0 -d "Production" --mandatory true

當咱們須要給用戶測試的時候,能夠先測試環境下發布給多少人更新,而後再正式版更新
1)有多少百分比的人能收到更新:  rollout表明百分比
code-push release MyProject codepush.js 1.0.0 --rollout 20
2)code-push release MyProject codepush.js 1.0.0 -d "Production" --mandatory true
3)code-push promote <appName> <sourceDeploymentName> <destDeploymentName> //promote copy文件服務器的意思

 

4、CodePush經常使用命令

  • code-push login 登錄
  • code-push loout 註銷
  • code-push access-key ls 列出登錄的token
  • code-push access-key rm <accessKye> 刪除某個 access-key

CodePush經常使用與項目的命令:

ps:code-push app add XXX

  • add 在帳號裏面添加一個新的app
  • remove 或者 rm 在帳號裏移除一個app
  • rename 重命名一個存在app
  • list 或則 ls 列出帳號下面的全部app
  • transfer 把app的全部權轉移到另一個帳號
  • deployment history <appName> <deploymentName> 查看歷史版本
  • code-push rollback <appName> <deploymentName> 回滾上一次版本

5、studio在mac安裝踩過的坑

1.「Could not get BatchedBridge, make sure your bundle is packaged properly」

http://stackoverflow.com/questions/38870710/error-could-not-get-batchedbridge-make-sure-your-bundle-is-packaged-properly

2.Gradle build-info.xml not found for module app. Please make sure that you are using gradle plugin '2.0.0-alpha4' or higher.

http://blog.csdn.net/my_chen_suo_zhang/article/details/51469001

相關文章
相關標籤/搜索