2

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:

  1. Installed react-native-document-picker:
    npm install react-native-document-picker
    
  2. Added READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions to android/app/src/main/AndroidManifest.xml:
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
  3. 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-native version here, e.g., npx react-native --version)
  • (Also, the version of react-native-document-picker you 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?

1 Answer 1

5

The package name has been changed. Uninstalling react-native-document-picker, installing @react-native-documents/picker , and following the steps on the migration page solved the problem for me.

Sign up to request clarification or add additional context in comments.

1 Comment

This should be marked as the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.