Reputation: 10350
I am fixing a incompatibility issue related to AndroidX by adding 2 lines to gradle.properties
under android
for my RN 0.59 project.
android.useAndroidX=true
android.enableJetifier=true
Now there is another error with run-android
related to react-native-gesture-handler
. Then I yarn remove
the current react-native-gesture-handler
of 1.2.0
and add it back. The new version is 1.3.0
. Here is the error:
> Task :react-native-gesture-handler:compileDebugJavaWithJavac
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:3: error: package android.support.v4.util does not exist
import android.support.v4.util.Pools;
^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:19: error: package Pools does not exist
private static final Pools.SynchronizedPool<RNGestureHandlerEvent> EVENTS_POOL =
^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:3: error: package android.support.v4.util does not exist
import android.support.v4.util.Pools;
^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:19: error: package Pools does not exist
private static final Pools.SynchronizedPool<RNGestureHandlerStateChangeEvent> EVENTS_POOL =
^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerEvent.java:20: error: package Pools does not exist
new Pools.SynchronizedPool<>(TOUCH_EVENTS_POOL_SIZE);
^
C:\D\code\js\emps_app\node_modules\react-native-gesture-handler\android\src\main\java\com\swmansion\gesturehandler\react\RNGestureHandlerStateChangeEvent.java:20: error: package Pools does not exist
new Pools.SynchronizedPool<>(TOUCH_EVENTS_POOL_SIZE);
^
Note: C:\D\code\js\emps_app\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.
6 errors
> Task :react-native-gesture-handler:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
The error is related 6 packages missing and I guess it is still related to Androidx. But I have no clue how to fix it. There is an issue post (for RN-gesture-handler) suggesting downgraded to version 1.0.5
for fixing but I wouldn't like to use such an old version.
Upvotes: 10
Views: 31291
Reputation: 85
As per my openion this error occurs due to incomplete installation and linking of npm library. Follows these steps:- At first Run this command inside your project (npm install --save react-native-gesture-handler). Then link this library by running this command (react-native link react-native-gesture-handler). Then run your project on devices or simulator , it will work. If it doesn't work then manually install and link this library from link given below. https://www.npmjs.com/package/react-native-gesture-handler
Upvotes: 0
Reputation: 670
Here's another answer for folks using RN < 0.60, as was the OP. I am using react-native-gesture-handler
v 1.3.0 as this was the the last version before the library updated to AndroidX.
Although the OP ran into this by adding
android.useAndroidX=true
android.enableJetifier=true
to his project, I unwittingly added it by adding another library that had been converted to AndroidX, react-native-safe-area-context
. I was expecting my build to fail when it got to that library, but I got really confused when it failed before that, while building react-native-gesture-handler
. Apparently if useAndroidX
and enableJetifier
are set to true anywhere in the build it affects the whole build.
I fixed the problem by patching the new library to revert AndroidX. I got the patch here.
Upvotes: 0
Reputation: 1482
$ npm i react-native-gesture-handler
$ react-native link react-native-gesture-handler
Install Jetifier ->
$ npm install --save-dev jetifier
or
$ yarn add -D jetifier
Then -> Edit your package.json and add a postinstall script: "postinstall": "npx jetify", like so:
{
"version": "2.0.0",
"lockfileVersion": 1,
"requires": true,
"scripts": {
"postinstall": "npx jetify"
},
....
}
$ npm install or $ yarn
$ npx jetify
Upvotes: 0
Reputation: 836
It cause this error for the RN 0.60
.
You can solve this by following,
npm i jetifier
npx jetify
fixed it for me on RN 0.60
.
Have a good day.
Upvotes: 20
Reputation: 876
npm i jetifier
npx jetify
Fixed it for me on react-native 0.60
Be carefully for latest react-native version don't need
react-native link react-native-gesture-handler
It is automatically linked by react-native 0.60
Upvotes: 5