3

我在将 CodePush 设置到我的 React-Native Android 应用程序中时遇到问题。在我的仪表板上,它没有显示任何应用程序已下载或安装更新。

注意:iOS 代码推送适用于此移动应用程序,但不适用于 Android。

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

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

我做过的事情:

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

    包括 ':app', ':react-native-code-push' project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code -推/安卓/应用程序')

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

    ... 依赖项 { ... 编译项目(':react-native-code-push') }

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

    ...申请自:“../../node_modules/react-native/react.gradle”申请自:“../../node_modules/react-native-code-push/android/codepush.gradle”。 ..

  4. 如果您要将 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 文件的图片

在此处输入图像描述


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

我也不太确定这是什么:

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));
4

1 回答 1

0

我将以下内容添加到我的 android/app/build.gradle 中,它可以作为一种解决方法。我猜这可能是一个 android gradle 插件问题。AGP 4.1+ 中似乎有一堆未记录的重大更改会影响 React Native。

在 android { defaultConfig { 我添加了

resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())

于 2022-01-24T03:34:43.803 回答