Skip to content

Commit

Permalink
Publish Proguard configs as part of Guava.
Browse files Browse the repository at this point in the history
Fixes #2117

RELNOTES=The published Guava jar now includes Proguard configurations that are picked up automatically by the Android Gradle Plugin. This should help with warnings that were promoted to errors in Android Gradle Plugin 8.x.
PiperOrigin-RevId: 530451845
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed May 9, 2023
1 parent 7d41e19 commit aeba1e1
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 0 deletions.
10 changes: 10 additions & 0 deletions android/guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
<!-- TODO(cpovirk): want this only for dependency plugin but seems not to work there? Maven runs without failure, but the resulting Javadoc is missing the hoped-for inherited text -->
</dependencies>
<build>
<resources>
<resource>
<directory>..</directory>
<includes>
<include>LICENSE</include> <!-- copied from the parent pom because I couldn't figure out a way to make combine.children="append" work -->
<include>proguard/*</include>
</includes>
<targetPath>META-INF</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
<!-- TODO(cpovirk): want this only for dependency plugin but seems not to work there? Maven runs without failure, but the resulting Javadoc is missing the hoped-for inherited text -->
</dependencies>
<build>
<resources>
<resource>
<directory>..</directory>
<includes>
<include>LICENSE</include> <!-- copied from the parent pom because I couldn't figure out a way to make combine.children="append" work -->
<include>proguard/*</include>
</includes>
<targetPath>META-INF</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
33 changes: 33 additions & 0 deletions proguard/base.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Note: We intentionally don't add the flags we'd need to make Flags and Enums
# work. That's because the Proguard configuration required to make them work on
# optimized code would preclude lots of optimization, like converting enums
# into ints.

# Throwables uses internal APIs for lazy stack trace resolution
-dontnote sun.misc.SharedSecrets
-keep class sun.misc.SharedSecrets {
*** getJavaLangAccess(...);
}
-dontnote sun.misc.JavaLangAccess
-keep class sun.misc.JavaLangAccess {
*** getStackTraceElement(...);
*** getStackTraceDepth(...);
}

# FinalizableReferenceQueue calls this reflectively
# Proguard is intelligent enough to spot the use of reflection onto this, so we
# only need to keep the names, and allow it to be stripped out if
# FinalizableReferenceQueue is unused.
-keepnames class com.google.common.base.internal.Finalizer {
*** startFinalizer(...);
}
# However, it cannot "spot" that this method needs to be kept IF the class is.
-keepclassmembers class com.google.common.base.internal.Finalizer {
*** startFinalizer(...);
}
-keepnames class com.google.common.base.FinalizableReference {
void finalizeReferent();
}
-keepclassmembers class com.google.common.base.FinalizableReference {
void finalizeReferent();
}
12 changes: 12 additions & 0 deletions proguard/cache.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Striped64 uses this
-dontwarn sun.misc.Unsafe

# Striped64 appears to make some assumptions about object layout that
# really might not be safe. This should be investigated.
-keepclassmembers class com.google.common.cache.Striped64 {
*** base;
*** busy;
}
-keepclassmembers class com.google.common.cache.Striped64$Cell {
<fields>;
}
34 changes: 34 additions & 0 deletions proguard/collect.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-dontwarn java.lang.SafeVarargs

# The nested FieldSettersHolder class looks these up.
#
# We use -keepclassmembernames because we want for ImmutableMultimap and its
# fields to be stripped if it's unused: -keepclassmembernames says that, *if*
# you're keeping the fields, you need to leave their names untouched. (Anyone
# who is using ImmutableMultimap will certainly be using its fields. So we
# don't need to worry that an ImmutableMultimap user will have the fields
# optimized away.)
#
# This configuration is untested....
-keepclassmembernames class com.google.common.collect.ImmutableMultimap {
*** map;
*** size;
}
# similarly:
-keepclassmembernames class com.google.common.collect.ConcurrentHashMultiset {
*** countMap;
}
# similarly:
-keepclassmembernames class com.google.common.collect.ImmutableSetMultimap {
*** emptySet;
}
# similarly:
-keepclassmembernames class com.google.common.collect.AbstractSortedMultiset {
*** comparator;
}
# similarly:
-keepclassmembernames class com.google.common.collect.TreeMultiset {
*** range;
*** rootReference;
*** header;
}
40 changes: 40 additions & 0 deletions proguard/concurrent.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Futures.getChecked, in both of its variants, is incompatible with proguard.

# Used by AtomicReferenceFieldUpdater and sun.misc.Unsafe
-keepclassmembers class com.google.common.util.concurrent.AbstractFuture** {
*** waiters;
*** value;
*** listeners;
*** thread;
*** next;
}
-keepclassmembers class com.google.common.util.concurrent.AtomicDouble {
*** value;
}
-keepclassmembers class com.google.common.util.concurrent.AggregateFutureState {
*** remaining;
*** seenExceptions;
}

# Since Unsafe is using the field offsets of these inner classes, we don't want
# to have class merging or similar tricks applied to these classes and their
# fields. It's safe to allow obfuscation, since the by-name references are
# already preserved in the -keep statement above.
-keep,allowshrinking,allowobfuscation class com.google.common.util.concurrent.AbstractFuture** {
<fields>;
}

# AbstractFuture uses this
-dontwarn sun.misc.Unsafe

# MoreExecutors references AppEngine
-dontnote com.google.appengine.api.ThreadManager
-keep class com.google.appengine.api.ThreadManager {
static *** currentRequestThreadFactory(...);
}
-dontnote com.google.apphosting.api.ApiProxy
-keep class com.google.apphosting.api.ApiProxy {
static *** getCurrentEnvironment (...);
}

-dontwarn java.lang.SafeVarargs
12 changes: 12 additions & 0 deletions proguard/hash.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# LittleEndianByteArray uses this
-dontwarn sun.misc.Unsafe

# Striped64 appears to make some assumptions about object layout that
# really might not be safe. This should be investigated.
-keepclassmembers class com.google.common.hash.Striped64 {
*** base;
*** busy;
}
-keepclassmembers class com.google.common.hash.Striped64$Cell {
<fields>;
}
3 changes: 3 additions & 0 deletions proguard/io.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-keep class java.lang.Throwable {
*** addSuppressed(...);
}
2 changes: 2 additions & 0 deletions proguard/primitives.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# UnsignedBytes uses this
-dontwarn sun.misc.Unsafe
9 changes: 9 additions & 0 deletions proguard/reflect.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Warning: common.reflect (like reflection in general) is typically slow and
# unreliable under Android. We do not recommend using it. This Proguard config
# exists only to avoid breaking the builds of users who already have
# common.reflect in their transitive dependencies.
#
-dontwarn com.google.common.reflect.Invokable
-dontwarn com.google.common.reflect.Invokable$ConstructorInvokable
-dontwarn com.google.common.reflect.Invokable$MethodInvokable
-dontwarn com.google.common.reflect.Parameter

0 comments on commit aeba1e1

Please sign in to comment.