I'm trying to implement file upload functionality in my React Native CLI project (targeting Android) using react-native-document-picker. I've encountered a compilation error related to GuardedResultAsyncTask after installing the package.
What I'm trying to achieve: Allow users to select files from their device in a React Native Android application.
Steps I've taken:
- Installed
react-native-document-picker:npm install react-native-document-picker - Added
READ_EXTERNAL_STORAGEandWRITE_EXTERNAL_STORAGEpermissions toandroid/app/src/main/AndroidManifest.xml:<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> - Cleaned Gradle cache and rebuilt the Android application:
cd android && ./gradlew clean && cd .. npx react-native run-android
The Problem / Error Message:
The build fails specifically on the :react-native-document-picker:compileDebugJavaWithJavac task with the following errors:
C:\Users\Dell7490\Desktop\blinkitclone\foodapp\node_modules\react-native-document-picker\android\src\main\java\com\reactnativedocumentpicker\RNDocumentPickerModule.java:21: error: cannot find symbol
import com.facebook.react.bridge.GuardedResultAsyncTask;
^
symbol: class GuardedResultAsyncTask
location: package com.facebook.react.bridge
C:\Users\Dell7490\Desktop\blinkitclone\foodapp\node_modules\react-native-document-picker\android\src\main\java\com\reactnativedocumentpicker\RNDocumentPickerModule.java:232: error: cannot find symbol
private static class ProcessDataTask extends GuardedResultAsyncTask<ReadableArray> {
^
symbol: class GuardedResultAsyncTask
location: class RNDocumentPickerModule
C:\Users\Dell7490\Desktop\blinkitclone\foodapp\node_modules\react-native-document-picker\android\src\main\java\com\reactnativedocumentpicker\RNDocumentPickerModule.java:226: error: cannot find symbol
new ProcessDataTask(getReactApplicationContext(), uris, copyTo, promise).execute();
^
symbol: method execute()
location: class ProcessDataTask
C:\Users\Dell7490\Desktop\blinkitclone\foodapp\node_modules\react-native-document-picker\android\src\main\java\com\reactnativedocumentpicker\RNDocumentPickerModule.java:246: error: method does not override or implement a method from a supertype
@Override
^
C:\Users\Dell7490\Desktop\blinkitclone\foodapp\node_modules\react-native-document-picker\android\src\main\java\com\reactnativedocumentpicker\RNDocumentPickerModule.java:255: error: method does not override or implement a method from a supertype
@Override
^
5 errors
2 warnings
It seems like the react-native-document-picker module is trying to use a class (GuardedResultAsyncTask) or methods that are no longer available or have changed in my React Native version's Android bridge.
Environment:
- React Native CLI project
- Targeting Android
- (You might want to add your specific
react-nativeversion here, e.g.,npx react-native --version) - (Also, the version of
react-native-document-pickeryou have installed, e.g.,npm list react-native-document-picker)
Question:
How can I resolve these compilation errors with react-native-document-picker on Android? Is there a specific version of the library I should use that is compatible with newer React Native versions, or are there additional configuration steps needed?