React-Native android CodePush设置未下载更新

时间:2018-11-23 17:35:28

标签: android react-native react-native-android react-native-code-push

我无法在我的React-Native Android应用程序中设置CodePush。在我的仪表板上,没有显示任何应用程序已下载或安装了更新。

注意:iOS Codepushing可以在此移动应用程序上使用,而不能在android系统上使用。

我目前已将我的codePush选项设置如下:

let codePushOptions = { 
   checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
   installMode: codePush.InstallMode.ON_NEXT_RESUME
};

我所做的事情:

1)在您的android/settings.gradle文件中,添加以下内容:

include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

2)在android/app/build.gradle文件中,将:react-native-code-push项目添加为编译时依赖项:

...
dependencies {
    ...
    compile project(':react-native-code-push')
}

3)在android/app/build.gradle文件中,将codepush.gradle文件添加为react.gradle下的附加构建任务定义:

...
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
...

4)如果要将代码推送集成到React Native应用程序中,请执行以下步骤:

通过以下更改将MainApplication.java文件更新为使用CodePush:

...
// 1. Import the plugin class.
import com.microsoft.codepush.react.CodePush;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        ...
        // 2. Override the getJSBundleFile method in order to let
        // the CodePush runtime determine where to get the JS
        // bundle location from on each app start
        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }

        @Override
        protected List<ReactPackage> getPackages() {
            // 3. Instantiate an instance of the CodePush runtime and add it to the list of
            // existing packages, specifying the right deployment key. If you don't already
            // have it, you can run "code-push deployment ls <appName> -k" to retrieve your key.
            return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new CodePush("deployment-key-here", MainApplication.this, BuildConfig.DEBUG)
            );
        }
    };
}

这是我的MainApplication.java文件的图片

enter image description here


我知道还有this portion条设置说明,我不知道是否需要这样做。我尝试实现它,但由于出现了错误,因为此代码与文件中的示例文档完全不一样。

我不太确定这是什么:

public class MyReactNativeHost extends ReactNativeHost implements ReactInstanceHolder {
  // ... usual overrides
}

编辑2-index.js文件

import { AppRegistry } from 'react-native';
import codePush from "react-native-code-push";

import App from './app/config/app';

let codePushOptions = { 
    checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
    installMode: codePush.InstallMode.ON_NEXT_RESUME
};

AppRegistry.registerComponent('AppName', () => codePush(codePushOptions)(App));

任何帮助将不胜感激。

0 个答案:

没有答案