【发布时间】:2018-11-23 17:35:28
【问题描述】:
在我的 React-Native Android 应用程序中设置 CodePush 时遇到问题。在我的仪表板上,它没有显示任何应用程序已下载或安装了更新。
注意:iOS 代码推送适用于此移动应用,但不适用于 Android。
我目前的 codePush 选项设置如下:
let codePushOptions = {
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
installMode: codePush.InstallMode.ON_NEXT_RESUME
};
我做过的事情:
-
在您的
android/settings.gradle文件中,添加以下内容:包括 ':app', ':react-native-code-push' project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
-
在您的
android/app/build.gradle文件中,添加:react-native-code-push项目作为编译时依赖项:... 依赖{ ... 编译项目(':react-native-code-push') }
-
在您的
android/app/build.gradle文件中,将codepush.gradle文件添加为react.gradle下面的附加构建任务定义:... 申请自:“../../node_modules/react-native/react.gradle” 申请自:“../../node_modules/react-native-code-push/android/codepush.gradle” ...
-
如果您要将 Code Push 集成到 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 文件的图片
我知道还有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));
【问题讨论】:
-
您能在仪表板中看到更新吗?
-
你能分享你的 index.js
-
@AshwinMothilal 更新在仪表板上,只有 iOS 设备列为已下载
-
@AnuragChutani 我已经更新了我的问题以在底部发布 index.js。我想重申 iOS Codepush 的工作。只是不是安卓。
-
尝试在点击按钮后立即使用安装模式 codePush.sync({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE });
标签: android react-native react-native-android react-native-code-push