Skip to content

Commit e779f9f

Browse files
committed
Merge branch 'releases'
2 parents 1bb1d91 + 4c127c1 commit e779f9f

8 files changed

+115
-36
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This release will bump the Realm file format from version 22 to 23. Opening a fi
5757
* None.
5858

5959
### Fixed
60-
* Added proguard consumer files to Android debug artifacts. (Issue [#1150](https://github.com/realm/realm-kotlin/issues/1150))
60+
* Fixed various proguard issues. (Issue [#1150](https://github.com/realm/realm-kotlin/issues/1150))
6161
* Fixed bug when creating `RealmInstant` instaces with `RealmInstant.now()` in Kotlin Native. (Issue [#1182](https://github.com/realm/realm-kotlin/issues/1182))
6262
* Allow `@Index` on `Boolean` fields. (Issue [#1193](https://github.com/realm/realm-kotlin/issues/1193))
6363
* Fixed issue with spaces in realm file path on iOS (Issue [#1194](https://github.com/realm/realm-kotlin/issues/1194))

Jenkinsfile

+16
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ pipeline {
227227
])
228228
}
229229
}
230+
stage('Minified Sync Tests - Android') {
231+
when { expression { runTests } }
232+
steps {
233+
testWithServer([
234+
{
235+
testAndCollect("packages", 'cleanAllTests :test-sync:connectedAndroidtest -PincludeSdkModules=false -PtestBuildType=debugMinified')
236+
}
237+
])
238+
sh 'rm mapping.zip || true'
239+
zip([
240+
'zipFile': 'mapping.zip',
241+
'archive': true,
242+
'glob': 'packages/test-sync/build/outputs/mapping/debugMinified/mapping.txt'
243+
])
244+
}
245+
}
230246
stage('Gradle Plugin Integration Tests') {
231247
when { expression { runTests } }
232248
steps {

packages/gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ kotlin.android.buildTypeAttribute.keep=false
3333
# includeSdkModules=true
3434
# includeTestModules=true
3535
testRepository=build/m2-buildrepo/
36+
# Must either be `debug` or `debugMinified`
37+
testBuildType=debug

packages/library-base/proguard-rules-consumer-common.pro

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
1-
# Keep all classes implemeting the RealmObject interface
2-
-keep class io.realm.kotlin.types.RealmObject
3-
-keep class * implements io.realm.kotlin.types.RealmObject { *; }
4-
5-
# Keep all classes implemeting the EmbeddedRealmObject interface
6-
-keep class io.realm.kotlin.types.EmbeddedRealmObject
7-
-keep class * implements io.realm.kotlin.types.EmbeddedRealmObject { *; }
1+
## Keep Companion classes and class.Companion member of all classes that can be used in our API to
2+
# allow calling realmObjectCompanionOrThrow and realmObjectCompanionOrNull on the classes
3+
-keep class io.realm.kotlin.types.ObjectId$Companion
4+
-keepclassmembers class io.realm.kotlin.types.ObjectId {
5+
io.realm.kotlin.types.ObjectId$Companion Companion;
6+
}
7+
-keep class io.realm.kotlin.types.RealmInstant$Companion
8+
-keepclassmembers class io.realm.kotlin.types.RealmInstant {
9+
io.realm.kotlin.types.RealmInstant$Companion Companion;
10+
}
11+
-keep class org.mongodb.kbson.BsonObjectId$Companion
12+
-keepclassmembers class org.mongodb.kbson.BsonObjectId {
13+
org.mongodb.kbson.BsonObjectId$Companion Companion;
14+
}
15+
-keep class io.realm.kotlin.dynamic.DynamicRealmObject$Companion, io.realm.kotlin.dynamic.DynamicMutableRealmObject$Companion
16+
-keepclassmembers class io.realm.kotlin.dynamic.DynamicRealmObject, io.realm.kotlin.dynamic.DynamicMutableRealmObject {
17+
**$Companion Companion;
18+
}
19+
-keep,allowobfuscation class ** implements io.realm.kotlin.types.BaseRealmObject
20+
-keep class ** implements io.realm.kotlin.internal.RealmObjectCompanion
21+
-keepclassmembers class ** implements io.realm.kotlin.types.BaseRealmObject {
22+
**$Companion Companion;
23+
}
824

9-
# Preserve all native method names and the names of their classes.
25+
## Preserve all native method names and the names of their classes.
1026
-keepclasseswithmembernames,includedescriptorclasses class * {
1127
native <methods>;
1228
}
1329

30+
## Preserve all classes that are looked up from native code
1431
# Notification callback
1532
-keep class io.realm.kotlin.internal.interop.NotificationCallback {
1633
*;
1734
}
18-
1935
# Utils to convert core errors into Kotlin exceptions
2036
-keep class io.realm.kotlin.internal.interop.CoreErrorUtils {
2137
*;
2238
}
23-
2439
-keep class io.realm.kotlin.internal.interop.JVMScheduler {
2540
*;
2641
}
27-
28-
# Prevent all RealmObjects from having their companions stripped
29-
-keep class ** implements io.realm.kotlin.internal.RealmObjectCompanion {
30-
*;
31-
}
32-
3342
# Interop, sync-specific classes
3443
-keep class io.realm.kotlin.internal.interop.sync.NetworkTransport {
3544
# TODO OPTIMIZE Only keep actually required symbols
@@ -43,7 +52,6 @@
4352
# TODO OPTIMIZE Only keep actually required symbols
4453
*;
4554
}
46-
4755
-keep class io.realm.kotlin.internal.interop.sync.AppError {
4856
# TODO OPTIMIZE Only keep actually required symbols
4957
*;
@@ -99,12 +107,13 @@
99107
-keep class io.realm.kotlin.internal.interop.ProgressCallback {
100108
*;
101109
}
102-
110+
-keep class io.realm.kotlin.internal.interop.sync.ApiKeyWrapper {
111+
*;
112+
}
103113
# Preserve Function<X> methods as they back various functional interfaces called from JNI
104114
-keep class kotlin.jvm.functions.Function* {
105115
*;
106116
}
107-
108117
-keep class kotlin.Unit {
109118
*;
110119
}

packages/test-base/build.gradle.kts

+17-8
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,22 @@ android {
111111
}
112112

113113
buildTypes {
114-
getByName("release") {
115-
isMinifyEnabled = false
116-
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
117-
}
114+
// LibraryBuildType is not minifiable, but the current dependency from test-sync doesn't
115+
// allow test-base to be configured as a library. To test test-base with minification
116+
// change the AGP plugin to
117+
// id("com.android.application")
118+
// and uncomment the below buildType then you can run the full test suite with
119+
// ./gradlew test-base:clean test-base:connAT -PtestBuildType=debugMinified
120+
// Note that we cannot get memory consumption for non-debuggable build types so MemoryTests
121+
// will fail
122+
// testBuildType = (properties["testBuildType"] ?: "debug") as String
123+
// create("debugMinified") {
124+
// initWith(getByName("debug"))
125+
// matchingFallbacks.add("debug")
126+
// isMinifyEnabled = true
127+
// isDebuggable = false
128+
// proguardFiles("proguard-rules-test.pro")
129+
// }
118130
}
119131

120132
compileOptions {
@@ -131,9 +143,7 @@ android {
131143
}
132144

133145
kotlin {
134-
android("android") {
135-
publishLibraryVariants("release")
136-
}
146+
android("android")
137147
sourceSets {
138148
val androidMain by getting {
139149
dependencies {
@@ -150,7 +160,6 @@ kotlin {
150160
implementation("androidx.test:runner:${Versions.androidxTest}")
151161
implementation("androidx.test:rules:${Versions.androidxTest}")
152162
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}")
153-
implementation("androidx.multidex:multidex:${Versions.multidex}")
154163
}
155164
}
156165
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# We cannot discard unused symbols for the non-test configurations as it might all symbols not used
2+
-dontoptimize
3+
-dontshrink
4+
5+
## Required to make assertions on incorrect type messages in dynamic realm object tests pass
6+
-keep class io.realm.kotlin.types.BaseRealmObject
7+
-keep class io.realm.kotlin.types.RealmUUID
8+
9+
## Required to make introspection by reflection in NullabilityTests work
10+
-keep class io.realm.kotlin.types.MutableRealmInt
11+
-keep class io.realm.kotlin.entities.Nullability {
12+
*;
13+
}
14+
15+
## Required to make introspection by reflection in PrimaryKeyTests work
16+
-keepclassmembers class io.realm.kotlin.entities.primarykey.* {
17+
*;
18+
}

packages/test-sync/build.gradle.kts

+10-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTes
1919

2020
plugins {
2121
id("org.jetbrains.kotlin.multiplatform")
22-
id("com.android.library")
22+
id("com.android.application")
2323
kotlin("plugin.serialization") version Versions.kotlin
2424
// Test relies on the compiler plugin, but we cannot apply our full plugin from within the same
2525
// gradle run, so we just apply the compiler plugin directly as a dependency below instead
@@ -106,6 +106,8 @@ android {
106106
compileSdkVersion(Versions.Android.compileSdkVersion)
107107
buildToolsVersion = Versions.Android.buildToolsVersion
108108

109+
testBuildType = (properties["testBuildType"] ?: "debug") as String
110+
109111
defaultConfig {
110112
minSdkVersion(Versions.Android.minSdk)
111113
targetSdkVersion(Versions.Android.targetSdk)
@@ -123,9 +125,12 @@ android {
123125
}
124126

125127
buildTypes {
126-
getByName("release") {
127-
isMinifyEnabled = false
128-
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
128+
create("debugMinified") {
129+
initWith(getByName("debug"))
130+
matchingFallbacks.add("debug")
131+
isMinifyEnabled = true
132+
isDebuggable = false
133+
proguardFiles("proguard-rules-test.pro")
129134
}
130135
}
131136

@@ -143,9 +148,7 @@ android {
143148
}
144149

145150
kotlin {
146-
android("android") {
147-
publishLibraryVariants("release")
148-
}
151+
android("android")
149152
sourceSets {
150153
val androidMain by getting {
151154
dependencies {
@@ -162,7 +165,6 @@ kotlin {
162165
implementation("androidx.test:runner:${Versions.androidxTest}")
163166
implementation("androidx.test:rules:${Versions.androidxTest}")
164167
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}")
165-
implementation("androidx.multidex:multidex:${Versions.multidex}")
166168
}
167169
}
168170
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## We cannot discard unused symbols for the non-test configurations as it might all symbols not used
2+
-dontoptimize
3+
-dontshrink
4+
5+
# io.realm.kotlin.test.mongodb.shared.FlexibleSyncConfigurationTests.toString_nonEmpty,
6+
# SyncConfigTests.unsupportedSchemaTypesThrowException_flexibleSync and
7+
# SyncConfigTests.unsupportedSchemaTypesThrowException_partitionBasedSync verifies exception
8+
# messages with explicit class names in them
9+
-keep class io.realm.kotlin.mongodb.internal.SyncConfigurationImpl
10+
-keep class io.realm.kotlin.dynamic.DynamicRealmObject
11+
12+
## Serialization related rules
13+
-keepclasseswithmembers class **.*$Companion {
14+
kotlinx.serialization.KSerializer serializer(...);
15+
}
16+
# If a companion has the serializer function, keep the companion field on the original type so that
17+
# the reflective lookup succeeds.
18+
-if class **.*$Companion {
19+
kotlinx.serialization.KSerializer serializer(...);
20+
}
21+
-keepclassmembers class <1>.<2> {
22+
<1>.<2>$Companion Companion;
23+
}

0 commit comments

Comments
 (0)