廢話很少說,直接開始正文了!java
參考文章:react
1.安裝code-push github
npm install -g code-push-cli
2.註冊code-push帳號shell
code-push register
具體的步驟,請參考上文的第一篇文章
express
好的,如今能夠註冊一個App到code-push了npm
code-push app add CodePushDemo
以下圖:react-native
Staging是默認的部署名,記下它的Key值,下邊會用到。
如今,須要修改react-native項目了。
1.添加react-native code-push插件
npm install react-native-code-push --save
2.android配置
a.編輯android/setting.gradle文件,如圖:
b.編輯android/app/builde.gradle文件,添加依賴。(注意:這裏還須要將defaultConfig->versionName改成1.0.0這種三個數字的格式)如圖:
c.修改android入口文件,MainActivity.java,添加CodePush包,注意,這裏這裏的配置方法會根據react-native版本的不一樣而不一樣,
個人版本是0.22,具體的參考官方文檔
d.修改javaScript代碼
componentDidMount() { CodePush.sync({ deploymentKey: "KGezOzb8AKHW1KSoRD46lvb7cH5SVycRHYbAe", updateDialog: { optionalIgnoreButtonLabel: '稍後', optionalInstallButtonLabel: '後臺更新', optionalUpdateMessage: 'Reading有新版本了,是否更新?', title: '更新提示' }, installMode: CodePush.InstallMode.ON_NEXT_RESTART }); }
以上,code-push就算是配置萬成了。下面就是如何更新app
第一步,package命令
cd CodePushReact
react-native bundle --platform android --entry-file index.android.js --bundle-output ./release/main.jsbundle --assets-dest ./release --dev false //完成後,會在項目根目錄下生成release文件夾,可是後來我把這個刪掉,直接運行下面的命令,同樣可行,彷佛無關緊要,有大神能夠在評論裏告訴我嗎?
code-push release-react Usage: code-push release-react <appName> <platform> [options] Options: --bundleName, -b Name of the generated JS bundle file. If unspecified, the standard bundle name will be used, depending on the specified platform: "main.jsbundle" (iOS) and "index.android.bundle" (Android) [string] [default: null] --deploymentName, -d Deployment to release the update to [string] [default: "Staging"] --description, --des Description of the changes made to the app with this release [string] [default: null] --development, --dev Specifies whether to generate a dev or release build [boolean] [default: false] --disabled, -x Specifies whether this release should be immediately downloadable [boolean] [default: false] --entryFile, -e Path to the app's entry Javascript file. If omitted, "index.<platform>.js" and then "index.js" will be used (if they exist) [string] [default: null] --mandatory, -m Specifies whether this release should be considered mandatory [boolean] [default: false] --rollout, -r Percentage of users this release should be immediately available to [string] [default: "100%"] --sourcemapOutput, -s Path to where the sourcemap for the resulting bundle should be written. If omitted, a sourcemap will not be generated. [string] [default: null] --targetBinaryVersion, -t Semver expression that specifies the binary app version(s) this release is targetting (e.g. 1.1.0, ~1.2.3). If omitted, the release will target the exact version specified in the "Info.plist" (iOS) or "build.gradle" (Android) files. [string] [default: null] Examples: release-react MyApp ios Releases the React Native iOS project in the current working directory to the "MyApp" app's "Staging" deployment release-react MyApp android -d Production Releases the React Native Android project in the current working directory to the "MyApp" app's "Production" deployment
code-push release-react CodePushReact android -t "1.0.0" --des "asd" -m true
到此結束!疑問一大堆啊!