Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cd1e2f9

Browse files
authoredFeb 27, 2025
Merge pull request #132 from powersync-ja/fix-proguard-rules
Android: Support minification with ProGuard and R8
2 parents 874c02c + f6b1e45 commit cd1e2f9

29 files changed

+392
-2
lines changed
 

‎build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ plugins {
88
alias(libs.plugins.kmmbridge) apply false
99
alias(libs.plugins.skie) apply false
1010
alias(libs.plugins.kotlin.jvm) apply false
11+
alias(libs.plugins.kotlin.android) apply false
1112
alias(libs.plugins.sqldelight) apply false
1213
alias(libs.plugins.grammarKitComposer) apply false
1314
alias(libs.plugins.mavenPublishPlugin) apply false
1415
alias(libs.plugins.downloadPlugin) apply false
1516
alias(libs.plugins.kotlinter) apply false
17+
alias(libs.plugins.keeper) apply false
1618
}
1719

1820
// Having different versions of this lead to the issue mentioned here

‎core-tests-android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

‎core-tests-android/build.gradle.kts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import com.slack.keeper.optInToKeeper
2+
3+
plugins {
4+
alias(libs.plugins.androidApplication)
5+
alias(libs.plugins.kotlin.android)
6+
alias(libs.plugins.keeper)
7+
}
8+
9+
dependencies {
10+
implementation(projects.core)
11+
implementation(libs.androidx.core)
12+
implementation(libs.androidx.appcompat)
13+
implementation(libs.androidx.material)
14+
15+
androidTestImplementation(libs.androidx.junit)
16+
androidTestImplementation(libs.androidx.espresso.core)
17+
androidTestImplementation(libs.test.coroutines)
18+
androidTestImplementation(libs.test.turbine)
19+
}
20+
21+
android {
22+
namespace = "com.powersync.testing"
23+
compileSdk = libs.versions.android.compileSdk.get().toInt()
24+
25+
defaultConfig {
26+
applicationId = "com.powersync.testing"
27+
minSdk = libs.versions.android.minSdk.get().toInt()
28+
targetSdk = libs.versions.android.targetSdk.get().toInt()
29+
versionCode = 1
30+
versionName = "1.0"
31+
32+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
33+
}
34+
35+
buildTypes {
36+
release {
37+
isMinifyEnabled = true
38+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
39+
signingConfig = signingConfigs.getByName("debug")
40+
}
41+
}
42+
testBuildType = "release"
43+
compileOptions {
44+
sourceCompatibility = JavaVersion.VERSION_11
45+
targetCompatibility = JavaVersion.VERSION_11
46+
}
47+
kotlinOptions {
48+
jvmTarget = "11"
49+
}
50+
}
51+
52+
androidComponents {
53+
beforeVariants { it.optInToKeeper() }
54+
}

‎core-tests-android/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.powersync
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import app.cash.turbine.turbineScope
6+
import com.powersync.db.schema.Schema
7+
import com.powersync.testutils.UserRow
8+
import kotlinx.coroutines.runBlocking
9+
import kotlinx.coroutines.test.runTest
10+
import org.junit.After
11+
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
15+
import org.junit.Assert.*
16+
import org.junit.Before
17+
18+
@RunWith(AndroidJUnit4::class)
19+
class AndroidDatabaseTest {
20+
private lateinit var database: PowerSyncDatabase
21+
22+
@Before
23+
fun setupDatabase() {
24+
database =
25+
PowerSyncDatabase(
26+
factory = DatabaseDriverFactory(InstrumentationRegistry.getInstrumentation().targetContext),
27+
schema = Schema(UserRow.table),
28+
dbFilename = "testdb",
29+
)
30+
31+
runBlocking {
32+
database.disconnectAndClear(true)
33+
}
34+
}
35+
36+
@After
37+
fun tearDown() {
38+
runBlocking { database.disconnectAndClear(true) }
39+
}
40+
41+
@Test
42+
fun testLinksPowerSync() =
43+
runTest {
44+
database.get("SELECT powersync_rs_version() AS r;") { it.getString(0)!! }
45+
}
46+
47+
@Test
48+
fun testTableUpdates() =
49+
runTest {
50+
turbineScope {
51+
val query = database.watch("SELECT * FROM users") { UserRow.from(it) }.testIn(this)
52+
53+
// Wait for initial query
54+
assertEquals(0, query.awaitItem().size)
55+
56+
database.execute(
57+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
58+
listOf("Test", "test@example.org"),
59+
)
60+
assertEquals(1, query.awaitItem().size)
61+
62+
database.writeTransaction {
63+
it.execute(
64+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
65+
listOf("Test2", "test2@example.org"),
66+
)
67+
it.execute(
68+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
69+
listOf("Test3", "test3@example.org"),
70+
)
71+
}
72+
73+
assertEquals(3, query.awaitItem().size)
74+
75+
try {
76+
database.writeTransaction {
77+
it.execute("DELETE FROM users;")
78+
it.execute("syntax error, revert please")
79+
}
80+
} catch (e: Exception) {
81+
// Ignore
82+
}
83+
84+
database.execute(
85+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
86+
listOf("Test4", "test4@example.org"),
87+
)
88+
assertEquals(4, query.awaitItem().size)
89+
90+
query.expectNoEvents()
91+
query.cancel()
92+
}
93+
}
94+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.powersync.testutils
2+
3+
import com.powersync.db.SqlCursor
4+
import com.powersync.db.getString
5+
import com.powersync.db.schema.Column
6+
import com.powersync.db.schema.Table
7+
8+
data class UserRow(
9+
val id: String,
10+
val name: String,
11+
val email: String,
12+
) {
13+
companion object {
14+
fun from(cursor: SqlCursor): UserRow =
15+
UserRow(
16+
id = cursor.getString("id"),
17+
name = cursor.getString("name"),
18+
email = cursor.getString("email"),
19+
)
20+
21+
val table = Table(name = "users", columns = listOf(Column.text("name"), Column.text("email")))
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
>
4+
5+
<application
6+
android:allowBackup="true"
7+
android:label="@string/app_name"
8+
android:icon="@mipmap/ic_launcher"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.Powersyncroot"/>
12+
13+
</manifest>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:height="108dp"
5+
android:width="108dp"
6+
android:viewportHeight="108"
7+
android:viewportWidth="108">
8+
<path android:fillColor="#3DDC84"
9+
android:pathData="M0,0h108v108h-108z"/>
10+
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
11+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
12+
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
13+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
14+
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
15+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
16+
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
17+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
18+
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
19+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
20+
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
21+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
22+
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
23+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
24+
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
25+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
26+
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
27+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
28+
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
29+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
30+
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
31+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
32+
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
33+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
34+
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
35+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
36+
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
37+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
38+
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
39+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
40+
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
41+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
42+
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
43+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
44+
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
45+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
46+
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
47+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
48+
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
49+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
50+
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
51+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
52+
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
53+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
54+
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
55+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
56+
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
57+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
58+
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
59+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
60+
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
61+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
62+
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
63+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
64+
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
65+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
66+
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
67+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
68+
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
69+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
70+
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
71+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
72+
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
73+
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
74+
</vector>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path
8+
android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
9+
<aapt:attr name="android:fillColor">
10+
<gradient
11+
android:startY="49.59793"
12+
android:startX="42.9492"
13+
android:endY="92.4963"
14+
android:endX="85.84757"
15+
android:type="linear">
16+
<item
17+
android:color="#44000000"
18+
android:offset="0.0"/>
19+
<item
20+
android:color="#00000000"
21+
android:offset="1.0"/>
22+
</gradient>
23+
</aapt:attr>
24+
</path>
25+
<path
26+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
27+
android:fillColor="#FFFFFF"
28+
android:fillType="nonZero"
29+
android:strokeWidth="1"
30+
android:strokeColor="#00000000"/>
31+
</vector>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@drawable/ic_launcher_background"/>
4+
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
5+
<monochrome android:drawable="@drawable/ic_launcher_foreground"/>
6+
</adaptive-icon>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@drawable/ic_launcher_background"/>
4+
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
5+
<monochrome android:drawable="@drawable/ic_launcher_foreground"/>
6+
</adaptive-icon>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<resources xmlns:tools="http://schemas.android.com/tools">
2+
<!-- Base application theme. -->
3+
<style name="Theme.Powersyncroot" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
4+
<!-- Primary brand color. -->
5+
<item name="colorPrimary">@color/purple_200</item>
6+
<item name="colorPrimaryVariant">@color/purple_700</item>
7+
<item name="colorOnPrimary">@color/black</item>
8+
<!-- Secondary brand color. -->
9+
<item name="colorSecondary">@color/teal_200</item>
10+
<item name="colorSecondaryVariant">@color/teal_200</item>
11+
<item name="colorOnSecondary">@color/black</item>
12+
<!-- Status bar color. -->
13+
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
14+
<!-- Customize your theme here. -->
15+
</style>
16+
</resources>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="purple_200">#FFBB86FC</color>
4+
<color name="purple_500">#FF6200EE</color>
5+
<color name="purple_700">#FF3700B3</color>
6+
<color name="teal_200">#FF03DAC5</color>
7+
<color name="teal_700">#FF018786</color>
8+
<color name="black">#FF000000</color>
9+
<color name="white">#FFFFFFFF</color>
10+
</resources>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Core Android tests</string>
3+
</resources>

0 commit comments

Comments
 (0)