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

android 6.1 for sqlcipher_flutter_libs #29

Closed
Ali1Ammar opened this issue Apr 28, 2021 · 1 comment · Fixed by #30
Closed

android 6.1 for sqlcipher_flutter_libs #29

Ali1Ammar opened this issue Apr 28, 2021 · 1 comment · Fixed by #30

Comments

@Ali1Ammar
Copy link
Contributor

i see there is error with dynamic link in old phone and some 6.1 device
there is applyWorkaroundToOpenSqlite3OnOldAndroidVersions for sqlite3_flutter_libs but not for sqlcipher_flutter_libs
also when we override like this as describe in moor docs will break old device because we need to use full path with id on old device

  open.overrideFor(
      OperatingSystem.android, () => DynamicLibrary.open('libsqlcipher.so'));

i suggest to add this to sqlcipher_flutter_libs :

1- applyWorkaroundToOpenSqlite3OnOldAndroidVersions

2- provide openCipherOnAndroid function that do this

DynamicLibrary openCipherOnAndroid() {
  try {
    return DynamicLibrary.open('libsqlcipher.so');
  } catch (_) {
    // On some (especially old) Android devices, we somehow can't dlopen
    // libraries shipped with the apk. We need to find the full path of the
    // library (/data/data/<id>/lib/libsqlcipher.so) and open that one.
    // For details, see https://github.com/simolus3/moor/issues/420
    final appIdAsBytes = File('/proc/self/cmdline').readAsBytesSync();

    // app id ends with the first \0 character in here.
    final endOfAppId = max(appIdAsBytes.indexOf(0), 0);
    final appId = String.fromCharCodes(appIdAsBytes.sublist(0, endOfAppId));

    return DynamicLibrary.open('/data/data/$appId/lib/libsqlcipher.so');
  }
}

then programmer could do

  open.overrideFor(
      OperatingSystem.android, openCipherOnAndroid);

i am happy to make pull request if this way ok .

@simolus3
Copy link
Owner

A pull request would be great, thanks 👍

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

Successfully merging a pull request may close this issue.

2 participants