废话很少说,直接开始正文了!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
到此结束!疑问一大堆啊!