Assets.fromModule().localUri starts with 'asset://' after build:android


#1

Hi.
I need to use existing SQLite file for my app, and for offline support, so I did following things:

  1. add “assetBundlePatterns” in app.json .
  2. Assets.loadAsync("./assets/db/db.db") to load db file
  3. FilesSystem.copyAsync({
    from:Assets.fromModule("./assets/db/db.db").localUri,
    to:FileSystem.documentDirectory + “/db/db.db”
    }) to copy db file.

on step 3,
I have no problem and can copy files with my device and simulator successfully on Expo XDE,
but it fails to copy the file on a standalone app after build (with expo build:android).

when I check the Assets.fromModule.localUri, it starts with “asset://”, not “file://”.
Expo document says FileSystem uses uri starting with ‘file://’, and the same Assets’ localUri on Expo XDE starts with ‘file://’.

I think it is the problem.

Is there any bypass or any correct way to copy using Assets.localUri in standalone app?

Thanks.


#2

I think .copyAsync can work with asset:// sources. For the database location, you will need to put it in documentDirectory /SQLite/.db and use .db as the filename to open with SQLite API. What exactly is the error you’re seeing?


#3

I got following error while copyAsync:

{ [Error: Location ‘asset:///asset_6a8f644332ca42dcae8c8527bf66bc01.db’ isn’t readable.] framesToPop: 1, code: ‘EUNSPECIFIED’ }

I don’t know the reason why I got this error. I did Asset.loadAsync() before copy. Can it cause a problem?


closed #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.