Search code examples
reactjsreact-nativeanimationnavigationnavigator

React-Native-Reanimated error at MainApplication.java


guys

I'm trying to install react-native-reanimated, but I keep getting this error.

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();
                     ^

Here is the full log error

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.

The error seems to be in MainApplication.java, so here is the file code:

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

Here is the steps I made to install react-native-reanimated -> https://docs.swmansion.com/react-native-reanimated/docs/installation/ In this installation doc, it says I have to install it with

yarn add react-native-reanimated@alpha

But, actually, I'm trying to install so I can use it with createDrawerNavigator (react-navigation 5) and react-native-gesture handler, so I installed following these steps too https://reactnavigation.org/docs/getting-started. In this doc, it install react-native-reanimated, not react-native-reanimated@alpha. If I install react-native-reanimated@alpha, the project builds ok! but later I get this error I posted in another question with createDrawerNavigator createDrawerNavigator | undefined is not a function But if I install react-native-reanimated, the project doesn't build, it gets the error I said in the top of this question. I believe these two errors are connected.

Can someone please help me?

here is the project dependencies:

"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://[email protected]/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"
  },

Solution

  • Fixed!

    All I had to do was install react-native-reanimated and NOT to do the manual steps that the documentation shows. Seems like there it shows the steps to react-native-reanimated@alpha, (version 2.x.x) that looks like it's still not working properly, specially with createDrawerNavigation.

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