-
Notifications
You must be signed in to change notification settings - Fork 760
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
Platform android@9.0.0 running on Android 10 : getFile produces INVALID_MODIFICATION_ERR - Error code 9. #408
Comments
Definitely sounds like an API 29 restriction/change. Does it work on Try setting the |
Yeah I think you're right, that worked with |
I think Scoped Storage is the change in API 29 that is causing this. |
Gave it a go saving to another location to see if it would get around that permission, seems like saving to the app data directory
Also noticed the following when trying out some options:
In case it's useful for anyone else that only needs to store files in the app dir, the change to use window.resolveLocalFileSystemURL(cordova.file.dataDirectory, // <-----------
function (dirEntry) { // <-----------
dirEntry.getFile("test2.txt", {create: true, exclusive: false}, // <-----------
function(fileEntry) { // File loaded/created
fileEntry.createWriter(
function(writer) { // Writer created
writer.write('hello');
console.log('test2 it worked!');
},
function(error) { // Writer failure
console.log('createWriter', error);
}
);
},
function(error) { // File failure
console.log('getFile', error);
}
);
},
function(error) { console.log('resolveLocalFileSystemURL', error); }
); |
That's interesting... When I use the Perhaps I tested the original code that produced the error for you on my android 10 device and it worked for me, but my app ensures that This is starting to look less like a scoped storage issue and more like something is just not being initialised properly issue. Edit: Just tried it on a cordova hello world template app and it still worked on my android 10 device, API target 29 apk 😕 |
setting "android-targetSdkVersion" to 28 is only a temporary solution. |
I have only briefly looked at this issue, but my time is rather limited. PRs are definitely welcome and appreciated. |
@breautek - I will try to see if I can fork a solution. |
fix added inside this PR #410 |
Thank you @eliadAfeka @peterfox1 since i failed to reproduce the issue last time I looked at this, could you test the PR to see if it resolves it for you? |
@breautek - to reproduce it you must have an Android 10 and set sdk version to 29. uninstall your app, build and run. |
Hi, i also had this issue, My error is, code 12 PATH_EXISTS_ERR when i try to create a folder global.resolveLocalFileSystemURL( cordova.file.externalRootDirectory, function (dirEntry) {
}) now i solve this by change target api to 28 instead of 29 but only temporary Mostly error from android 10. |
@hariagustian can you install the PR #410 and let us know if the PR solves your issue when targeting API 29? |
The ImagePicker Plugin has a similar Problem and it was solved with the same Fix. |
I can confirm that the same line from PR #410 put manually in config.xml solves the problem. Just to add some details, we had this line in our config.xml:
Installing @eliadAfeka 's fork gave us this error:
So we edited our config.xml to look like this:
and the problem seems to be solved. Thanks everyone for your help. |
@rastafan But it would have worked if you removed your Config, so i think it is ready to merge |
I had the same issue and it was fixed of the comment added by @rastafan (quoted reply) in my Samsung phone - Android 10. I added the code - "android:usesCleartextTraffic="true" android:requestLegacyExternalStorage="true"" in the directory /plaforms/android/app/src/main/AndroidManifest.xml AndroidManifest file added code in the application tag:
and also to add, I used the Special thanks to this thread: @rastafan @breautek @peterfox1 @HansKrywaa @hariagustian @eliadAfeka |
It magically worked. Thank you everyone! |
Hi I'm having this problem when trying to add the android:requestLegacyExternalStorage Here is the error: I already update my SDK idk what to do anymore. TIA Ionic Info: Ionic CLI : 5.4.16 Cordova: Cordova CLI : 9.0.0 (cordova-lib@9.0.1) Utility: cordova-res : not installed System: NodeJS : v12.16.1 (C:\Program Files\nodejs\node.exe) |
@apolunderblade I think you need to update your Cordova CLI to version 10.0.0 and your Cordova Android to 9.0.0 before you can add the |
I see let me try! Thanks Edited: |
I am also facing this issue. now is there actually some upcoming fix for this? |
hi, is there any news with the version? we still get the modification error. |
The provided PR is currently in a broken state: see #410 (comment)
The |
Hi everyone, I have the same problem: I have a cordova 9.0.0 app that works on Android 9 and doesn't work on Android 10. If I put SdkTarget to 28 everything ok, but I have to use sdk 29, so I would like to find a solution, I can't figure out if I have to modify the config.xml of my app, if I do it it gives me compilation error .. Can you help me please? Thanks |
Hi @Rei66RM, can your provide your code in config.xml file (loc: /config.xml) & the AndroidManifest.xml file located in - /plaforms/android/app/src/main/AndroidManifest.xml to examine the diff of my existing cordova app. Thanks! |
HI Pepenero, Are you Italian? |
Oh nice, I'm glad u already solved it! I'm from the Philippines @Rei66RM - yeah! you already targetted the android API 29 0 |
worked seamlessly |
Can anyone help me? code : |
Hi everyone. It's 2022 and I'm having this issue again. android-targetSdkVersion: 30 (Play Store Requirements)
Already added to config.xml Error Code 9 still coming up. Has anything changed about this for SDK 30? |
I believe an invalid modification error on API 30 generally occurs when you're attempting to write to an external storage path that is no longer writable, or that your app doesn't have permission to write to (such as modifying a file that wasn't created by your app). |
@breautek I'm experiencing the same problem. I'm trying to write to |
If anyone has this problem <edit-config file="app/src/main/AndroidManifest.xml" target="application" mode="merge">
<application android:requestLegacyExternalStorage="true" />
</edit-config> Still works when targeting android-30. Just be sure to have |
I have tried by using these config in my config.xml file. But it still does not seems to resolve the issue. Issue: Getting Cordova : v11 Issue is still present even in the newer Cordova version. Can anyone suggest a workaround for the same ? |
The requestLegacyExternalStorage flag is an API 29 only flag. It was added to make API 29 revert back to the old filesystem as it worked in API 28. Without it, API 29 will use the newer restricted filesystem. API 30 or later ignores this flag.
The
In my testing, reading & writing of the root external directory is no longer allowed. You can access existing subdirectories, such as I believe creation of new directories is also forbidden, except for your application's external data directory. My best advice is to evaluate whether you actually need external storage. Are you trying to make your files shareable between apps? If not, then perhaps you should be using the internal storage directories instead, e.g. I've already explained this a few times in the past on this thread, so I'll be locking this thread. It's an older thread, if you continue having an issue which you believe is a bug in this plugin, I suggest opening a new issue with more modern/up-to-date information. |
Bug Report
Problem
What is expected to happen?
fileSystem.root.getFile
Should trigger the success callback.What does actually happen?
On Android 10, it triggers the error callback with
FileError {code: 9}
(INVALID_MODIFICATION_ERR).On Android 9 it works as expected - the success callback is triggered.
Information
Issue replicated with a physical Pixel 2 & the Pixel 2 emulator from android studio.
I wasn't getting the issue with android@8.0.0 / API 28, it's just been introduced when switching to android@9.0.0 / API 29.
Command or Code
Minimal example:
Output:
getFile FileError {code: 9}
Environment, Platform, Device
Android 10.0 / Pixel 2 API 29 emulator
Also replicated on a real Pixel 2 / Android 10.
Works correctly on Android 9 / Samsung S8.
Version information
Cordova
9.0.0 (cordova-lib@9.0.1)
Platform
android@9.0.0
cordova-plugin-file
6.0.1 & 6.0.2
Android 10.0 / Pixel 2 API 29 emulator
Android Studio 4.0.1
Windows 10.
Checklist
The text was updated successfully, but these errors were encountered: