Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test stage with minified Android builds #1190

Merged
merged 8 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* None.

### Fixed
* Added proguard consumer files to Android debug artifacts. (Issue [#1150](https://github.com/realm/realm-kotlin/issues/1150))
* Fixed various proguard issues. (Issue [#1150](https://github.com/realm/realm-kotlin/issues/1150))
* Fixed bug when creating `RealmInstant` instaces with `RealmInstant.now()` in Kotlin Native. (Issue [#1182](https://github.com/realm/realm-kotlin/issues/1182))
* Allow `@Index` on `Boolean` fields. (Issue [#1193](https://github.com/realm/realm-kotlin/issues/1193))
* Fixed issue with spaces in realm file path on iOS (Issue [#1194](https://github.com/realm/realm-kotlin/issues/1194))
Expand Down
16 changes: 16 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ pipeline {
])
}
}
stage('Minified Sync Tests - Android') {
when { expression { runTests } }
steps {
testWithServer([
{
testAndCollect("packages", 'cleanAllTests :test-sync:connectedAndroidtest -PincludeSdkModules=false -PtestBuildType=debugMinified')
}
])
sh 'rm mapping.zip || true'
zip([
'zipFile': 'mapping.zip',
'archive': true,
'glob': 'packages/test-sync/build/outputs/mapping/debugMinified/mapping.txt'
])
}
}
stage('Gradle Plugin Integration Tests') {
when { expression { runTests } }
steps {
Expand Down
2 changes: 2 additions & 0 deletions packages/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ kotlin.android.buildTypeAttribute.keep=false
# includeSdkModules=true
# includeTestModules=true
testRepository=build/m2-buildrepo/
# debug/debugMinified
rorbech marked this conversation as resolved.
Show resolved Hide resolved
testBuildType=debug
47 changes: 28 additions & 19 deletions packages/library-base/proguard-rules-consumer-common.pro
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
# Keep all classes implemeting the RealmObject interface
-keep class io.realm.kotlin.types.RealmObject
-keep class * implements io.realm.kotlin.types.RealmObject { *; }

# Keep all classes implemeting the EmbeddedRealmObject interface
-keep class io.realm.kotlin.types.EmbeddedRealmObject
-keep class * implements io.realm.kotlin.types.EmbeddedRealmObject { *; }
## Keep Companion classes and class.Companion member of all classes that can be used in our API to
# allow calling realmObjectCompanionOrThrow and realmObjectCompanionOrNull on the classes
-keep class io.realm.kotlin.types.ObjectId$Companion
-keepclassmembers class io.realm.kotlin.types.ObjectId {
io.realm.kotlin.types.ObjectId$Companion Companion;
}
-keep class io.realm.kotlin.types.RealmInstant$Companion
-keepclassmembers class io.realm.kotlin.types.RealmInstant {
io.realm.kotlin.types.RealmInstant$Companion Companion;
}
-keep class org.mongodb.kbson.BsonObjectId$Companion
-keepclassmembers class org.mongodb.kbson.BsonObjectId {
org.mongodb.kbson.BsonObjectId$Companion Companion;
}
-keep class io.realm.kotlin.dynamic.DynamicRealmObject$Companion, io.realm.kotlin.dynamic.DynamicMutableRealmObject$Companion
-keepclassmembers class io.realm.kotlin.dynamic.DynamicRealmObject, io.realm.kotlin.dynamic.DynamicMutableRealmObject {
**$Companion Companion;
}
-keep,allowobfuscation class ** implements io.realm.kotlin.types.BaseRealmObject
-keep class ** implements io.realm.kotlin.internal.RealmObjectCompanion
-keepclassmembers class ** implements io.realm.kotlin.types.BaseRealmObject {
**$Companion Companion;
}

# Preserve all native method names and the names of their classes.
## Preserve all native method names and the names of their classes.
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}

## Preserve all classes that are looked up from native code
# Notification callback
-keep class io.realm.kotlin.internal.interop.NotificationCallback {
*;
}

# Utils to convert core errors into Kotlin exceptions
-keep class io.realm.kotlin.internal.interop.CoreErrorUtils {
*;
}

-keep class io.realm.kotlin.internal.interop.JVMScheduler {
*;
}

# Prevent all RealmObjects from having their companions stripped
-keep class ** implements io.realm.kotlin.internal.RealmObjectCompanion {
*;
}

# Interop, sync-specific classes
-keep class io.realm.kotlin.internal.interop.sync.NetworkTransport {
# TODO OPTIMIZE Only keep actually required symbols
Expand All @@ -43,7 +52,6 @@
# TODO OPTIMIZE Only keep actually required symbols
*;
}

-keep class io.realm.kotlin.internal.interop.sync.AppError {
# TODO OPTIMIZE Only keep actually required symbols
*;
Expand Down Expand Up @@ -96,12 +104,13 @@
-keep class io.realm.kotlin.internal.interop.NativePointer {
*;
}

-keep class io.realm.kotlin.internal.interop.sync.ApiKeyWrapper {
*;
}
# Preserve Function<X> methods as they back various functional interfaces called from JNI
-keep class kotlin.jvm.functions.Function* {
*;
}

-keep class kotlin.Unit {
*;
}
Expand Down
25 changes: 17 additions & 8 deletions packages/test-base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,22 @@ android {
}

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

compileOptions {
Expand All @@ -131,9 +143,7 @@ android {
}

kotlin {
android("android") {
publishLibraryVariants("release")
}
android("android")
rorbech marked this conversation as resolved.
Show resolved Hide resolved
sourceSets {
val androidMain by getting {
dependencies {
Expand All @@ -150,7 +160,6 @@ kotlin {
implementation("androidx.test:runner:${Versions.androidxTest}")
implementation("androidx.test:rules:${Versions.androidxTest}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}")
implementation("androidx.multidex:multidex:${Versions.multidex}")
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions packages/test-base/proguard-rules-test.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# We cannot discard unused symbols for the non-test configurations as it might all symbols not used
-dontoptimize
-dontshrink

## Required to make assertions on incorrect type messages in dynamic realm object tests pass
-keep class io.realm.kotlin.types.BaseRealmObject
-keep class io.realm.kotlin.types.RealmUUID

## Required to make introspection by reflection in NullabilityTests work
-keep class io.realm.kotlin.types.MutableRealmInt
-keep class io.realm.kotlin.entities.Nullability {
*;
}

## Required to make introspection by reflection in PrimaryKeyTests work
-keepclassmembers class io.realm.kotlin.entities.primarykey.* {
*;
}
18 changes: 10 additions & 8 deletions packages/test-sync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTes

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

testBuildType = (properties["testBuildType"] ?: "debug") as String

defaultConfig {
minSdkVersion(Versions.Android.minSdk)
targetSdkVersion(Versions.Android.targetSdk)
Expand All @@ -123,9 +125,12 @@ android {
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
create("debugMinified") {
initWith(getByName("debug"))
matchingFallbacks.add("debug")
isMinifyEnabled = true
isDebuggable = false
proguardFiles("proguard-rules-test.pro")
}
}

Expand All @@ -143,9 +148,7 @@ android {
}

kotlin {
android("android") {
publishLibraryVariants("release")
}
android("android")
sourceSets {
val androidMain by getting {
dependencies {
Expand All @@ -162,7 +165,6 @@ kotlin {
implementation("androidx.test:runner:${Versions.androidxTest}")
implementation("androidx.test:rules:${Versions.androidxTest}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.coroutines}")
implementation("androidx.multidex:multidex:${Versions.multidex}")
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions packages/test-sync/proguard-rules-test.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## We cannot discard unused symbols for the non-test configurations as it might all symbols not used
-dontoptimize
-dontshrink

# io.realm.kotlin.test.mongodb.shared.FlexibleSyncConfigurationTests.toString_nonEmpty,
# SyncConfigTests.unsupportedSchemaTypesThrowException_flexibleSync and
# SyncConfigTests.unsupportedSchemaTypesThrowException_partitionBasedSync verifies exception
# messages with explicit class names in them
-keep class io.realm.kotlin.mongodb.internal.SyncConfigurationImpl
-keep class io.realm.kotlin.dynamic.DynamicRealmObject

## Serialization related rules
-keepclasseswithmembers class **.*$Companion {
kotlinx.serialization.KSerializer serializer(...);
}
# If a companion has the serializer function, keep the companion field on the original type so that
# the reflective lookup succeeds.
-if class **.*$Companion {
kotlinx.serialization.KSerializer serializer(...);
}
-keepclassmembers class <1>.<2> {
<1>.<2>$Companion Companion;
}