Avoid duplicated classes for boot dex jars

When a boot classpath java library is directly or indirectly included in
APEXes, multiple variant of the library exist. When running the
hiddenapi tool, we need to eliminate the duplication, otherwise the tool
will complain.

Previously, we simply choose the platform variant of the java library
among the multiple variants. However, if the java library is marked not
available for the platform (i.e. "//apex_available:platform" is not in
the apex_available property), the platform variant does not exist and
thus it is not fed into the hiddenapi tool, which causes missing
references in the tool.

To solve the problem, the platform variant is selected only for the java
libs that are available for the platform. For those libs that are not
available for the platform, we choose one variant of it using a
heuristic; skip testing APEXes and choose com.android.art.release among
the com.android.art.* variants.

Bug: 128708192
Test: m

Change-Id: I33bf297eb3029696ae3504a011486210708fb2c2
This commit is contained in:
Jiyong Park 2019-12-02 19:50:03 +09:00
parent 505221f6e0
commit 2812df4edb
1 changed files with 18 additions and 5 deletions

View File

@ -16,6 +16,7 @@ package java
import (
"fmt"
"strings"
"android/soong/android"
)
@ -152,11 +153,23 @@ func stubFlagsRule(ctx android.SingletonContext) {
// Collect dex jar paths for modules that had hiddenapi encode called on them.
if h, ok := module.(hiddenAPIIntf); ok {
if jar := h.bootDexJar(); jar != nil {
// For a java lib included in an APEX, only take the one built for
// the platform variant, and skip the variants for APEXes.
// Otherwise, the hiddenapi tool will complain about duplicated classes
if a, ok := module.(android.ApexModule); ok {
if android.InAnyApex(module.Name()) && !a.IsForPlatform() {
// Don't add multiple variants of the same library to bootDexJars, otherwise
// hiddenapi tool will complain about duplicated classes. Such multiple variants
// of the same library can happen when the library is included in one or more APEXes.
// TODO(b/146308764): remove this heuristic
if a, ok := module.(android.ApexModule); ok && android.InAnyApex(module.Name()) {
if a.AvailableFor("//apex_available:platform") && !a.IsForPlatform() {
// skip the apex variants if the jar is available for the platform
return
}
apexName := a.ApexName()
if strings.Contains(apexName, "test") {
// skip the if the jar is in test APEX
return
}
if strings.Contains(apexName, "com.android.art") && apexName != "com.android.art.release" {
// skip the ART APEX variants other than com.android.art.release
return
}
}