Run R8 with necessary Tethering classpath classes
R8 emits "missing class" warnings when optimizing Tethering.apk
because Tethering packages the already built TetheringApiXLib, but does
not specify any classpath library, which are actually needed for R8.
This causes wrong optimizations, where R8 would sometimes strip out code
that it thinks is unused (because it considers it unreachable due to the
missing class, or it does not know the superclass of a callback and
thinks the overridden methods cannot be called).
Add the necessary classpath libraries to remove the warnings.
Bug: 226127213
Test: m
Change-Id: Icd639d2783a2adc21e05a3b44f276ad72ad1e2d3
diff --git a/Tethering/Android.bp b/Tethering/Android.bp
index f3d6aee..3ab1ec2 100644
--- a/Tethering/Android.bp
+++ b/Tethering/Android.bp
@@ -26,6 +26,21 @@
}
java_defaults {
+ name: "TetheringExternalLibs",
+ // Libraries not including Tethering's own framework-tethering (different flavors of that one
+ // are needed depending on the build rule)
+ libs: [
+ "framework-connectivity.stubs.module_lib",
+ "framework-connectivity-t.stubs.module_lib",
+ "framework-statsd.stubs.module_lib",
+ "framework-wifi",
+ "framework-bluetooth",
+ "unsupportedappusage",
+ ],
+ defaults_visibility: ["//visibility:private"],
+}
+
+java_defaults {
name: "TetheringAndroidLibraryDefaults",
srcs: [
"apishim/**/*.java",
@@ -51,14 +66,9 @@
"netd-client",
"tetheringstatsprotos",
],
+ defaults: ["TetheringExternalLibs"],
libs: [
- "framework-connectivity",
- "framework-connectivity-t.stubs.module_lib",
- "framework-statsd.stubs.module_lib",
"framework-tethering.impl",
- "framework-wifi",
- "framework-bluetooth",
- "unsupportedappusage",
],
plugins: ["java_api_finder"],
manifest: "AndroidManifestBase.xml",
@@ -148,9 +158,17 @@
resource_dirs: [
"res",
],
+ // Libs are not actually needed to build here since build rules using these defaults are just
+ // packaging the TetheringApiXLibs in APKs, but they are necessary so that R8 has the right
+ // references to optimize the code. Without these, there will be missing class warnings and code
+ // may be wrongly optimized.
+ // R8 runs after jarjar, so the framework-X libraries need to be the post-jarjar artifacts
+ // (framework-tethering.impl), if they are not just stubs, so that the name of jarjared
+ // classes match.
+ // TODO(b/229727645): ensure R8 fails the build fully if libraries are missing
+ defaults: ["TetheringExternalLibs"],
libs: [
- "framework-tethering",
- "framework-wifi",
+ "framework-tethering.impl",
],
jarjar_rules: "jarjar-rules.txt",
optimize: {