From 437adefb03de6531c46616f0f051e16ee55eb763 Mon Sep 17 00:00:00 2001 From: merkost Date: Fri, 7 Jul 2023 22:49:47 +1000 Subject: [PATCH] Added serialization plugin --- app/build.gradle | 15 ++++++++++----- app/proguard-rules.pro | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index aac92854..f5ed10c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,10 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -apply plugin: 'kotlin-kapt' +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'kotlin-android-extensions' + id 'kotlin-kapt' + id 'org.jetbrains.kotlin.plugin.serialization' version "$kotlin_version" +} def keystorePropertiesFile = rootProject.file("keystore.properties") def keystoreProperties = new Properties() @@ -10,7 +13,7 @@ if (keystorePropertiesFile.exists()) { } android { - compileSdkVersion 33 + compileSdk 33 defaultConfig { applicationId "com.simplemobiletools.notes.pro" @@ -70,4 +73,6 @@ dependencies { kapt 'androidx.room:room-compiler:2.5.1' implementation 'androidx.room:room-runtime:2.5.1' annotationProcessor 'androidx.room:room-compiler:2.5.1' + + implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1" } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f27914fe..eb348cee 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,3 +1,27 @@ -keep class com.simplemobiletools.notes.pro.models.* { ; } + +# Keep `Companion` object fields of serializable classes. +# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects. +-if @kotlinx.serialization.Serializable class ** +-keepclassmembers class <1> { + static <1>$Companion Companion; +} + +# Keep `serializer()` on companion objects (both default and named) of serializable classes. +-if @kotlinx.serialization.Serializable class ** { + static **$* *; +} +-keepclassmembers class <2>$<3> { + kotlinx.serialization.KSerializer serializer(...); +} + +# Keep `INSTANCE.serializer()` of serializable objects. +-if @kotlinx.serialization.Serializable class ** { + public static ** INSTANCE; +} +-keepclassmembers class <1> { + public static <1> INSTANCE; + kotlinx.serialization.KSerializer serializer(...); +}