Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Feb 26, 2025

On Android, a build step crawls the call graph to minify method names and remove unused methods. This step uses tools like R8 (or ProGuard on much older SDKs) that only look at Java bytecode to determine which methods are called. In our SDK, there are two caveats that these tools miss:

  1. com.powersync.DatabaseDriverFactory.setupSqliteBinding is a native method implemented with JNI. Its name must not be changed for the linking to work.
  2. In the same class, onTableUpdate and onTransactionCommit are called from C code with JNI. If the methods are renamed or removed, we'll crash.

For these reasons, we need to add ProGuard files marking these methods as used and unsuitable for minifying.

To test this, I've copied some of the simpler integration tests on the core project into a core-tests-android where they can run on an emulator / real device (due to limitations in the Kotlin multiplatform and Android Gradle platforms, it doesn't appear to be possible possible to share this code across platforms). The tests in that project started passing after adding the ProGuard rules.

Closes #112.

@simolus3 simolus3 merged commit cd1e2f9 into main Feb 27, 2025
3 checks passed
@simolus3 simolus3 deleted the fix-proguard-rules branch February 27, 2025 09:37
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 this pull request may close these issues.

Crash on Android when using R8/Proguard

2 participants