From 80d834fb5587906d77dbb0dc83d056da23ffe0bb Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 1 Jun 2019 13:18:11 -0700 Subject: [PATCH] Use kotshi instead of moshi-kotlin-codegen --- app/build.gradle | 7 ++- app/proguard-moshi.pro | 49 ------------------- app/proguard-rules.pro | 2 +- .../topjohnwu/magisk/di/NetworkingModule.kt | 13 ++++- .../magisk/model/entity/MagiskApp.kt | 4 +- .../magisk/model/entity/MagiskConfig.kt | 4 +- .../magisk/model/entity/MagiskFlashable.kt | 4 +- .../magisk/model/entity/MagiskLink.kt | 4 +- 8 files changed, 26 insertions(+), 61 deletions(-) delete mode 100644 app/proguard-moshi.pro diff --git a/app/build.gradle b/app/build.gradle index 0405cf009..9d764198e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,7 @@ android { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), - 'proguard-rules.pro', 'proguard-moshi.pro', 'proguard-kotlin.pro' + 'proguard-rules.pro', 'proguard-kotlin.pro' } } @@ -86,7 +86,10 @@ dependencies { def vMoshi = "1.8.0" implementation "com.squareup.moshi:moshi:${vMoshi}" - kapt "com.squareup.moshi:moshi-kotlin-codegen:${vMoshi}" + + def vKotshi = "2.0.1" + implementation "se.ansman.kotshi:api:${vKotshi}" + kapt "se.ansman.kotshi:compiler:${vKotshi}" implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.browser:browser:1.0.0' diff --git a/app/proguard-moshi.pro b/app/proguard-moshi.pro deleted file mode 100644 index a5296c3f6..000000000 --- a/app/proguard-moshi.pro +++ /dev/null @@ -1,49 +0,0 @@ -# JSR 305 annotations are for embedding nullability information. --dontwarn javax.annotation.** - --keepclasseswithmembers class * { - @com.squareup.moshi.* ; -} - --keep @com.squareup.moshi.JsonQualifier interface * - -# Enum field names are used by the integrated EnumJsonAdapter. -# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi. --keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum { - ; -} - -# The name of @JsonClass types is used to look up the generated adapter. --keepnames @com.squareup.moshi.JsonClass class * - -# Retain generated JsonAdapters if annotated type is retained. --if @com.squareup.moshi.JsonClass class * --keep class <1>JsonAdapter { - (...); - ; -} --if @com.squareup.moshi.JsonClass class **$* --keep class <1>_<2>JsonAdapter { - (...); - ; -} --if @com.squareup.moshi.JsonClass class **$*$* --keep class <1>_<2>_<3>JsonAdapter { - (...); - ; -} --if @com.squareup.moshi.JsonClass class **$*$*$* --keep class <1>_<2>_<3>_<4>JsonAdapter { - (...); - ; -} --if @com.squareup.moshi.JsonClass class **$*$*$*$* --keep class <1>_<2>_<3>_<4>_<5>JsonAdapter { - (...); - ; -} --if @com.squareup.moshi.JsonClass class **$*$*$*$*$* --keep class <1>_<2>_<3>_<4>_<5>_<6>JsonAdapter { - (...); - ; -} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 6e6d2e170..1891bff0a 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -17,7 +17,7 @@ #} # Retrofit classes --keep,allowobfuscation class com.topjohnwu.magisk.data.network.** +-keep,allowobfuscation class com.topjohnwu.magisk.data.network.* # Snet -keepclassmembers class com.topjohnwu.magisk.utils.ISafetyNetHelper { *; } diff --git a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt index 3c96836c9..030a0034c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.di +import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.topjohnwu.magisk.Constants import com.topjohnwu.magisk.data.network.GithubRawApiServices @@ -11,6 +12,7 @@ import retrofit2.Converter import retrofit2.Retrofit import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory import retrofit2.converter.moshi.MoshiConverterFactory +import se.ansman.kotshi.KotshiJsonAdapterFactory val networkingModule = module { single { createOkHttpClient() } @@ -31,7 +33,9 @@ fun createOkHttpClient(): OkHttpClient { } fun createConverterFactory(): Converter.Factory { - val moshi = Moshi.Builder().build() + val moshi = Moshi.Builder() + .add(JsonAdapterFactory.INSTANCE) + .build() return MoshiConverterFactory.create(moshi) } @@ -50,6 +54,13 @@ fun createRetrofit( .client(okHttpClient) } +@KotshiJsonAdapterFactory +abstract class JsonAdapterFactory : JsonAdapter.Factory { + companion object { + val INSTANCE: JsonAdapterFactory = KotshiJsonAdapterFactory + } +} + inline fun createApiService(retrofitBuilder: Retrofit.Builder, baseUrl: String): T { return retrofitBuilder .baseUrl(baseUrl) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskApp.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskApp.kt index 6fc7d3cfd..fb9c4f7ff 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskApp.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskApp.kt @@ -1,8 +1,8 @@ package com.topjohnwu.magisk.model.entity -import com.squareup.moshi.JsonClass +import se.ansman.kotshi.JsonSerializable -@JsonClass(generateAdapter = true) +@JsonSerializable data class MagiskApp( val version: String, val versionCode: String, diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskConfig.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskConfig.kt index ec5a76478..4983dabbe 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskConfig.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskConfig.kt @@ -1,8 +1,8 @@ package com.topjohnwu.magisk.model.entity -import com.squareup.moshi.JsonClass +import se.ansman.kotshi.JsonSerializable -@JsonClass(generateAdapter = true) +@JsonSerializable data class MagiskConfig( val app: MagiskApp, val uninstaller: MagiskLink, diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskFlashable.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskFlashable.kt index bc7323021..a9b3ce04b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskFlashable.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskFlashable.kt @@ -1,9 +1,9 @@ package com.topjohnwu.magisk.model.entity import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass +import se.ansman.kotshi.JsonSerializable -@JsonClass(generateAdapter = true) +@JsonSerializable data class MagiskFlashable( val version: String, val versionCode: String, diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLink.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLink.kt index 28df1788e..599dfb8ad 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLink.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskLink.kt @@ -1,8 +1,8 @@ package com.topjohnwu.magisk.model.entity -import com.squareup.moshi.JsonClass +import se.ansman.kotshi.JsonSerializable -@JsonClass(generateAdapter = true) +@JsonSerializable data class MagiskLink( val link: String ) \ No newline at end of file