mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Merge pull request #1152 from Tolriq/R8_fix
Fix R8 keeping all Kotlin metadata when using Moshi.
This commit is contained in:
@@ -54,7 +54,7 @@ public final class Util {
|
|||||||
Class<? extends Annotation> metadata = null;
|
Class<? extends Annotation> metadata = null;
|
||||||
try {
|
try {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
metadata = (Class<? extends Annotation>) Class.forName("kotlin.Metadata");
|
metadata = (Class<? extends Annotation>) Class.forName(getKotlinMetadataClassName());
|
||||||
} catch (ClassNotFoundException ignored) {
|
} catch (ClassNotFoundException ignored) {
|
||||||
}
|
}
|
||||||
METADATA = metadata;
|
METADATA = metadata;
|
||||||
@@ -69,6 +69,11 @@ public final class Util {
|
|||||||
DEFAULT_CONSTRUCTOR_MARKER = defaultConstructorMarker;
|
DEFAULT_CONSTRUCTOR_MARKER = defaultConstructorMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extracted as a method with a keep rule to prevent R8 from keeping Kotlin Metada
|
||||||
|
private static String getKotlinMetadataClassName() {
|
||||||
|
return "kotlin.Metadata";
|
||||||
|
}
|
||||||
|
|
||||||
private Util() {
|
private Util() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,3 +14,8 @@
|
|||||||
<fields>;
|
<fields>;
|
||||||
**[] values();
|
**[] values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Keep helper method to avoid R8 optimisation that would keep all Kotlin Metadata when unwanted
|
||||||
|
-keepclassmembers class com.squareup.moshi.internal.Util {
|
||||||
|
private static java.lang.String getKotlinMetadataClassName();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user