Search code examples
androidflutterdartffi

Usage of precompiled library that read/write config in Flutter


I have a C++ library compiled for Android (*.so) and need to implement functionality in Flutter using it. The library connected normally using standard ffi tools. Along with the library there is a configuration file, which must be located in the same directory as the library. The library should read and write it regularly.

The compiled application for Android prevents the library from working with the configuration file.

  1. Where does an Flutter Android application unpack the compiled (*.so) library?
  2. How does the loading process take place?
  3. Is it possible to implement reading/writing a configuration file in the same directory as the library?
  4. What permissions must be granted to the application?

Current permissions of application:


Solution

  • Here's the solution: don't have it read/write to the same directory as the dynamic library.

    Instead, you have two options:

    1. Grab the application's data directory using Flutter and pass it to the library over ffi (easier in my experience, ironically)
    2. Use the NDK to get the application's data directory instead (but I think this requires some sort of context object, making it much less ergonomic)

    I can't remember exactly where dynamic libraries are put, but think of it this way: if an app is able to read/write to that folder, what is stopping arbitrary code execution from taking place? You could have some malicious code write to a new .so file, and load that into the app, and bingo, you just got around Google Play's restrictions and malware protections. This probably isn't going to be possible without a rooted phone and distributing outside of one of the stores.