FileSystem.writeAsStringAsync crashes

Please provide the following:

  1. SDK Version: 41
  2. Platforms(Android/iOS/web/all): Android
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

I’ve just updated my expo application from 40 to 41 and then this line of code started to crash:

await FileSystem.writeAsStringAsync(filename, aux, {
				encoding: FileSystem.EncodingType.UTF8,
			});

This is the whole function:

export async function writeExternalData(data: CombinedDataModelInterfaces) {
	try {
		console.log(TAG, '::writeExternalData::data:', data);
		// const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
		const {status,granted} = await MediaLibrary.requestPermissionsAsync()
		console.log(TAG,'::status:',status,'::granted:',granted)
		if (status === 'granted') {
			let tempname = 'lotusdata_' + new Date().toISOString();
			let filename = FileSystem.documentDirectory + tempname + '.json';
			console.log(TAG, '::filename:' + filename);
			const aux = JSON.stringify(data)
			console.log(TAG,'::data as json string:',aux)
			await FileSystem.writeAsStringAsync(filename, aux, {
				encoding: FileSystem.EncodingType.UTF8,
			});
			console.log(TAG,'::createAssetAsync')
			await MediaLibrary.createAssetAsync(filename);
			console.log(TAG,'::assetAsync created')
			return filename;
		} else {
			return new Error('Permissions denied... :(');
		}
	} catch (error) {
		return error;
	}
}

Value of aux variable:

{"dataA":[],"dataB":[{"a":"Data A 1","email":"email123@gmail.com","phone1":"123123","phone2":null,"c":"data123","d":"11333989016","e":{"id":1,"ea":"AA","eb":"Ia","ec":"Test","ee":"Va","ef":123,"eg":""},"f":null,"g":null,"h":"","id":1,"deleted":0}],"dataC":[],"dataD":[]}

Relevant lib versions:

    "expo": "^41.0.0",
    "expo-document-picker": "~9.1.2",
    "expo-file-system": "~11.0.2",
    "expo-media-library": "~12.0.2",
    "expo-permissions": "~12.0.1",
    "expo-sharing": "~9.1.2",
    "expo-sqlite": "~9.1.0",
    "expo-status-bar": "~1.0.4",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",

Native error code that I get

java.lang.RuntimeException: An error occurred while executing doInBackground()
	at android.os.AsyncTask$4.done(AsyncTask.java:399)
	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
	at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
	at java.util.concurrent.FutureTask.run(FutureTask.java:271)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
	at abi41_0_0.expo.modules.medialibrary.MediaLibraryUtils.getRelativePathForAssetType(MediaLibraryUtils.java:1)
	at abi41_0_0.expo.modules.medialibrary.MediaLibraryUtils.getEnvDirectoryForAssetType(MediaLibraryUtils.java:1)
	at abi41_0_0.expo.modules.medialibrary.CreateAsset.createAssetFile(CreateAsset.java:4)
	at abi41_0_0.expo.modules.medialibrary.CreateAsset.doInBackground(CreateAsset.java:4)
	at abi41_0_0.expo.modules.medialibrary.CreateAsset.doInBackground(CreateAsset.java:1)
	at android.os.AsyncTask$3.call(AsyncTask.java:378)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	... 3 more```

Hey @mpcsj_empreendimento, could you open a github issue for this and provide both a runnable repro example (such as a clonable github repo or Snack) and as much relevant information as you can provide (such as android version, etc)

Cheers,
Adam