Skip to content

Commit aeba1e1

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedMay 9, 2023
Publish Proguard configs as part of Guava.
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
1 parent 7d41e19 commit aeba1e1

File tree

10 files changed

+165
-0
lines changed

10 files changed

+165
-0
lines changed
 

‎android/guava/pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
<!-- 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 -->
4848
</dependencies>
4949
<build>
50+
<resources>
51+
<resource>
52+
<directory>..</directory>
53+
<includes>
54+
<include>LICENSE</include> <!-- copied from the parent pom because I couldn't figure out a way to make combine.children="append" work -->
55+
<include>proguard/*</include>
56+
</includes>
57+
<targetPath>META-INF</targetPath>
58+
</resource>
59+
</resources>
5060
<plugins>
5161
<plugin>
5262
<artifactId>maven-jar-plugin</artifactId>

‎guava/pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
<!-- 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 -->
4848
</dependencies>
4949
<build>
50+
<resources>
51+
<resource>
52+
<directory>..</directory>
53+
<includes>
54+
<include>LICENSE</include> <!-- copied from the parent pom because I couldn't figure out a way to make combine.children="append" work -->
55+
<include>proguard/*</include>
56+
</includes>
57+
<targetPath>META-INF</targetPath>
58+
</resource>
59+
</resources>
5060
<plugins>
5161
<plugin>
5262
<artifactId>maven-jar-plugin</artifactId>

‎proguard/base.pro

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Note: We intentionally don't add the flags we'd need to make Flags and Enums
2+
# work. That's because the Proguard configuration required to make them work on
3+
# optimized code would preclude lots of optimization, like converting enums
4+
# into ints.
5+
6+
# Throwables uses internal APIs for lazy stack trace resolution
7+
-dontnote sun.misc.SharedSecrets
8+
-keep class sun.misc.SharedSecrets {
9+
*** getJavaLangAccess(...);
10+
}
11+
-dontnote sun.misc.JavaLangAccess
12+
-keep class sun.misc.JavaLangAccess {
13+
*** getStackTraceElement(...);
14+
*** getStackTraceDepth(...);
15+
}
16+
17+
# FinalizableReferenceQueue calls this reflectively
18+
# Proguard is intelligent enough to spot the use of reflection onto this, so we
19+
# only need to keep the names, and allow it to be stripped out if
20+
# FinalizableReferenceQueue is unused.
21+
-keepnames class com.google.common.base.internal.Finalizer {
22+
*** startFinalizer(...);
23+
}
24+
# However, it cannot "spot" that this method needs to be kept IF the class is.
25+
-keepclassmembers class com.google.common.base.internal.Finalizer {
26+
*** startFinalizer(...);
27+
}
28+
-keepnames class com.google.common.base.FinalizableReference {
29+
void finalizeReferent();
30+
}
31+
-keepclassmembers class com.google.common.base.FinalizableReference {
32+
void finalizeReferent();
33+
}

‎proguard/cache.pro

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Striped64 uses this
2+
-dontwarn sun.misc.Unsafe
3+
4+
# Striped64 appears to make some assumptions about object layout that
5+
# really might not be safe. This should be investigated.
6+
-keepclassmembers class com.google.common.cache.Striped64 {
7+
*** base;
8+
*** busy;
9+
}
10+
-keepclassmembers class com.google.common.cache.Striped64$Cell {
11+
<fields>;
12+
}

‎proguard/collect.pro

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-dontwarn java.lang.SafeVarargs
2+
3+
# The nested FieldSettersHolder class looks these up.
4+
#
5+
# We use -keepclassmembernames because we want for ImmutableMultimap and its
6+
# fields to be stripped if it's unused: -keepclassmembernames says that, *if*
7+
# you're keeping the fields, you need to leave their names untouched. (Anyone
8+
# who is using ImmutableMultimap will certainly be using its fields. So we
9+
# don't need to worry that an ImmutableMultimap user will have the fields
10+
# optimized away.)
11+
#
12+
# This configuration is untested....
13+
-keepclassmembernames class com.google.common.collect.ImmutableMultimap {
14+
*** map;
15+
*** size;
16+
}
17+
# similarly:
18+
-keepclassmembernames class com.google.common.collect.ConcurrentHashMultiset {
19+
*** countMap;
20+
}
21+
# similarly:
22+
-keepclassmembernames class com.google.common.collect.ImmutableSetMultimap {
23+
*** emptySet;
24+
}
25+
# similarly:
26+
-keepclassmembernames class com.google.common.collect.AbstractSortedMultiset {
27+
*** comparator;
28+
}
29+
# similarly:
30+
-keepclassmembernames class com.google.common.collect.TreeMultiset {
31+
*** range;
32+
*** rootReference;
33+
*** header;
34+
}

‎proguard/concurrent.pro

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Futures.getChecked, in both of its variants, is incompatible with proguard.
2+
3+
# Used by AtomicReferenceFieldUpdater and sun.misc.Unsafe
4+
-keepclassmembers class com.google.common.util.concurrent.AbstractFuture** {
5+
*** waiters;
6+
*** value;
7+
*** listeners;
8+
*** thread;
9+
*** next;
10+
}
11+
-keepclassmembers class com.google.common.util.concurrent.AtomicDouble {
12+
*** value;
13+
}
14+
-keepclassmembers class com.google.common.util.concurrent.AggregateFutureState {
15+
*** remaining;
16+
*** seenExceptions;
17+
}
18+
19+
# Since Unsafe is using the field offsets of these inner classes, we don't want
20+
# to have class merging or similar tricks applied to these classes and their
21+
# fields. It's safe to allow obfuscation, since the by-name references are
22+
# already preserved in the -keep statement above.
23+
-keep,allowshrinking,allowobfuscation class com.google.common.util.concurrent.AbstractFuture** {
24+
<fields>;
25+
}
26+
27+
# AbstractFuture uses this
28+
-dontwarn sun.misc.Unsafe
29+
30+
# MoreExecutors references AppEngine
31+
-dontnote com.google.appengine.api.ThreadManager
32+
-keep class com.google.appengine.api.ThreadManager {
33+
static *** currentRequestThreadFactory(...);
34+
}
35+
-dontnote com.google.apphosting.api.ApiProxy
36+
-keep class com.google.apphosting.api.ApiProxy {
37+
static *** getCurrentEnvironment (...);
38+
}
39+
40+
-dontwarn java.lang.SafeVarargs

‎proguard/hash.pro

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# LittleEndianByteArray uses this
2+
-dontwarn sun.misc.Unsafe
3+
4+
# Striped64 appears to make some assumptions about object layout that
5+
# really might not be safe. This should be investigated.
6+
-keepclassmembers class com.google.common.hash.Striped64 {
7+
*** base;
8+
*** busy;
9+
}
10+
-keepclassmembers class com.google.common.hash.Striped64$Cell {
11+
<fields>;
12+
}

‎proguard/io.pro

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-keep class java.lang.Throwable {
2+
*** addSuppressed(...);
3+
}

‎proguard/primitives.pro

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# UnsignedBytes uses this
2+
-dontwarn sun.misc.Unsafe

‎proguard/reflect.pro

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Warning: common.reflect (like reflection in general) is typically slow and
2+
# unreliable under Android. We do not recommend using it. This Proguard config
3+
# exists only to avoid breaking the builds of users who already have
4+
# common.reflect in their transitive dependencies.
5+
#
6+
-dontwarn com.google.common.reflect.Invokable
7+
-dontwarn com.google.common.reflect.Invokable$ConstructorInvokable
8+
-dontwarn com.google.common.reflect.Invokable$MethodInvokable
9+
-dontwarn com.google.common.reflect.Parameter

0 commit comments

Comments
 (0)
Please sign in to comment.