diff --git a/.fernignore b/.fernignore index e1c0d26e..f1c176f1 100644 --- a/.fernignore +++ b/.fernignore @@ -84,3 +84,5 @@ src/test/java/com/whop/api/helpers/ .fern/replay.lock .fern/replay.yml .gitattributes +# Remove when Fern emits and tests equivalent Android consumer rules. +src/main/resources/META-INF/proguard/whop-java.pro diff --git a/.github/package-smoke/src/main/java/PackageConsumer.java b/.github/package-smoke/src/main/java/PackageConsumer.java index f70a3c27..aea016dd 100644 --- a/.github/package-smoke/src/main/java/PackageConsumer.java +++ b/.github/package-smoke/src/main/java/PackageConsumer.java @@ -25,6 +25,19 @@ public static void main(String[] args) throws Exception { require( version.equals(WhopApiClient.class.getPackage().getImplementationVersion()), "installed jar manifest has an incorrect version"); + try (java.io.InputStream rules = + WhopApiClient.class.getResourceAsStream("/META-INF/proguard/whop-java.pro")) { + require(rules != null, "installed jar is missing Android consumer rules"); + String contents = new String(rules.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8); + require( + contents.contains("-keep class com.whop.api.core.NullableNonemptyFilter { *; }"), + "installed jar does not preserve the reflective nullable filter"); + require( + contents.contains("com.whop.api.types.**") + && contents.contains("com.whop.api.resources.**.requests.**") + && contents.contains("-keepattributes Signature,*Annotation*,InnerClasses,EnclosingMethod"), + "installed jar does not preserve Jackson models and annotations"); + } String apiVersion = java.util.Arrays.stream(ApiKeyApiVersionDate.class.getFields()) .filter(field -> Modifier.isStatic(field.getModifiers()) && field.getType() == ApiKeyApiVersionDate.class) diff --git a/MIGRATING.md b/MIGRATING.md index dfdbbebf..12921244 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -45,6 +45,12 @@ Closing a client releases HTTP resources the SDK created. A supplied `OkHttpClie The generated builder sends the API version matching its models. An explicit `apiVersionDate(...)` still overrides that pin; select an older API date only when your integration also expects its response shapes. +## Android release builds + +The SDK JAR includes consumer rules in `META-INF/proguard/whop-java.pro`. Android builds consume these automatically when R8 is enabled. They preserve Jackson model annotations, generated request and response models, and the `NullableNonemptyFilter` constructor and methods used through reflection. + +Without the filter rule, an optimized app can read API responses but fail while serializing a request with nullable fields. A debug build does not exercise that shrinker behavior. Validate a minified app when changing these rules. + ## Installing and releasing the package This change builds and tests the SDK without publishing it. `gradle.properties` keeps `version=0.0.0`, and the release workflow refuses to publish that placeholder. Generated metadata records the generator's input version; the release workflow stamps the artifact, source headers, and metadata from `gradle.properties` before building them. diff --git a/src/main/resources/META-INF/proguard/whop-java.pro b/src/main/resources/META-INF/proguard/whop-java.pro new file mode 100644 index 00000000..9150de8b --- /dev/null +++ b/src/main/resources/META-INF/proguard/whop-java.pro @@ -0,0 +1,7 @@ +-keepattributes Signature,*Annotation*,InnerClasses,EnclosingMethod +-keep class com.whop.api.types.** { *; } +-keep class com.whop.api.resources.**.types.** { *; } +-keep class com.whop.api.resources.**.requests.** { *; } +-keep class com.whop.api.core.NullableNonemptyFilter { *; } +-keep class com.fasterxml.jackson.databind.annotation.JacksonStdImpl +-keep,allowobfuscation,allowshrinking @com.fasterxml.jackson.databind.annotation.JacksonStdImpl class *