Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

[Android] undefined is not an object (evaluating 'RNFetchBlob.DocumentDir') #51

Closed
dphov opened this issue Jul 12, 2016 · 24 comments
Closed
Assignees

Comments

@dphov
Copy link
Contributor

dphov commented Jul 12, 2016

Hello!

This error appears at start launch in the simulator/device.

In my example I'm trying implement this part of code, how we can avoid this issue?

Thank you in advance.

componentDidMount() { RNFetchBlob .config({ // add this option that makes response data to be stored as a file, // this is much more performant. fileCache : true, }) .fetch('GET', 'https://homepages.cae.wisc.edu/~ece533/images/mountain.png') .then((res) => { // the temp file path console.log('The file saved to ', res.path('/')) }) requestPermission("android.permission.ACCESS_FINE_LOCATION").then((result) => { console.log("Granted!", result);// now you can set the listenner to watch the user geo location }, (result) => { console.log("Not Granted!"); console.log(result); });

react-native@0.29.0
react-native-cli@1.0.0
react@15.2.0
react-native-fetch-blob@0.6.3-dev.1

img1
img2

@wkh237
Copy link
Owner

wkh237 commented Jul 12, 2016

Hi @dphov , It looks like your package is not linked properly, did you restart your packager after install the package ? the module has many native code so you have to rebuild the project after install it.

@dphov
Copy link
Contributor Author

dphov commented Jul 12, 2016

Hi @wkh237 ,

  1. I'm has restarted packager
  2. Ran npm install
  3. Then ran rnpm link

And I got the same error

@wkh237
Copy link
Owner

wkh237 commented Jul 12, 2016

Did you save the package dependency to package.json ? rnpm does not work if the package could not be found in package.json.

could you try the following commands ?

$ npm install --save react-native-fetch-blog@0.6.3-dev.1
$ rnpm link react-native-fetch-blob
$ react-native run-android
@dphov
Copy link
Contributor Author

dphov commented Jul 12, 2016

package.json after running commands
"dependencies": { "react": "15.2.0", "react-native": "0.29.0", "react-native-android-permissions": "^0.0.6", "react-native-cli": "^1.0.0", "react-native-fetch-blob": "^0.6.3-dev.1", "undefined": "^0.1.0" }

got same error again

@wkh237
Copy link
Owner

wkh237 commented Jul 12, 2016

This may also related to changes in 0.29 , could you check MainApplication.java in /android/app/src/main/java/com/<project name>t/MainApplication.java, see if the RNFetchBlobPackage is added into package list ?

 @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          // Add this line if it does not exists
+         new RNFetchBlobPackage()                                                                                                                
      );
    }

Add the missing package and compile to see if it work 👍

@wkh237 wkh237 self-assigned this Jul 12, 2016
@wkh237
Copy link
Owner

wkh237 commented Jul 12, 2016

  • Add 0.29 instruction to README.md
  • Change rnpm link script
@dphov dphov closed this as completed Jul 12, 2016
@dphov dphov reopened this Jul 12, 2016
@dphov
Copy link
Contributor Author

dphov commented Jul 12, 2016

Hurray! It works! Thank you!

@wkh237
Copy link
Owner

wkh237 commented Jul 12, 2016

That's great 👍 Please feel free file an issue if something's going wrong 😄

@dphov
Copy link
Contributor Author

dphov commented Jul 12, 2016

Sure! 😄 👍

@shirleycharlin
Copy link

Commenting just in case anyone encounter the same issue when compiling IOS.

I have also encountered this when I transfer my project to a new macbook.

Solution:
Run the app on the simulator.
Delete away the build file inside IOS folder.
At the simulator, go to Simulator > Reset content and setting
Rebuild the app again - react-native run-ios

Credits to this link: http://stackoverflow.com/questions/35611765/react-native-run-ios-command-fails-pch-issues-but-build-succeeds-in-xcode

@wkh237
Copy link
Owner

wkh237 commented Aug 4, 2016

@shirleycharlin , great thanks for your additional information 👍

@RichardBoyewa
Copy link

I am still having this same issue @dphov reported, I have done the linking but the error persists on Android. Is there any other reason

 RNFetchBlob 

will be undefined? Cos I get error undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

  1. "react-native-fetch-blob": "^0.8.2",
  2. "react-native": "0.30.0",
@wkh237
Copy link
Owner

wkh237 commented Aug 14, 2016

@RichardBoyewa , I've write some instructions in other thread, let's discuss this issue here, Thank you: )

@snjjain11
Copy link

I'm getting the error not able to find the symbol RNFetchBlobPackage after adding the package in main application

@snjjain11
Copy link

before that i was getting the error undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

@slender9168
Copy link

Two things solved the problem for me:
1- use the react-native link command
2- deploy the app again to the device from android studio ( i think using the package manager (npm start) only packages the new javascript code, not the library native code )

@valerybodak
Copy link

@dphov
How did you resolve this issue? I have the same error on Android emulator.
My dependencies from package.json:

"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-drawer": "^2.3.0",
"react-native-fetch-blob": "^0.10.5",
"react-native-localization": "^0.1.30",
"react-native-router-flux": "3.39.1",
"react-native-video": "^1.0.0"
},

@hzuhyb
Copy link

hzuhyb commented Sep 1, 2017

@wkh237 @shirleycharlin I got the same issue when compiling IOS, but it work when compiling Android.I follow your steps to solve, but still not work.

dependencies:
1、"react-native": "0.44.0",
2、"react-native-fetch-blob": "^0.10.8"

Compile Error:
** BUILD FAILED **

The following build commands failed:
CompileC /Users/leo/code/RNDemo/ios/build/Build/Intermediates/TcpSockets.build/Debug-iphonesimulator/TcpSockets.build/Objects-normal/x86_64/TcpSockets.o TcpSockets.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Installing build/Build/Products/Debug-iphonesimulator/RNDemo.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist

Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/RNDemo.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist

@percyhanna
Copy link

For future posterity: I also ran into this problem because I was accidentally still running a React packager for a different project. I assume they got their wires crossed somehow. Not sure if it's expected to be able to run 2 packagers side-by-side or not?

@harish-aka-shivi
Copy link

If you are making a Activity and implementing DefaultHardwareBackBtnHandler, then in your onCreate(Bundle savedInstanceState), use addPackage() method like this:

mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModulePath("index.android") .addPackage(new MainReactPackage()) .addPackage(new RNFetchBlobPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build();

@krishan-kumar-mourya
Copy link

After linking you need to run
pod update

@frostover
Copy link

frostover commented Jan 9, 2019

This is solution for Android build. I didn't have any issues with iOS, some of these steps might help for iOS as well.

First make sure the package is installed

npm install react-native-fetch-blog

Next make sure it's included your package.json file (your version number might be different, just make sure it's there)

"dependencies": {
  "react-native-fetch-blob": "^0.10.8",
}

Next link the react-native-fetch-blob package directly using

react-native link react-native-fetch-blob

Next verify that the package is included in app/src/main/java/com/[APP-NAME]/MainApplication.java. Find the getPackages() function, inside there you should see new MainReactPackage(), among other packages. Look for new RNFetchBlogPackage(), if it's not in this list, add it.

new RNFetchBlogPackage()

Try to build the project. If you get an error error: cannot find symbol new RNFetchBlobPackage() then go back to the file app/src/main/java/com/[APP-NAME]/MainApplication.java and add

import com.RNFetchBlob.RNFetchBlobPackage;

to the top with the other imports. Try to build and it should work.

All these steps ended up working for me and the project was built.

julian-becker pushed a commit to julian-becker/react-native-fetch-blob that referenced this issue Mar 30, 2022
* Fixes import cycles
* Fixes problems for streaming files in combination with utf-8 encoding

Fixes wkh237#58
Fixes wkh237#51

Merge remote-tracking branch 'origin/develop' into master
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.