-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] TypeError: null is not an object (evaluating '_NativeBlobUtils.default.getConstants') #238
Comments
I was able to fix this by simply removing the library and reverting back to |
I'm having the same problem. I'm currently running it on Android 12 (Samsung Galaxy S10e) within Windows and it's an ejected Expo App. |
I found the solution!!!! The problem is that the documentation needs to be updated. Here's the step by step processDetails:
1st. Add on your dependencies {
// other dependencies
implementation project(':react-native-blob-util')
// other dependencies
} 2nd. In your <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.app.name" xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<application ... >
<activity ...>
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
</manifest> I am curious to know whether those were valid. 3rd. on your include ':react-native-blob-util'
project(':react-native-blob-util').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-blob-util/android'); Notes:
4th. Compile your project (In my case I sent it to Expo). 5th. Import as usual (example): import { useCallback } from 'react';
import ReactNativeBlobUtil from 'react-native-blob-util';
import share from 'react-native-share';
import { PermissionsAndroid, Platform } from 'react-native';
import { useToast } from '@components/toast/useToast';
import { t } from '@lingui/macro';
type DownloadStatementsInput = {
url: string;
filename: string;
};
export function useDownloadStatements(input: DownloadStatementsInput) {
const { url, filename } = input;
const displayToast = useToast();
const bankToken = 'The Bank Token';
return useCallback(async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'storage title',
message: 'storage_permission',
buttonPositive: 'ok',
}
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
console.log('Permission denied');
return;
}
const dirs = ReactNativeBlobUtil.fs.dirs;
displayToast(
t`Downloading your statement for ${filename}.`,
'info'
);
const result = await ReactNativeBlobUtil.config({
fileCache: true,
appendExt: 'pdf',
path: `${dirs.DownloadDir}/${filename}`,
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
mediaScannable: true,
title: filename,
description: `Pana Bank Statement for $`,
mime: 'application/pdf',
},
}).fetch('GET', url, {
Authorization: `Bearer ${bankToken}`,
'x-pana-client-source': 'PANA_APP',
});
const androidMessage =
Platform.OS === 'android'
? t` Open your notifications for the PDF.`
: ``;
displayToast(t`Downloading finished. ${androidMessage}`, 'info');
// in iOS, we want to save our files by opening up the saveToFiles bottom sheet action.
// whereas in android, the download manager is handling the download for us.
if (Platform.OS === 'ios') {
const filePath = result.path();
let options = {
type: 'application/pdf',
url: filePath,
saveToFiles: true,
};
share
.open(options)
.then(resp => console.log(resp))
.catch(err => console.log(err));
}
} catch (e) {}
}, [bankToken, url, filename]);
} |
@superjose Thanks for then help. I have tried your solution but am still getting the same error. Here is what I did...
implementation project(':react-native-blob-util')
include ':react-native-blob-util'
project(':react-native-blob-util').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-blob-util/android');
I didn't change my js code to request permissions but I don't think it would make a difference since I am getting this error when I build the app from android studio. You can see my entire PR here for more information. We are not using expo so maybe that has something to do with it? I noticed that you mentioned you ejected the app? what does this achieve? @RonRadtke could we get some help here? this is a major blocker for my project. I tried using rn-fetch-blob (which does not give me this error) but I am encountering another error which requires me to migrate to your package. |
@owencraston did you manage to solve the issue now? |
Thank you @RonRadtke for responding. I've since migrated back to RNFetchBlob for the time being. That package has its own issues (namely this one) but I was able to get it working on certain version of android. To reproduce I would try doing the following.
The above branch is old and stale so it may fail for various reasons. If this happens you can always repoduce by doing the following....
I appreciate your help with this. Let me know if you have any questions or if these reproduction steps do not work. I will try and get a more up to date branch ready for you if not. I wonder if this issue stems from our project previously using RNFetchBlob and perhaps not cleaning up the old usage of it. |
I should also mention that adding the permissions did not solve the problem for me. |
But just to be on the save side before investing hours... Line 13 in 132051c console.log(ReactNativeBlobUtil)
To see if the module is actually correctly loaded or if the error is due to module not being loaded at all |
@RonRadtke console.log(ReactNativeBlobUtil) is null |
I was able to solve the problem with this solution. my environment:
other packages:
|
Issue
I am getting the following error when trying to build on Android API 30. This is
not an EXPO project
. I am not getting this issue at all on iOS and it builds perfectly with xcode.Error:
Context
here is my React native info:
"react-native-blob-util": "^0.17.2",
"redux-persist-filesystem-storage": "4.1.0",
I tried everything in this thread and it did not work.
What I tried
pod install
in the ios folderThe text was updated successfully, but these errors were encountered: