Skip to content
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

Question : Can we set file path for DB on Android ? #927

Closed
avinashlng1080 opened this issue Jan 20, 2021 · 3 comments
Closed

Question : Can we set file path for DB on Android ? #927

avinashlng1080 opened this issue Jan 20, 2021 · 3 comments

Comments

@avinashlng1080
Copy link
Contributor

Hello Guys,

On iOS, we are able to pass in a file path for the dbName to set up the database at a specific location; for example, in the shared directory of an App-Group.

Can we pass in a file path for Android? I tried and met with a few issues. I've used expo-file-system to create the directory under the 'Documents' direction on Android, but when I pass in the file path, the database isn't created. I get the following error:

[WatermelonDB] Uh-oh. Database failed to load, we're in big trouble. This might happen if you 
didn't set up native code correctly (iOS, Android), or if you didn't recompile native app after 
WatermelonDB update. It might also mean that IndexedDB  or SQLite refused to open. 

[Error: File file:///data/user/0/com.mattermost.rnbeta/files/databases/default.db/default.db.db 
contains a path separator]

Can you please guide me into solving this? Maybe this feature is not yet supported or I'm not doing something right.

@avinashlng1080
Copy link
Contributor Author

@radex can you please share your thoughts on this?

@radex
Copy link
Collaborator

radex commented Jan 21, 2021

don't ask me, let's look at the code:

https://github.com/Nozbe/WatermelonDB/blob/master/native/android/src/main/java/com/nozbe/watermelondb/Database.kt#L11-L21

Well, nope, it seems that this assumes one just wants to have the DB in the Databases folder.

Compare that to the iOS implementation:

https://github.com/Nozbe/WatermelonDB/blob/master/native/ios/WatermelonDB/DatabaseDriver.swift#L245-L256

Pull requests are welcome :)

@avinashlng1080
Copy link
Contributor Author

avinashlng1080 commented Jan 26, 2021

Thanks @radex .

I have a working solution that actually creates *.db under a folder in the Files directory.

I'm preparing for a PR; when I run the 'yarn run ktlint' command, it keeps failing with the following error :

> Configure project :watermelondb-jsi
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /Users/avinashlingaloo/Library/Android/sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

Can you please guide me here ? I may be doing something wrong.

@radex radex closed this as completed Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants