android - 更新到 React 0.60.4 会破坏 Android 构建(错误找不到符号)

标签 android reactjs react-native gradle

我最近更新到 React Native@0.60.4

该应用程序在 iOS 和 xcode 上编译并运行良好。但是,当我尝试运行新的 android 代码时,我遇到了以下错误:

/redacted/MainApplication.java:6: error: cannot find symbol
import com.facebook.react.PackageList;
                         ^
  symbol:   class PackageList
  location: package com.facebook.react
/redacted/MainApplication.java:28: error: cannot find symbol
      List<ReactPackage> packages = new PackageList(this).getPackages();
                                        ^
  symbol: class PackageList
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.

这是我的 MainApplication.java

package com.my.app;

import android.app.Application;
import android.util.Log;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;

import com.facebook.soloader.SoLoader;

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

$ npx react-native info 转储

System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    Memory: 288.14 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.4.0 - /usr/local/bin/node
    Yarn: 1.17.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.4

最佳答案

事实证明,当我使用 https://react-native-community.github.io/upgrade-helper/?from=0.59.8&to=0.60.4 时,我错过了 android/app/build.gradle 中的新内容

android/app/build.gradle 文件被关闭了,我错过了

关于android - 更新到 React 0.60.4 会破坏 Android 构建(错误找不到符号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57166876/

相关文章:

android - 如何使用android应用程序控制在linux PC上运行的程序?

reactjs - Cypress 在我的 ts 文件旁边添加了 js 文件

javascript - 为什么每次我的标题渲染都使用了 React.memo?

javascript - react 原生中可能出现未处理的 promise 拒绝

module - 有人开始创建 React Native API/插件/模块了吗?

react-native - 结合 TabNavigator 和 Drawernavigator

android - ProcessException:aapt完成,退出值非零2

android - 如何使用 Retrofit 刷新 lambda API 生成的 token ?

android - Linux 中带有许可证的 Flutter 安装错误

javascript - React - Babel 不转译文件