【问题标题】:How to resolve android compile error 'cant find symbol' from react-native-code-push如何从 react-native-code-push 解决 android 编译错误“找不到符号”
【发布时间】:2020-11-10 16:30:38
【问题描述】:

不知道这里有什么问题。在 Microsoft appcenter 上构建/分发时,构建没有问题。我记得在成功构建后与代码推送相关的唯一一件事就是向 build.gradle 添加不同的部署密钥:

buildTypes {
        debug {
            signingConfig signingConfigs.debug
            // Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
            // specifically left blank in appcenter docs
            resValue "string", "CodePushDeploymentKey", '""'
        }
        releaseStaging {
            resValue "string", "CodePushDeploymentKey",  '"<key>"'

            // Note: It is a good idea to provide matchingFallbacks for the new buildType you create to prevent build issues
            // Add the following line if not already there
            matchingFallbacks = ['release']
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            // signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            resValue "string", "CodePushDeploymentKey", '"<key>"'
        }
    }

现在当我尝试从 android studio 中构建时,我收到此错误:

> Task :react-native-code-push:javaPreCompileDebug UP-TO-DATE

> Task :react-native-code-push:compileDebugJavaWithJavac FAILED
/Users/vorousjames/Desktop/Development/Slide/Slide/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java:157: error: cannot find symbol
                isLiveReloadEnabled = devInternalSettings.isReloadOnJSChangeEnabled();
                                                         ^
  symbol:   method isReloadOnJSChangeEnabled()
  location: variable devInternalSettings of type DevInternalSettings
/Users/vorousjames/Desktop/Development/Slide/Slide/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java:175: warning: [unchecked] unchecked cast
        List<ReactRootView> mAttachedRootViews = (List<ReactRootView>)mAttachedRootViewsField.get(instanceManager);
                                                                                                 ^
  required: List<ReactRootView>
  found:    Object
1 error
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-code-push:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

是什么导致了这个问题以及如何解决这个问题?

【问题讨论】:

    标签: android react-native react-native-android visual-studio-app-center react-native-code-push


    【解决方案1】:
    1. 将导入保存在 MainApplication.java

      导入 com.microsoft.codepush.react.CodePush;

    2. 保留 覆盖 getJSBundleFile 方法。

    3. 删除 buildConfigFields 并更新为这种格式

      resValue "string",

    reactNativeCodePush_androidDeploymentKey”,'"&lt;INSERT_PRODUCTION_KEY&gt;"'

    1. strings.xml 中删除密钥(如果已在其中添加)。

    关注所有细节here的提交

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2013-01-15
      • 2022-08-04
      • 1970-01-01
      • 1970-01-01
      • 2023-02-13
      • 2011-04-23
      相关资源
      最近更新 更多