From ae96fbd6b7e0b356258b15a88a56accf1c70550f Mon Sep 17 00:00:00 2001 From: Arnab Nandy Date: Sat, 18 Jul 2026 11:32:17 +0530 Subject: [PATCH] fix: preserve Data null sentinels with R8 Signed-off-by: Arnab Nandy --- docs/android.md | 9 +++++++++ .../proguard-google-api-client.txt | 7 +++++++ .../resources/META-INF/proguard/google-api-client.pro | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/docs/android.md b/docs/android.md index 9ed63abe0..950675052 100644 --- a/docs/android.md +++ b/docs/android.md @@ -35,6 +35,14 @@ public void onCreate(Bundle savedInstanceState) { Begin by reading the [Android development instructions][http-client-android] for the Google HTTP Client Library for Java. +## R8 and ProGuard + +The `google-api-client` artifact includes consumer rules required by the +library. If your build does not automatically consume rules from dependency +JARs, include the rules from +[`google-api-client.pro`][google-api-client-proguard] in your R8 or ProGuard +configuration. + ## Authentication As described in the [Android development instructions][http-client-android], the @@ -75,5 +83,6 @@ if (files == null || files.isEmpty()) { [play-services]: https://developer.android.com/google/play-services/index.html [account-manager]: http://developer.android.com/reference/android/accounts/AccountManager.html [http-client-android]: https://github.com/googleapis/google-http-java-client/wiki/Android +[google-api-client-proguard]: https://github.com/googleapis/google-api-java-client/blob/main/google-api-client/src/main/resources/META-INF/proguard/google-api-client.pro [oauth2-android]: https://github.com/googleapis/google-api-java-client#oauth2-android [quickstart]: https://developers.google.com/drive/api/v3/quickstart/java diff --git a/google-api-client-assembly/proguard-google-api-client.txt b/google-api-client-assembly/proguard-google-api-client.txt index 68ec92b85..0b87c7ddb 100644 --- a/google-api-client-assembly/proguard-google-api-client.txt +++ b/google-api-client-assembly/proguard-google-api-client.txt @@ -10,6 +10,13 @@ @com.google.api.client.util.Key ; } +# Data's magic null values rely on reference identity. Keep R8 from replacing +# wrapper instances with canonical values such as Boolean.TRUE. + +-keepclassmembers class com.google.api.client.util.Data { + public static final *** NULL_*; +} + # Needed by google-http-client-android when linking against an older platform version -dontwarn com.google.api.client.extensions.android.** diff --git a/google-api-client/src/main/resources/META-INF/proguard/google-api-client.pro b/google-api-client/src/main/resources/META-INF/proguard/google-api-client.pro index 8f805a49a..9b40efd62 100644 --- a/google-api-client/src/main/resources/META-INF/proguard/google-api-client.pro +++ b/google-api-client/src/main/resources/META-INF/proguard/google-api-client.pro @@ -1,2 +1,9 @@ # https://github.com/googleapis/google-api-java-client/issues/1450 -keep public class com.google.api.client.googleapis.GoogleUtils + +# Data's magic null values rely on reference identity. Keep R8 from replacing +# wrapper instances with canonical values such as Boolean.TRUE. +# https://github.com/googleapis/google-api-java-client/issues/2603 +-keepclassmembers class com.google.api.client.util.Data { + public static final *** NULL_*; +}