MainApplication.java 上的 React-Native-Reanimated 错误

Posted

技术标签:

【中文标题】MainApplication.java 上的 React-Native-Reanimated 错误【英文标题】:React-Native-Reanimated error at MainApplication.java 【发布时间】:2020-10-12 08:03:47 【问题描述】:

伙计们

我正在尝试安装 react-native-reanimated,但我不断收到此错误。

C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\main\java\com\tracker\MainApplication.java:17: error: cannot find symbol
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
                               ^
  symbol:   class ReanimatedJSIModulePackage
  location: package com.swmansion.reanimated
C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\main\java\com\tracker\MainApplication.java:45: error: cannot find symbol
          return new ReanimatedJSIModulePackage();
                     ^

这是完整的日志错误

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1372 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Installing the app...

> Task :@mauron85_react-native-background-geolocation-common:compileDebugJavaWithJavac

> Task :mauron85_react-native-background-geolocation:compileDebugJavaWithJavac

> Task :react-native-camera:compileGeneralDebugJavaWithJavac

> Task :react-native-community_async-storage:compileDebugJavaWithJavac

> Task :react-native-gesture-handler:compileDebugJavaWithJavac

> Task :react-native-geolocation-service:compileDebugJavaWithJavac

> Task :react-native-maps:compileDebugJavaWithJavac

> Task :react-native-reanimated:compileDebugJavaWithJavac

> Task :react-native-screens:compileDebugJavaWithJavac

> Task :app:compileDebugJavaWithJavac

> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
210 actionable tasks: 210 executed
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-camera\android\src\main\java\com\google\android\cameraview\Camera2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\@react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-geolocation-service\android\src\main\java\com\agontuk\RNFusedLocation\LocationUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-reanimated\android\src\main\java\com\swmansion\reanimated\NodesManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-reanimated\android\src\main\java\com\swmansion\reanimated\NodesManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\main\java\com\tracker\MainApplication.java:17: error: cannot find symbol
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
                               ^
  symbol:   class ReanimatedJSIModulePackage
  location: package com.swmansion.reanimated
C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\main\java\com\tracker\MainApplication.java:45: error: cannot find symbol
          return new ReanimatedJSIModulePackage();
                     ^
  symbol: class ReanimatedJSIModulePackage
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\debug\java\com\tracker\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
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 3m 12s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-camera\android\src\main\java\com\google\android\cameraview\Camera2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\@react-native-community\async-storage\android\src\main\java\com\reactnativecommunity\asyncstorage\AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-geolocation-service\android\src\main\java\com\agontuk\RNFusedLocation\LocationUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-reanimated\android\src\main\java\com\swmansion\reanimated\NodesManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\react-native-reanimated\android\src\main\java\com\swmansion\reanimated\NodesManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\main\java\com\tracker\MainApplication.java:17: error: cannot find symbol
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
                               ^
  symbol:   class ReanimatedJSIModulePackage
  location: package com.swmansion.reanimated
C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\main\java\com\tracker\MainApplication.java:45: error: cannot find symbol
          return new ReanimatedJSIModulePackage();
                     ^
  symbol: class ReanimatedJSIModulePackage
Note: C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\android\app\src\debug\java\com\tracker\ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
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 3m 12s

    at makeError (C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\execa\index.js:174:9)
    at C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\execa\index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async runOnAllDevices (C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
    at async Command.handleAction (C:\Users\danilojldeo\Desktop\MeuGithub\controle-de-pragas\node_modules\@react-native-community\cli\build\index.js:186:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

错误似乎在MainApplication.java中,所以这里是文件代码:

package com.tracker;

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.ocetnik.timer.BackgroundTimerPackage;
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 com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.bridge.JSIModulePackage;
import java.util.List;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;

public class MainApplication extends Application implements ReactApplication 
  static 
    ReactFeatureFlags.useTurboModules = true;
  
  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
        protected JSIModulePackage getJSIModulePackage() 
          return new ReanimatedJSIModulePackage();
        
      ;

  @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.tracker.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();
      
    
  

这是我安装 react-native-reanimated 的步骤 -> https://docs.swmansion.com/react-native-reanimated/docs/installation/ 在这个安装文档中,它说我必须安装它

yarn add react-native-reanimated@alpha

但是,实际上,我正在尝试安装,以便可以将它与 createDrawerNavigator (react-navigation 5) 和 react-native-gesture 处理程序一起使用,所以我也按照这些步骤安装了 https://reactnavigation.org/docs/getting-started。在这个文档中,它安装了 react-native-reanimated,而不是 react-native-reanimated@alpha。 如果我安装 react-native-reanimated@alpha,则项目构建正常!但后来我收到了这个错误,我在另一个问题中发布了 createDrawerNavigator createDrawerNavigator | undefined is not a function 但是如果我安装 react-native-reanimated,项目不会构建,它会得到我在这个问题顶部所说的错误。 我相信这两个错误是有关联的。

有人可以帮帮我吗?

这里是项目依赖:

"dependencies": 
    "@mauron85/react-native-background-geolocation": "^0.6.3",
    "@react-native-community/async-storage": "^1.9.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/drawer": "^5.8.2",
    "@react-navigation/material-bottom-tabs": "^5.1.6",
    "@react-navigation/native": "^5.5.1",
    "@react-navigation/stack": "^5.0.6",
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-action-button": "^2.8.5",
    "react-native-animatable": "^1.3.3",
    "react-native-background-timer": "^2.2.0",
    "react-native-camera": "git+https://git@github.com/react-native-community/react-native-camera.git",
    "react-native-geolocation-service": "^5.0.0",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-maps": "^0.27.1",
    "react-native-paper": "^3.6.1",
    "react-native-reanimated": "^1.9.0",
    "react-native-safe-area-context": "^3.0.5",
    "react-native-screens": "^2.9.0",
    "react-native-vector-icons": "^6.6.0",
    "rn-fetch-blob": "^0.12.0"
  ,

【问题讨论】:

【参考方案1】:

已修复!

我所要做的就是安装 react-native-reanimated 而不是执行文档显示的手动步骤。 似乎那里显示了 react-native-reanimated@alpha(版本 2.x.x)的步骤,看起来它仍然无法正常工作,特别是使用 createDrawerNavigation。

yarn add react-native-reanimated@alpha //NO
yarn add react-native-reanimated //YES

【讨论】:

对于 NPM USER 使用 npm install react-native-reanimated 谢谢它似乎也对我有用!令人难以置信的是,Reanimated 2 的记录如此糟糕。【参考方案2】:

当我用yarn add react-native-reanimated@next安装它时,我得到了同样的错误,因为没有指定要安装的具体版本。

通过运行npm ls react-native-reanimated@nextnpm,您可以选择要安装的版本,例如我最新的版本是 2.0.0-rc.3。清理并重建项目。

【讨论】:

以上是关于MainApplication.java 上的 React-Native-Reanimated 错误的主要内容,如果未能解决你的问题,请参考以下文章

无法运行 react-native-background-task。将代码插入 MainApplication.java 时出错

嗨,我对 React Native Firebase 有疑问

当我尝试实现身份验证时出现 Firebase.app() 错误

react-native修改android包名

react-native修改android包名

反应本土:错误:无法找到升级后的符号