Android: Support minification with ProGuard and R8 #132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
com.powersync.DatabaseDriverFactory.setupSqliteBinding
is a native method implemented with JNI. Its name must not be changed for the linking to work.onTableUpdate
andonTransactionCommit
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 acore-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.