. Advertisement .
..3..
. Advertisement .
..4..
As we are attempting to launch my react-native application, we encounter the following issue: ”Attempt to invoke interface method boolean com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder.isLayoutAnimationEnabled() on a null object reference ”. Let’s solve this error in the below article with our most possible solution!
What is ”Attempt to invoke interface method boolean com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder.isLayoutAnimationEnabled() on a null object reference”?
We get this error when we try to launch the react-native application.
Attempt to invoke interface method boolean com.swmansion.reanimated.layoutReanimation.
NativeMethodsHolder.isLayoutAnimationEnabled() on a null object reference
How to solve the error ”Attempt to invoke interface method boolean com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder.isLayoutAnimationEnabled() on a null object reference”
Option 1: Change it in the Package.json directory
All we have to do is change it in the Package.json directory to solve this issue. Next, we should utilize the 2.2.4 version. Then uninstall the package and reinstall the “react-native-reanimated” v2.2.4. It will fix your problem.
Here is our code to start the application.
/** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local */ import 'react-native-gesture-handler'; import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, useColorScheme, View, } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; import Upload from './Screens/Upload'; import Display from './Screens/Display'; const Stack = createStackNavigator() function App() { return ( <NavigationContainer> <Stack.Navigator> <Stack.Screen name='Screen_A' component={Upload} > </Stack.Screen> <Stack.Screen name='Screen_B' component={Display} > </Stack.Screen> </Stack.Navigator> </NavigationContainer> ); }; export default App;
Option 2: Follow these steps
Follow these steps to fix the error ”Attempt to invoke interface method boolean com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder.isLayoutAnimationEnabled() on a null object reference”.
Step 1: Edit android/app/build.gradle to enable the Hermes engine.
project.ext.react = [
enableHermes: true // <- here -- convert false for true
]
Step 2: Plug Reanimated at Degree Two in MainApplication.java
android\app\src\main\java\com\<yourProjectName>\MainApplication.java
import com.facebook.react.bridge.JSIModulePackage; // <- add this
import com.swmansion.reanimated.ReanimatedJSIModulePackage; // <- add this
...
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
...
@Override
protected String getJSMainModuleName() {
return "index";
}
// add more this "Override" below <----------------
@Override
protected JSIModulePackage getJSIModulePackage() {
return new ReanimatedJSIModulePackage(); // <- add
}
};
...
AFTER ALL PROCEDURE Navigation Docs for React Add the following to your entry file, like as index.js or App.js, at the top (make sure it’s at the top and there’s nothing before it), to complete the installing of react-native-gesture-handler.
the import of “react-native-gesture-handler”
Let’s save everything and the Android command line for rebuilding is: npx react-native run-android.
Package.json
"@react-navigation/drawer": "^6.1.8" "@react-navigation/native": "^6.0.6" "@react-navigation/native-stack": "^6.2.5" "react-native": "0.66.4" "react-native-gesture-handler": "^2.1.0"
Conclusion
If you face the same issue, feel free to use our solution on Attempt to invoke interface method boolean com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder.isLayoutAnimationEnabled() on a null object reference error.
Please leave any ideas and questions about the issue in the comment section and let us know if the solution works best for you.
Leave a comment