android - 代码推送功能不适用于反应本机应用程序
问题描述
我是代码推送和本机反应的新手,我按照官方文档中给出的步骤- https://docs.microsoft.com/en-us/appcenter/distribution/codepush/react-native#getting-started,但即使将代码推送到 appcenter 后,它不会更新应用程序。请在下面找到必要的代码。
索引.js
import 'react-native-gesture-handler';
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import codePush from 'react-native-code-push';
let codePushOptions = {checkFrequency: codePush.CheckFrequency.ON_APP_START};
AppRegistry.registerComponent(appName, () => codePush(codePushOptions)(App));
MainApplication.java
package com.awesomeproject;
import com.microsoft.codepush.react.CodePush;
import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// // Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}
/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(
Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.awesomeproject.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
字符串.xml
<resources>
<string name="app_name">AwesomeProject</string>
<string moduleConfig="true" name="CodePushDeploymentKey">"I have added the deployment key here"</string>
</resources>
包.json
{
"name": "AwesomeProject",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/masked-view": "^0.1.7",
"@react-navigation/native": "^5.1.4",
"@react-navigation/stack": "^5.2.9",
"appcenter-cli": "^2.4.0",
"react": "16.11.0",
"react-native": "0.62.0",
"react-native-code-push": "^6.2.0",
"react-native-gesture-handler": "^1.6.1",
"react-native-paper": "^3.6.0",
"react-native-reanimated": "^1.7.1",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.4.0",
"react-native-vector-icons": "^6.6.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@react-native-community/eslint-config": "^1.0.0",
"babel-jest": "^25.2.4",
"eslint": "^6.8.0",
"jest": "^25.2.4",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "16.11.0"
},
"jest": {
"preset": "react-native"
}
}
Appcenter代码推送截图 Appcenter代码推送
请让我知道,如果还有什么需要。
解决方案
我得到了解决方案,在我发表这篇文章时,我有 React 本机版本 0.62 和代码推送仅支持本机版本 0.61 及以下版本。所以我只是将版本降级到 0.61,现在 codePush 工作正常。
推荐阅读
- python - 如何在数据框中创建列,其中包含受条件影响的标题列表,应用上限,然后排除不尊重条件标题
- c# - 使用 nunit 测试并行化
- node.js - 从控制台命令 nestjs 获取选项
- react-multi-carousel - 如何使用带有打字稿的 react-multi-carousel
- node.js - 在 NodeJS http.Agent 中干净地删除排队的 HTTP 请求
- python - 使用带有字符串的数据类
- c++ - 在 CMake Extension for VSCode 中运行 CMake Qt 项目时出现问题
- pyspark - Pyspark 替换嵌套结构字段中的空值
- python - 无法理解或将 Microsoft Graph API HTTP 请求转换为 python 请求
- sql - 获取日期列表中每个日期的工作日数