-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
I installed the library and linked it with react-native link react-native-fs
.
I try to run the minimal example:
RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)
.then((result) => {
console.log('GOT RESULT', result);
// stat the first file
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then((statResult) => {
if (statResult[0].isFile()) {
// if we have a file, read it
return RNFS.readFile(statResult[1], 'utf8');
}
return 'no file';
})
.then((contents) => {
// log the file contents
console.log(contents);
})
.catch((err) => {
console.log(err.message, err.code);
});
which gives me (on Android API 26)
Cannot read property 'startsWith' of undefined
I tried with a lower API (24) which gives me
undefined is not an object (evaluation 'path.startsWith')
My MainActivity.java
file looks different than the one suggested when you manually link the library
package com.MYAPP;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "MYAPP";
}
}
But when I change it to this
package com.MYAPP;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity implements DefaultHardwareBackBtnHandler{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new RNFSPackage()) // <------- add package
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);
setContentView(mReactRootView);
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "MAYAPP";
}
}
The app does not even compile...
react-native-cli: 2.0.1
react-native: 0.48.3
npm: 5.3.0
Any ideas?
Metadata
Metadata
Assignees
Labels
No labels