Merge "Update default system Proguard config rules"
diff --git a/core/binary.mk b/core/binary.mk
index cf47374..94e3a0f 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -32,6 +32,12 @@
   endif
 endif
 
+# Third party code has additional no-override flags.
+is_third_party :=
+ifneq ($(filter external/% hardware/% vendor/%,$(LOCAL_PATH)),)
+  is_third_party := true
+endif
+
 my_soong_problems :=
 
 # The following LOCAL_ variables will be modified in this file.
@@ -48,6 +54,10 @@
 my_cppflags := $(LOCAL_CPPFLAGS)
 my_cflags_no_override := $(GLOBAL_CLANG_CFLAGS_NO_OVERRIDE)
 my_cppflags_no_override := $(GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE)
+ifdef is_third_party
+    my_cflags_no_override += $(GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE)
+    my_cppflags_no_override += $(GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE)
+endif
 my_ldflags := $(LOCAL_LDFLAGS)
 my_ldlibs := $(LOCAL_LDLIBS)
 my_asflags := $(LOCAL_ASFLAGS)
diff --git a/tools/compliance/Android.bp b/tools/compliance/Android.bp
index e74986d..d5965f8 100644
--- a/tools/compliance/Android.bp
+++ b/tools/compliance/Android.bp
@@ -86,6 +86,16 @@
     testSrcs: ["cmd/textnotice/textnotice_test.go"],
 }
 
+blueprint_go_binary {
+    name: "xmlnotice",
+    srcs: ["cmd/xmlnotice/xmlnotice.go"],
+    deps: [
+        "compliance-module",
+        "blueprint-deptools",
+    ],
+    testSrcs: ["cmd/xmlnotice/xmlnotice_test.go"],
+}
+
 bootstrap_go_package {
     name: "compliance-module",
     srcs: [
diff --git a/tools/compliance/cmd/bom/bom.go b/tools/compliance/cmd/bom/bom.go
index aaec786..5363a59 100644
--- a/tools/compliance/cmd/bom/bom.go
+++ b/tools/compliance/cmd/bom/bom.go
@@ -29,7 +29,7 @@
 
 var (
 	outputFile  = flag.String("o", "-", "Where to write the bill of materials. (default stdout)")
-	stripPrefix = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
+	stripPrefix = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
 
 	failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
 	failNoLicenses    = fmt.Errorf("No licenses found")
@@ -39,7 +39,20 @@
 	stdout      io.Writer
 	stderr      io.Writer
 	rootFS      fs.FS
-	stripPrefix string
+	stripPrefix []string
+}
+
+func (ctx context) strip(installPath string) string {
+	for _, prefix := range ctx.stripPrefix {
+		if strings.HasPrefix(installPath, prefix) {
+			p := strings.TrimPrefix(installPath, prefix)
+			if 0 == len(p) {
+				continue
+			}
+			return p
+		}
+	}
+	return installPath
 }
 
 func init() {
@@ -54,6 +67,19 @@
 	}
 }
 
+// newMultiString creates a flag that allows multiple values in an array.
+func newMultiString(name, usage string) *multiString {
+	var f multiString
+	flag.Var(&f, name, usage)
+	return &f
+}
+
+// multiString implements the flag `Value` interface for multiple strings.
+type multiString []string
+
+func (ms *multiString) String() string     { return strings.Join(*ms, ", ") }
+func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil }
+
 func main() {
 	flag.Parse()
 
@@ -135,11 +161,7 @@
 	}
 
 	for path := range ni.InstallPaths() {
-		if 0 < len(ctx.stripPrefix) && strings.HasPrefix(path, ctx.stripPrefix) {
-			fmt.Fprintln(ctx.stdout, path[len(ctx.stripPrefix):])
-		} else {
-			fmt.Fprintln(ctx.stdout, path)
-		}
+		fmt.Fprintln(ctx.stdout, ctx.strip(path))
 	}
 	return nil
 }
diff --git a/tools/compliance/cmd/bom/bom_test.go b/tools/compliance/cmd/bom/bom_test.go
index 163ac2a..4a9889f 100644
--- a/tools/compliance/cmd/bom/bom_test.go
+++ b/tools/compliance/cmd/bom/bom_test.go
@@ -282,7 +282,7 @@
 				rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
 			}
 
-			ctx := context{stdout, stderr, os.DirFS("."), tt.stripPrefix}
+			ctx := context{stdout, stderr, os.DirFS("."), []string{tt.stripPrefix}}
 
 			err := billOfMaterials(&ctx, rootFiles...)
 			if err != nil {
diff --git a/tools/compliance/cmd/dumpgraph/dumpgraph.go b/tools/compliance/cmd/dumpgraph/dumpgraph.go
index 02ab025..fa16b1b 100644
--- a/tools/compliance/cmd/dumpgraph/dumpgraph.go
+++ b/tools/compliance/cmd/dumpgraph/dumpgraph.go
@@ -29,7 +29,7 @@
 var (
 	graphViz        = flag.Bool("dot", false, "Whether to output graphviz (i.e. dot) format.")
 	labelConditions = flag.Bool("label_conditions", false, "Whether to label target nodes with conditions.")
-	stripPrefix     = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
+	stripPrefix     = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
 
 	failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
 	failNoLicenses    = fmt.Errorf("No licenses found")
@@ -38,7 +38,20 @@
 type context struct {
 	graphViz        bool
 	labelConditions bool
-	stripPrefix     string
+	stripPrefix     []string
+}
+
+func (ctx context) strip(installPath string) string {
+	for _, prefix := range ctx.stripPrefix {
+		if strings.HasPrefix(installPath, prefix) {
+			p := strings.TrimPrefix(installPath, prefix)
+			if 0 == len(p) {
+				continue
+			}
+			return p
+		}
+	}
+	return installPath
 }
 
 func init() {
@@ -60,6 +73,19 @@
 	}
 }
 
+// newMultiString creates a flag that allows multiple values in an array.
+func newMultiString(name, usage string) *multiString {
+	var f multiString
+	flag.Var(&f, name, usage)
+	return &f
+}
+
+// multiString implements the flag `Value` interface for multiple strings.
+type multiString []string
+
+func (ms *multiString) String() string     { return strings.Join(*ms, ", ") }
+func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil }
+
 func main() {
 	flag.Parse()
 
@@ -107,7 +133,7 @@
 
 	// targetOut calculates the string to output for `target` separating conditions as needed using `sep`.
 	targetOut := func(target *compliance.TargetNode, sep string) string {
-		tOut := strings.TrimPrefix(target.Name(), ctx.stripPrefix)
+		tOut := ctx.strip(target.Name())
 		if ctx.labelConditions {
 			conditions := target.LicenseConditions().Names()
 			sort.Strings(conditions)
diff --git a/tools/compliance/cmd/dumpgraph/dumpgraph_test.go b/tools/compliance/cmd/dumpgraph/dumpgraph_test.go
index 516c1db..67b2b40 100644
--- a/tools/compliance/cmd/dumpgraph/dumpgraph_test.go
+++ b/tools/compliance/cmd/dumpgraph/dumpgraph_test.go
@@ -59,7 +59,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/"},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic static",
 				"bin/bin1.meta_lic lib/libc.a.meta_lic static",
@@ -75,7 +75,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice static",
 				"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:notice static",
@@ -146,7 +146,7 @@
 			condition: "notice",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/"},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic static",
 				"bin/bin1.meta_lic lib/libc.a.meta_lic static",
@@ -162,7 +162,7 @@
 			condition: "notice",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice static",
 				"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:notice static",
@@ -233,7 +233,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/"},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic static",
 				"bin/bin1.meta_lic lib/libc.a.meta_lic static",
@@ -249,7 +249,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:reciprocal static",
 				"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:reciprocal static",
@@ -320,7 +320,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/"},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic static",
 				"bin/bin1.meta_lic lib/libc.a.meta_lic static",
@@ -336,7 +336,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:restricted_allows_dynamic_linking static",
 				"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:reciprocal static",
@@ -407,7 +407,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/"},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic static",
 				"bin/bin1.meta_lic lib/libc.a.meta_lic static",
@@ -423,7 +423,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:by_exception_only:proprietary static",
 				"bin/bin1.meta_lic:notice lib/libc.a.meta_lic:by_exception_only:proprietary static",
@@ -613,7 +613,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/"},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("bin/bin2.meta_lic"),
@@ -636,7 +636,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("bin/bin2.meta_lic", "notice"),
@@ -735,7 +735,7 @@
 			condition: "notice",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/"},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("bin/bin2.meta_lic"),
@@ -758,7 +758,7 @@
 			condition: "notice",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("bin/bin2.meta_lic", "notice"),
@@ -857,7 +857,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/"},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("bin/bin2.meta_lic"),
@@ -880,7 +880,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("bin/bin2.meta_lic", "notice"),
@@ -979,7 +979,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/"},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("bin/bin2.meta_lic"),
@@ -1002,7 +1002,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("bin/bin2.meta_lic", "notice"),
@@ -1101,7 +1101,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/"},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("bin/bin2.meta_lic"),
@@ -1124,7 +1124,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("bin/bin2.meta_lic", "by_exception_only", "proprietary"),
diff --git a/tools/compliance/cmd/dumpresolutions/dumpresolutions.go b/tools/compliance/cmd/dumpresolutions/dumpresolutions.go
index 463dfad..9c5e972 100644
--- a/tools/compliance/cmd/dumpresolutions/dumpresolutions.go
+++ b/tools/compliance/cmd/dumpresolutions/dumpresolutions.go
@@ -30,7 +30,7 @@
 	conditions      = newMultiString("c", "License condition to resolve. (may be given multiple times)")
 	graphViz        = flag.Bool("dot", false, "Whether to output graphviz (i.e. dot) format.")
 	labelConditions = flag.Bool("label_conditions", false, "Whether to label target nodes with conditions.")
-	stripPrefix     = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
+	stripPrefix     = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
 
 	failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
 	failNoLicenses    = fmt.Errorf("No licenses found")
@@ -40,7 +40,20 @@
 	conditions      []compliance.LicenseCondition
 	graphViz        bool
 	labelConditions bool
-	stripPrefix     string
+	stripPrefix     []string
+}
+
+func (ctx context) strip(installPath string) string {
+	for _, prefix := range ctx.stripPrefix {
+		if strings.HasPrefix(installPath, prefix) {
+			p := strings.TrimPrefix(installPath, prefix)
+			if 0 == len(p) {
+				continue
+			}
+			return p
+		}
+	}
+	return installPath
 }
 
 func init() {
@@ -140,7 +153,7 @@
 
 	// targetOut calculates the string to output for `target` adding `sep`-separated conditions as needed.
 	targetOut := func(target *compliance.TargetNode, sep string) string {
-		tOut := strings.TrimPrefix(target.Name(), ctx.stripPrefix)
+		tOut := ctx.strip(target.Name())
 		if ctx.labelConditions {
 			conditions := target.LicenseConditions().Names()
 			if len(conditions) > 0 {
diff --git a/tools/compliance/cmd/dumpresolutions/dumpresolutions_test.go b/tools/compliance/cmd/dumpresolutions/dumpresolutions_test.go
index b7ccdc5..6fe1e8a 100644
--- a/tools/compliance/cmd/dumpresolutions/dumpresolutions_test.go
+++ b/tools/compliance/cmd/dumpresolutions/dumpresolutions_test.go
@@ -65,7 +65,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/"},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
 				"bin/bin1.meta_lic lib/liba.so.meta_lic notice",
@@ -87,7 +87,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
@@ -110,7 +110,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []string{},
 		},
@@ -120,7 +120,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []string{},
 		},
@@ -130,7 +130,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  append(compliance.ImpliesPrivate.AsList(), compliance.ImpliesShared.AsList()...),
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []string{},
 		},
@@ -138,7 +138,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice bin/bin1.meta_lic:notice notice",
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice notice",
@@ -223,7 +223,7 @@
 			condition: "notice",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/"},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
 				"bin/bin1.meta_lic lib/liba.so.meta_lic notice",
@@ -245,7 +245,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
@@ -268,7 +268,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []string{},
 		},
@@ -278,7 +278,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []string{},
 		},
@@ -288,7 +288,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  append(compliance.ImpliesShared.AsList(), compliance.ImpliesPrivate.AsList()...),
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []string{},
 		},
@@ -296,7 +296,7 @@
 			condition: "notice",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice bin/bin1.meta_lic:notice notice",
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice notice",
@@ -381,7 +381,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/"},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
 				"bin/bin1.meta_lic lib/liba.so.meta_lic reciprocal",
@@ -403,7 +403,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
@@ -421,7 +421,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic reciprocal",
@@ -437,7 +437,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []string{},
 		},
@@ -447,7 +447,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  append(compliance.ImpliesShared.AsList(), compliance.ImpliesPrivate.AsList()...),
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic reciprocal",
@@ -461,7 +461,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice bin/bin1.meta_lic:notice notice",
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:reciprocal reciprocal",
@@ -547,7 +547,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/"},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice:restricted_allows_dynamic_linking",
 				"bin/bin1.meta_lic lib/liba.so.meta_lic restricted_allows_dynamic_linking",
@@ -570,7 +570,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
@@ -586,7 +586,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic restricted_allows_dynamic_linking",
@@ -610,7 +610,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []string{},
 		},
@@ -620,7 +620,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  append(compliance.ImpliesShared.AsList(), compliance.ImpliesPrivate.AsList()...),
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic restricted_allows_dynamic_linking",
@@ -642,7 +642,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice bin/bin1.meta_lic:notice notice:restricted_allows_dynamic_linking",
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:restricted_allows_dynamic_linking restricted_allows_dynamic_linking",
@@ -730,7 +730,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/"},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
 				"bin/bin1.meta_lic lib/liba.so.meta_lic proprietary:by_exception_only",
@@ -753,7 +753,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic bin/bin1.meta_lic notice",
@@ -767,7 +767,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []string{
 				"bin/bin2.meta_lic bin/bin2.meta_lic restricted",
@@ -784,7 +784,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic proprietary",
@@ -802,7 +802,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  append(compliance.ImpliesShared.AsList(), compliance.ImpliesPrivate.AsList()...),
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []string{
 				"bin/bin1.meta_lic lib/liba.so.meta_lic proprietary",
@@ -822,7 +822,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true},
 			expectedOut: []string{
 				"bin/bin1.meta_lic:notice bin/bin1.meta_lic:notice notice",
 				"bin/bin1.meta_lic:notice lib/liba.so.meta_lic:proprietary:by_exception_only proprietary:by_exception_only",
@@ -1080,7 +1080,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/"},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("lib/liba.so.meta_lic"),
@@ -1144,7 +1144,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -1209,7 +1209,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -1219,7 +1219,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -1229,7 +1229,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.Union(compliance.ImpliesPrivate).AsList(),
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -1237,7 +1237,7 @@
 			condition: "firstparty",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/firstparty/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("lib/liba.so.meta_lic", "notice"),
@@ -1472,7 +1472,7 @@
 			condition: "notice",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/"},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("lib/liba.so.meta_lic"),
@@ -1536,7 +1536,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -1601,7 +1601,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -1611,7 +1611,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -1621,7 +1621,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.Union(compliance.ImpliesPrivate).AsList(),
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -1629,7 +1629,7 @@
 			condition: "notice",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/notice/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("lib/liba.so.meta_lic", "notice"),
@@ -1864,7 +1864,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/"},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("lib/liba.so.meta_lic"),
@@ -1928,7 +1928,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -1971,7 +1971,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -2006,7 +2006,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -2016,7 +2016,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.Union(compliance.ImpliesPrivate).AsList(),
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -2049,7 +2049,7 @@
 			condition: "reciprocal",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/reciprocal/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("lib/liba.so.meta_lic", "reciprocal"),
@@ -2296,7 +2296,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/"},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("lib/liba.so.meta_lic"),
@@ -2372,7 +2372,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -2406,7 +2406,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -2478,7 +2478,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []getMatcher{},
 		},
@@ -2488,7 +2488,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.Union(compliance.ImpliesPrivate).AsList(),
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -2558,7 +2558,7 @@
 			condition: "restricted",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/restricted/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("lib/liba.so.meta_lic", "restricted_allows_dynamic_linking"),
@@ -2836,7 +2836,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/"},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
 				matchTarget("lib/liba.so.meta_lic"),
@@ -2914,7 +2914,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  []compliance.LicenseCondition{compliance.NoticeCondition},
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -2939,7 +2939,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.AsList(),
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin2.meta_lic"),
@@ -2977,7 +2977,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesPrivate.AsList(),
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -3021,7 +3021,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				conditions:  compliance.ImpliesShared.Union(compliance.ImpliesPrivate).AsList(),
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic"),
@@ -3082,7 +3082,7 @@
 			condition: "proprietary",
 			name:      "apex_trimmed_labelled",
 			roots:     []string{"highest.apex.meta_lic"},
-			ctx:       context{stripPrefix: "testdata/proprietary/", labelConditions: true},
+			ctx:       context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true},
 			expectedOut: []getMatcher{
 				matchTarget("bin/bin1.meta_lic", "notice"),
 				matchTarget("lib/liba.so.meta_lic", "by_exception_only", "proprietary"),
diff --git a/tools/compliance/cmd/htmlnotice/htmlnotice.go b/tools/compliance/cmd/htmlnotice/htmlnotice.go
index 6363acf..938bb7d 100644
--- a/tools/compliance/cmd/htmlnotice/htmlnotice.go
+++ b/tools/compliance/cmd/htmlnotice/htmlnotice.go
@@ -35,7 +35,7 @@
 	outputFile  = flag.String("o", "-", "Where to write the NOTICE text file. (default stdout)")
 	depsFile    = flag.String("d", "", "Where to write the deps file")
 	includeTOC  = flag.Bool("toc", true, "Whether to include a table of contents.")
-	stripPrefix = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
+	stripPrefix = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
 	title       = flag.String("title", "", "The title of the notice file.")
 
 	failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
@@ -47,11 +47,27 @@
 	stderr      io.Writer
 	rootFS      fs.FS
 	includeTOC  bool
-	stripPrefix string
+	stripPrefix []string
 	title       string
 	deps        *[]string
 }
 
+func (ctx context) strip(installPath string) string {
+	for _, prefix := range ctx.stripPrefix {
+		if strings.HasPrefix(installPath, prefix) {
+			p := strings.TrimPrefix(installPath, prefix)
+			if 0 == len(p) {
+				p = ctx.title
+			}
+			if 0 == len(p) {
+				continue
+			}
+			return p
+		}
+	}
+	return installPath
+}
+
 func init() {
 	flag.Usage = func() {
 		fmt.Fprintf(os.Stderr, `Usage: %s {options} file.meta_lic {file.meta_lic...}
@@ -65,6 +81,19 @@
 	}
 }
 
+// newMultiString creates a flag that allows multiple values in an array.
+func newMultiString(name, usage string) *multiString {
+	var f multiString
+	flag.Var(&f, name, usage)
+	return &f
+}
+
+// multiString implements the flag `Value` interface for multiple strings.
+type multiString []string
+
+func (ms *multiString) String() string     { return strings.Join(*ms, ", ") }
+func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil }
+
 func main() {
 	flag.Parse()
 
@@ -190,20 +219,7 @@
 			id := fmt.Sprintf("id%d", i)
 			i++
 			ids[installPath] = id
-			var p string
-			if 0 < len(ctx.stripPrefix) && strings.HasPrefix(installPath, ctx.stripPrefix) {
-				p = installPath[len(ctx.stripPrefix):]
-				if 0 == len(p) {
-					if 0 < len(ctx.title) {
-						p = ctx.title
-					} else {
-						p = "root"
-					}
-				}
-			} else {
-				p = installPath
-			}
-			fmt.Fprintf(ctx.stdout, "    <li id=\"%s\"><strong>%s</strong>\n      <ul>\n", id, html.EscapeString(p))
+			fmt.Fprintf(ctx.stdout, "    <li id=\"%s\"><strong>%s</strong>\n      <ul>\n", id, html.EscapeString(ctx.strip(installPath)))
 			for _, h := range ni.InstallHashes(installPath) {
 				libs := ni.InstallHashLibs(installPath, h)
 				fmt.Fprintf(ctx.stdout, "        <li><a href=\"#%s\">%s</a>\n", h.String(), html.EscapeString(strings.Join(libs, ", ")))
@@ -218,17 +234,9 @@
 			fmt.Fprintf(ctx.stdout, "  <strong>%s</strong> used by:\n    <ul class=\"file-list\">\n", html.EscapeString(libName))
 			for _, installPath := range ni.HashLibInstalls(h, libName) {
 				if id, ok := ids[installPath]; ok {
-					if 0 < len(ctx.stripPrefix) && strings.HasPrefix(installPath, ctx.stripPrefix) {
-						fmt.Fprintf(ctx.stdout, "      <li><a href=\"#%s\">%s</a>\n", id, html.EscapeString(installPath[len(ctx.stripPrefix):]))
-					} else {
-						fmt.Fprintf(ctx.stdout, "      <li><a href=\"#%s\">%s</a>\n", id, html.EscapeString(installPath))
-					}
+					fmt.Fprintf(ctx.stdout, "      <li><a href=\"#%s\">%s</a>\n", id, html.EscapeString(ctx.strip(installPath)))
 				} else {
-					if 0 < len(ctx.stripPrefix) && strings.HasPrefix(installPath, ctx.stripPrefix) {
-						fmt.Fprintf(ctx.stdout, "      <li>%s\n", html.EscapeString(installPath[len(ctx.stripPrefix):]))
-					} else {
-						fmt.Fprintf(ctx.stdout, "      <li>%s\n", html.EscapeString(installPath))
-					}
+					fmt.Fprintf(ctx.stdout, "      <li>%s\n", html.EscapeString(ctx.strip(installPath)))
 				}
 			}
 			fmt.Fprintf(ctx.stdout, "    </ul>\n")
diff --git a/tools/compliance/cmd/htmlnotice/htmlnotice_test.go b/tools/compliance/cmd/htmlnotice/htmlnotice_test.go
index 4e9c43c..9863b6d 100644
--- a/tools/compliance/cmd/htmlnotice/htmlnotice_test.go
+++ b/tools/compliance/cmd/htmlnotice/htmlnotice_test.go
@@ -651,7 +651,7 @@
 
 			var deps []string
 
-			ctx := context{stdout, stderr, os.DirFS("."), tt.includeTOC, tt.stripPrefix, tt.title, &deps}
+			ctx := context{stdout, stderr, os.DirFS("."), tt.includeTOC, []string{tt.stripPrefix}, tt.title, &deps}
 
 			err := htmlNotice(&ctx, rootFiles...)
 			if err != nil {
diff --git a/tools/compliance/cmd/rtrace/rtrace.go b/tools/compliance/cmd/rtrace/rtrace.go
index a2ff594..7c63979 100644
--- a/tools/compliance/cmd/rtrace/rtrace.go
+++ b/tools/compliance/cmd/rtrace/rtrace.go
@@ -28,7 +28,7 @@
 
 var (
 	sources         = newMultiString("rtrace", "Projects or metadata files to trace back from. (required; multiple allowed)")
-	stripPrefix     = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
+	stripPrefix     = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
 
 	failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
 	failNoSources     = fmt.Errorf("\nNo projects or metadata files to trace back from")
@@ -37,7 +37,20 @@
 
 type context struct {
 	sources         []string
-	stripPrefix     string
+	stripPrefix     []string
+}
+
+func (ctx context) strip(installPath string) string {
+	for _, prefix := range ctx.stripPrefix {
+		if strings.HasPrefix(installPath, prefix) {
+			p := strings.TrimPrefix(installPath, prefix)
+			if 0 == len(p) {
+				continue
+			}
+			return p
+		}
+	}
+	return installPath
 }
 
 func init() {
@@ -143,7 +156,7 @@
 
 	// targetOut calculates the string to output for `target` adding `sep`-separated conditions as needed.
 	targetOut := func(target *compliance.TargetNode, sep string) string {
-		tOut := strings.TrimPrefix(target.Name(), ctx.stripPrefix)
+		tOut := ctx.strip(target.Name())
 		return tOut
 	}
 
diff --git a/tools/compliance/cmd/rtrace/rtrace_test.go b/tools/compliance/cmd/rtrace/rtrace_test.go
index 658aa96..a8eb884 100644
--- a/tools/compliance/cmd/rtrace/rtrace_test.go
+++ b/tools/compliance/cmd/rtrace/rtrace_test.go
@@ -52,7 +52,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				sources:     []string{"testdata/firstparty/bin/bin1.meta_lic"},
-				stripPrefix: "testdata/firstparty/",
+				stripPrefix: []string{"testdata/firstparty/"},
 			},
 			expectedOut: []string{},
 		},
@@ -92,7 +92,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				sources:     []string{"testdata/notice/bin/bin1.meta_lic"},
-				stripPrefix: "testdata/notice/",
+				stripPrefix: []string{"testdata/notice/"},
 			},
 			expectedOut: []string{},
 		},
@@ -132,7 +132,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				sources:     []string{"testdata/reciprocal/bin/bin1.meta_lic"},
-				stripPrefix: "testdata/reciprocal/",
+				stripPrefix: []string{"testdata/reciprocal/"},
 			},
 			expectedOut: []string{},
 		},
@@ -175,7 +175,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				sources:     []string{"testdata/restricted/bin/bin1.meta_lic"},
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []string{"lib/liba.so.meta_lic restricted_allows_dynamic_linking"},
 		},
@@ -185,7 +185,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				sources:     []string{"testdata/restricted/bin/bin2.meta_lic"},
-				stripPrefix: "testdata/restricted/",
+				stripPrefix: []string{"testdata/restricted/"},
 			},
 			expectedOut: []string{"lib/libb.so.meta_lic restricted"},
 		},
@@ -228,7 +228,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				sources:     []string{"testdata/proprietary/bin/bin1.meta_lic"},
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []string{},
 		},
@@ -238,7 +238,7 @@
 			roots:     []string{"highest.apex.meta_lic"},
 			ctx: context{
 				sources:     []string{"testdata/proprietary/bin/bin2.meta_lic"},
-				stripPrefix: "testdata/proprietary/",
+				stripPrefix: []string{"testdata/proprietary/"},
 			},
 			expectedOut: []string{"lib/libb.so.meta_lic restricted"},
 		},
diff --git a/tools/compliance/cmd/textnotice/textnotice.go b/tools/compliance/cmd/textnotice/textnotice.go
index eebb13d..35c5c24 100644
--- a/tools/compliance/cmd/textnotice/textnotice.go
+++ b/tools/compliance/cmd/textnotice/textnotice.go
@@ -16,6 +16,7 @@
 
 import (
 	"bytes"
+	"compress/gzip"
 	"flag"
 	"fmt"
 	"io"
@@ -32,7 +33,8 @@
 var (
 	outputFile  = flag.String("o", "-", "Where to write the NOTICE text file. (default stdout)")
 	depsFile    = flag.String("d", "", "Where to write the deps file")
-	stripPrefix = flag.String("strip_prefix", "", "Prefix to remove from paths. i.e. path to root")
+	stripPrefix = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
+	title       = flag.String("title", "", "The title of the notice file.")
 
 	failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
 	failNoLicenses    = fmt.Errorf("No licenses found")
@@ -42,10 +44,27 @@
 	stdout      io.Writer
 	stderr      io.Writer
 	rootFS      fs.FS
-	stripPrefix string
+	stripPrefix []string
+	title       string
 	deps        *[]string
 }
 
+func (ctx context) strip(installPath string) string {
+	for _, prefix := range ctx.stripPrefix {
+		if strings.HasPrefix(installPath, prefix) {
+			p := strings.TrimPrefix(installPath, prefix)
+			if 0 == len(p) {
+				p = ctx.title
+			}
+			if 0 == len(p) {
+				continue
+			}
+			return p
+		}
+	}
+	return installPath
+}
+
 func init() {
 	flag.Usage = func() {
 		fmt.Fprintf(os.Stderr, `Usage: %s {options} file.meta_lic {file.meta_lic...}
@@ -58,6 +77,19 @@
 	}
 }
 
+// newMultiString creates a flag that allows multiple values in an array.
+func newMultiString(name, usage string) *multiString {
+	var f multiString
+	flag.Var(&f, name, usage)
+	return &f
+}
+
+// multiString implements the flag `Value` interface for multiple strings.
+type multiString []string
+
+func (ms *multiString) String() string     { return strings.Join(*ms, ", ") }
+func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil }
+
 func main() {
 	flag.Parse()
 
@@ -89,14 +121,21 @@
 	}
 
 	var ofile io.Writer
+	var closer io.Closer
 	ofile = os.Stdout
+	var obuf *bytes.Buffer
 	if *outputFile != "-" {
-		ofile = &bytes.Buffer{}
+		obuf = &bytes.Buffer{}
+		ofile = obuf
+	}
+	if strings.HasSuffix(*outputFile, ".gz") {
+		ofile, _ = gzip.NewWriterLevel(obuf, gzip.BestCompression)
+		closer = ofile.(io.Closer)
 	}
 
 	var deps []string
 
-	ctx := &context{ofile, os.Stderr, os.DirFS("."), *stripPrefix, &deps}
+	ctx := &context{ofile, os.Stderr, os.DirFS("."), *stripPrefix, *title, &deps}
 
 	err := textNotice(ctx, flag.Args()...)
 	if err != nil {
@@ -106,8 +145,12 @@
 		fmt.Fprintf(os.Stderr, "%s\n", err.Error())
 		os.Exit(1)
 	}
+	if closer != nil {
+		closer.Close()
+	}
+
 	if *outputFile != "-" {
-		err := os.WriteFile(*outputFile, ofile.(*bytes.Buffer).Bytes(), 0666)
+		err := os.WriteFile(*outputFile, obuf.Bytes(), 0666)
 		if err != nil {
 			fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
 			os.Exit(1)
@@ -152,11 +195,7 @@
 		for _, libName := range ni.HashLibs(h) {
 			fmt.Fprintf(ctx.stdout, "%s used by:\n", libName)
 			for _, installPath := range ni.HashLibInstalls(h, libName) {
-				if 0 < len(ctx.stripPrefix) && strings.HasPrefix(installPath, ctx.stripPrefix) {
-					fmt.Fprintf(ctx.stdout, "  %s\n", installPath[len(ctx.stripPrefix):])
-				} else {
-					fmt.Fprintf(ctx.stdout, "  %s\n", installPath)
-				}
+				fmt.Fprintf(ctx.stdout, "  %s\n", ctx.strip(installPath))
 			}
 			fmt.Fprintln(ctx.stdout)
 		}
diff --git a/tools/compliance/cmd/textnotice/textnotice_test.go b/tools/compliance/cmd/textnotice/textnotice_test.go
index 39f711d..0ed3394 100644
--- a/tools/compliance/cmd/textnotice/textnotice_test.go
+++ b/tools/compliance/cmd/textnotice/textnotice_test.go
@@ -564,7 +564,7 @@
 
 			var deps []string
 
-			ctx := context{stdout, stderr, os.DirFS("."), tt.stripPrefix, &deps}
+			ctx := context{stdout, stderr, os.DirFS("."), []string{tt.stripPrefix}, "", &deps}
 
 			err := textNotice(&ctx, rootFiles...)
 			if err != nil {
diff --git a/tools/compliance/cmd/xmlnotice/xmlnotice.go b/tools/compliance/cmd/xmlnotice/xmlnotice.go
new file mode 100644
index 0000000..eb169f3
--- /dev/null
+++ b/tools/compliance/cmd/xmlnotice/xmlnotice.go
@@ -0,0 +1,220 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+	"bytes"
+	"compress/gzip"
+	"encoding/xml"
+	"flag"
+	"fmt"
+	"io"
+	"io/fs"
+	"os"
+	"path/filepath"
+	"strings"
+
+	"android/soong/tools/compliance"
+
+	"github.com/google/blueprint/deptools"
+)
+
+var (
+	outputFile  = flag.String("o", "-", "Where to write the NOTICE xml or xml.gz file. (default stdout)")
+	depsFile    = flag.String("d", "", "Where to write the deps file")
+	stripPrefix = newMultiString("strip_prefix", "Prefix to remove from paths. i.e. path to root (multiple allowed)")
+	title       = flag.String("title", "", "The title of the notice file.")
+
+	failNoneRequested = fmt.Errorf("\nNo license metadata files requested")
+	failNoLicenses    = fmt.Errorf("No licenses found")
+)
+
+type context struct {
+	stdout      io.Writer
+	stderr      io.Writer
+	rootFS      fs.FS
+	stripPrefix []string
+	title       string
+	deps        *[]string
+}
+
+func (ctx context) strip(installPath string) string {
+	for _, prefix := range ctx.stripPrefix {
+		if strings.HasPrefix(installPath, prefix) {
+			p := strings.TrimPrefix(installPath, prefix)
+			if 0 == len(p) {
+				p = ctx.title
+			}
+			if 0 == len(p) {
+				continue
+			}
+			return p
+		}
+	}
+	return installPath
+}
+
+func init() {
+	flag.Usage = func() {
+		fmt.Fprintf(os.Stderr, `Usage: %s {options} file.meta_lic {file.meta_lic...}
+
+Outputs an xml NOTICE.xml or gzipped NOTICE.xml.gz file if the -o filename ends
+with ".gz".
+
+Options:
+`, filepath.Base(os.Args[0]))
+		flag.PrintDefaults()
+	}
+}
+
+// newMultiString creates a flag that allows multiple values in an array.
+func newMultiString(name, usage string) *multiString {
+	var f multiString
+	flag.Var(&f, name, usage)
+	return &f
+}
+
+// multiString implements the flag `Value` interface for multiple strings.
+type multiString []string
+
+func (ms *multiString) String() string     { return strings.Join(*ms, ", ") }
+func (ms *multiString) Set(s string) error { *ms = append(*ms, s); return nil }
+
+func main() {
+	flag.Parse()
+
+	// Must specify at least one root target.
+	if flag.NArg() == 0 {
+		flag.Usage()
+		os.Exit(2)
+	}
+
+	if len(*outputFile) == 0 {
+		flag.Usage()
+		fmt.Fprintf(os.Stderr, "must specify file for -o; use - for stdout\n")
+		os.Exit(2)
+	} else {
+		dir, err := filepath.Abs(filepath.Dir(*outputFile))
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "cannot determine path to %q: %s\n", *outputFile, err)
+			os.Exit(1)
+		}
+		fi, err := os.Stat(dir)
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "cannot read directory %q of %q: %s\n", dir, *outputFile, err)
+			os.Exit(1)
+		}
+		if !fi.IsDir() {
+			fmt.Fprintf(os.Stderr, "parent %q of %q is not a directory\n", dir, *outputFile)
+			os.Exit(1)
+		}
+	}
+
+	var ofile io.Writer
+	var closer io.Closer
+	ofile = os.Stdout
+	var obuf *bytes.Buffer
+	if *outputFile != "-" {
+		obuf = &bytes.Buffer{}
+		ofile = obuf
+	}
+	if strings.HasSuffix(*outputFile, ".gz") {
+		ofile, _ = gzip.NewWriterLevel(obuf, gzip.BestCompression)
+		closer = ofile.(io.Closer)
+	}
+
+	var deps []string
+
+	ctx := &context{ofile, os.Stderr, os.DirFS("."), *stripPrefix, *title, &deps}
+
+	err := xmlNotice(ctx, flag.Args()...)
+	if err != nil {
+		if err == failNoneRequested {
+			flag.Usage()
+		}
+		fmt.Fprintf(os.Stderr, "%s\n", err.Error())
+		os.Exit(1)
+	}
+	if closer != nil {
+		closer.Close()
+	}
+
+	if *outputFile != "-" {
+		err := os.WriteFile(*outputFile, obuf.Bytes(), 0666)
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
+			os.Exit(1)
+		}
+	}
+	if *depsFile != "" {
+		err := deptools.WriteDepFile(*depsFile, *outputFile, deps)
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "could not write deps to %q: %s\n", *depsFile, err)
+			os.Exit(1)
+		}
+	}
+	os.Exit(0)
+}
+
+// xmlNotice implements the xmlnotice utility.
+func xmlNotice(ctx *context, files ...string) error {
+	// Must be at least one root file.
+	if len(files) < 1 {
+		return failNoneRequested
+	}
+
+	// Read the license graph from the license metadata files (*.meta_lic).
+	licenseGraph, err := compliance.ReadLicenseGraph(ctx.rootFS, ctx.stderr, files)
+	if err != nil {
+		return fmt.Errorf("Unable to read license metadata file(s) %q: %v\n", files, err)
+	}
+	if licenseGraph == nil {
+		return failNoLicenses
+	}
+
+	// rs contains all notice resolutions.
+	rs := compliance.ResolveNotices(licenseGraph)
+
+	ni, err := compliance.IndexLicenseTexts(ctx.rootFS, licenseGraph, rs)
+	if err != nil {
+		return fmt.Errorf("Unable to read license text file(s) for %q: %v\n", files, err)
+	}
+
+	fmt.Fprintln(ctx.stdout, "<?xml version=\"1.0\" encoding=\"utf-8\"?>")
+	fmt.Fprintln(ctx.stdout, "<licenses>")
+
+	for installPath := range ni.InstallPaths() {
+		p := ctx.strip(installPath)
+		for _, h := range ni.InstallHashes(installPath) {
+			for _, lib := range ni.InstallHashLibs(installPath, h) {
+				fmt.Fprintf(ctx.stdout, "<file-name contentId=\"%s\" lib=\"", h.String())
+				xml.EscapeText(ctx.stdout, []byte(lib))
+				fmt.Fprintf(ctx.stdout, "\">")
+				xml.EscapeText(ctx.stdout, []byte(p))
+				fmt.Fprintln(ctx.stdout, "</file-name>")
+			}
+		}
+	}
+	for h := range ni.Hashes() {
+		fmt.Fprintf(ctx.stdout, "<file-content contentId=\"%s\"><![CDATA[", h)
+		xml.EscapeText(ctx.stdout, ni.HashText(h))
+		fmt.Fprintf(ctx.stdout, "]]></file-content>\n\n")
+	}
+	fmt.Fprintln(ctx.stdout, "</licenses>")
+
+	*ctx.deps = ni.InputNoticeFiles()
+
+	return nil
+}
diff --git a/tools/compliance/cmd/xmlnotice/xmlnotice_test.go b/tools/compliance/cmd/xmlnotice/xmlnotice_test.go
new file mode 100644
index 0000000..3a62438
--- /dev/null
+++ b/tools/compliance/cmd/xmlnotice/xmlnotice_test.go
@@ -0,0 +1,634 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+	"bufio"
+	"bytes"
+	"encoding/xml"
+	"fmt"
+	"os"
+	"reflect"
+	"regexp"
+	"strings"
+	"testing"
+)
+
+var (
+	installTarget = regexp.MustCompile(`^<file-name contentId="[^"]{32}" lib="([^"]*)">([^<]+)</file-name>`)
+	licenseText = regexp.MustCompile(`^<file-content contentId="[^"]{32}"><![[]CDATA[[]([^]]*)[]][]]></file-content>`)
+)
+
+func TestMain(m *testing.M) {
+	// Change into the parent directory before running the tests
+	// so they can find the testdata directory.
+	if err := os.Chdir(".."); err != nil {
+		fmt.Printf("failed to change to testdata directory: %s\n", err)
+		os.Exit(1)
+	}
+	os.Exit(m.Run())
+}
+
+func Test(t *testing.T) {
+	tests := []struct {
+		condition    string
+		name         string
+		roots        []string
+		stripPrefix  string
+		expectedOut  []matcher
+		expectedDeps []string
+	}{
+		{
+			condition: "firstparty",
+			name:      "apex",
+			roots:     []string{"highest.apex.meta_lic"},
+			expectedOut: []matcher{
+				target{"highest.apex", "Android"},
+				target{"highest.apex/bin/bin1", "Android"},
+				target{"highest.apex/bin/bin2", "Android"},
+				target{"highest.apex/lib/liba.so", "Android"},
+				target{"highest.apex/lib/libb.so", "Android"},
+				firstParty{},
+			},
+			expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
+		},
+		{
+			condition: "firstparty",
+			name:      "container",
+			roots:     []string{"container.zip.meta_lic"},
+			expectedOut: []matcher{
+				target{"container.zip", "Android"},
+				target{"container.zip/bin1", "Android"},
+				target{"container.zip/bin2", "Android"},
+				target{"container.zip/liba.so", "Android"},
+				target{"container.zip/libb.so", "Android"},
+				firstParty{},
+			},
+			expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
+		},
+		{
+			condition: "firstparty",
+			name:      "application",
+			roots:     []string{"application.meta_lic"},
+			expectedOut: []matcher{
+				target{"application", "Android"},
+				firstParty{},
+			},
+			expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
+		},
+		{
+			condition: "firstparty",
+			name:      "binary",
+			roots:     []string{"bin/bin1.meta_lic"},
+			expectedOut: []matcher{
+				target{"bin/bin1", "Android"},
+				firstParty{},
+			},
+			expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
+		},
+		{
+			condition: "firstparty",
+			name:      "library",
+			roots:     []string{"lib/libd.so.meta_lic"},
+			expectedOut: []matcher{
+				target{"lib/libd.so", "Android"},
+				firstParty{},
+			},
+			expectedDeps: []string{"testdata/firstparty/FIRST_PARTY_LICENSE"},
+		},
+		{
+			condition: "notice",
+			name:      "apex",
+			roots:     []string{"highest.apex.meta_lic"},
+			expectedOut: []matcher{
+				target{"highest.apex", "Android"},
+				target{"highest.apex/bin/bin1", "Android"},
+				target{"highest.apex/bin/bin1", "Device"},
+				target{"highest.apex/bin/bin1", "External"},
+				target{"highest.apex/bin/bin2", "Android"},
+				target{"highest.apex/lib/liba.so", "Device"},
+				target{"highest.apex/lib/libb.so", "Android"},
+				firstParty{},
+				notice{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/notice/NOTICE_LICENSE",
+			},
+		},
+		{
+			condition: "notice",
+			name:      "container",
+			roots:     []string{"container.zip.meta_lic"},
+			expectedOut: []matcher{
+				target{"container.zip", "Android"},
+				target{"container.zip/bin1", "Android"},
+				target{"container.zip/bin1", "Device"},
+				target{"container.zip/bin1", "External"},
+				target{"container.zip/bin2", "Android"},
+				target{"container.zip/liba.so", "Device"},
+				target{"container.zip/libb.so", "Android"},
+				firstParty{},
+				notice{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/notice/NOTICE_LICENSE",
+			},
+		},
+		{
+			condition: "notice",
+			name:      "application",
+			roots:     []string{"application.meta_lic"},
+			expectedOut: []matcher{
+				target{"application", "Android"},
+				target{"application", "Device"},
+				firstParty{},
+				notice{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/notice/NOTICE_LICENSE",
+			},
+		},
+		{
+			condition: "notice",
+			name:      "binary",
+			roots:     []string{"bin/bin1.meta_lic"},
+			expectedOut: []matcher{
+				target{"bin/bin1", "Android"},
+				target{"bin/bin1", "Device"},
+				target{"bin/bin1", "External"},
+				firstParty{},
+				notice{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/notice/NOTICE_LICENSE",
+			},
+		},
+		{
+			condition: "notice",
+			name:      "library",
+			roots:     []string{"lib/libd.so.meta_lic"},
+			expectedOut: []matcher{
+				target{"lib/libd.so", "External"},
+				notice{},
+			},
+			expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"},
+		},
+		{
+			condition: "reciprocal",
+			name:      "apex",
+			roots:     []string{"highest.apex.meta_lic"},
+			expectedOut: []matcher{
+				target{"highest.apex", "Android"},
+				target{"highest.apex/bin/bin1", "Android"},
+				target{"highest.apex/bin/bin1", "Device"},
+				target{"highest.apex/bin/bin1", "External"},
+				target{"highest.apex/bin/bin2", "Android"},
+				target{"highest.apex/lib/liba.so", "Device"},
+				target{"highest.apex/lib/libb.so", "Android"},
+				firstParty{},
+				reciprocal{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/reciprocal/RECIPROCAL_LICENSE",
+			},
+		},
+		{
+			condition: "reciprocal",
+			name:      "container",
+			roots:     []string{"container.zip.meta_lic"},
+			expectedOut: []matcher{
+				target{"container.zip", "Android"},
+				target{"container.zip/bin1", "Android"},
+				target{"container.zip/bin1", "Device"},
+				target{"container.zip/bin1", "External"},
+				target{"container.zip/bin2", "Android"},
+				target{"container.zip/liba.so", "Device"},
+				target{"container.zip/libb.so", "Android"},
+				firstParty{},
+				reciprocal{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/reciprocal/RECIPROCAL_LICENSE",
+			},
+		},
+		{
+			condition: "reciprocal",
+			name:      "application",
+			roots:     []string{"application.meta_lic"},
+			expectedOut: []matcher{
+				target{"application", "Android"},
+				target{"application", "Device"},
+				firstParty{},
+				reciprocal{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/reciprocal/RECIPROCAL_LICENSE",
+			},
+		},
+		{
+			condition: "reciprocal",
+			name:      "binary",
+			roots:     []string{"bin/bin1.meta_lic"},
+			expectedOut: []matcher{
+				target{"bin/bin1", "Android"},
+				target{"bin/bin1", "Device"},
+				target{"bin/bin1", "External"},
+				firstParty{},
+				reciprocal{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/reciprocal/RECIPROCAL_LICENSE",
+			},
+		},
+		{
+			condition: "reciprocal",
+			name:      "library",
+			roots:     []string{"lib/libd.so.meta_lic"},
+			expectedOut: []matcher{
+				target{"lib/libd.so", "External"},
+				notice{},
+			},
+			expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"},
+		},
+		{
+			condition: "restricted",
+			name:      "apex",
+			roots:     []string{"highest.apex.meta_lic"},
+			expectedOut: []matcher{
+				target{"highest.apex", "Android"},
+				target{"highest.apex/bin/bin1", "Android"},
+				target{"highest.apex/bin/bin1", "Device"},
+				target{"highest.apex/bin/bin1", "External"},
+				target{"highest.apex/bin/bin2", "Android"},
+				target{"highest.apex/bin/bin2", "Android"},
+				target{"highest.apex/lib/liba.so", "Device"},
+				target{"highest.apex/lib/libb.so", "Android"},
+				firstParty{},
+				restricted{},
+				reciprocal{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/reciprocal/RECIPROCAL_LICENSE",
+				"testdata/restricted/RESTRICTED_LICENSE",
+			},
+		},
+		{
+			condition: "restricted",
+			name:      "container",
+			roots:     []string{"container.zip.meta_lic"},
+			expectedOut: []matcher{
+				target{"container.zip", "Android"},
+				target{"container.zip/bin1", "Android"},
+				target{"container.zip/bin1", "Device"},
+				target{"container.zip/bin1", "External"},
+				target{"container.zip/bin2", "Android"},
+				target{"container.zip/bin2", "Android"},
+				target{"container.zip/liba.so", "Device"},
+				target{"container.zip/libb.so", "Android"},
+				firstParty{},
+				restricted{},
+				reciprocal{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/reciprocal/RECIPROCAL_LICENSE",
+				"testdata/restricted/RESTRICTED_LICENSE",
+			},
+		},
+		{
+			condition: "restricted",
+			name:      "application",
+			roots:     []string{"application.meta_lic"},
+			expectedOut: []matcher{
+				target{"application", "Android"},
+				target{"application", "Device"},
+				firstParty{},
+				restricted{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/restricted/RESTRICTED_LICENSE",
+			},
+		},
+		{
+			condition: "restricted",
+			name:      "binary",
+			roots:     []string{"bin/bin1.meta_lic"},
+			expectedOut: []matcher{
+				target{"bin/bin1", "Android"},
+				target{"bin/bin1", "Device"},
+				target{"bin/bin1", "External"},
+				firstParty{},
+				restricted{},
+				reciprocal{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/reciprocal/RECIPROCAL_LICENSE",
+				"testdata/restricted/RESTRICTED_LICENSE",
+			},
+		},
+		{
+			condition: "restricted",
+			name:      "library",
+			roots:     []string{"lib/libd.so.meta_lic"},
+			expectedOut: []matcher{
+				target{"lib/libd.so", "External"},
+				notice{},
+			},
+			expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"},
+		},
+		{
+			condition: "proprietary",
+			name:      "apex",
+			roots:     []string{"highest.apex.meta_lic"},
+			expectedOut: []matcher{
+				target{"highest.apex", "Android"},
+				target{"highest.apex/bin/bin1", "Android"},
+				target{"highest.apex/bin/bin1", "Device"},
+				target{"highest.apex/bin/bin1", "External"},
+				target{"highest.apex/bin/bin2", "Android"},
+				target{"highest.apex/bin/bin2", "Android"},
+				target{"highest.apex/lib/liba.so", "Device"},
+				target{"highest.apex/lib/libb.so", "Android"},
+				restricted{},
+				firstParty{},
+				proprietary{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/proprietary/PROPRIETARY_LICENSE",
+				"testdata/restricted/RESTRICTED_LICENSE",
+			},
+		},
+		{
+			condition: "proprietary",
+			name:      "container",
+			roots:     []string{"container.zip.meta_lic"},
+			expectedOut: []matcher{
+				target{"container.zip", "Android"},
+				target{"container.zip/bin1", "Android"},
+				target{"container.zip/bin1", "Device"},
+				target{"container.zip/bin1", "External"},
+				target{"container.zip/bin2", "Android"},
+				target{"container.zip/bin2", "Android"},
+				target{"container.zip/liba.so", "Device"},
+				target{"container.zip/libb.so", "Android"},
+				restricted{},
+				firstParty{},
+				proprietary{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/proprietary/PROPRIETARY_LICENSE",
+				"testdata/restricted/RESTRICTED_LICENSE",
+			},
+		},
+		{
+			condition: "proprietary",
+			name:      "application",
+			roots:     []string{"application.meta_lic"},
+			expectedOut: []matcher{
+				target{"application", "Android"},
+				target{"application", "Device"},
+				firstParty{},
+				proprietary{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/proprietary/PROPRIETARY_LICENSE",
+			},
+		},
+		{
+			condition: "proprietary",
+			name:      "binary",
+			roots:     []string{"bin/bin1.meta_lic"},
+			expectedOut: []matcher{
+				target{"bin/bin1", "Android"},
+				target{"bin/bin1", "Device"},
+				target{"bin/bin1", "External"},
+				firstParty{},
+				proprietary{},
+			},
+			expectedDeps: []string{
+				"testdata/firstparty/FIRST_PARTY_LICENSE",
+				"testdata/proprietary/PROPRIETARY_LICENSE",
+			},
+		},
+		{
+			condition: "proprietary",
+			name:      "library",
+			roots:     []string{"lib/libd.so.meta_lic"},
+			expectedOut: []matcher{
+				target{"lib/libd.so", "External"},
+				notice{},
+			},
+			expectedDeps: []string{"testdata/notice/NOTICE_LICENSE"},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.condition+" "+tt.name, func(t *testing.T) {
+			stdout := &bytes.Buffer{}
+			stderr := &bytes.Buffer{}
+
+			rootFiles := make([]string, 0, len(tt.roots))
+			for _, r := range tt.roots {
+				rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
+			}
+
+			var deps []string
+
+			ctx := context{stdout, stderr, os.DirFS("."), []string{tt.stripPrefix}, "", &deps}
+
+			err := xmlNotice(&ctx, rootFiles...)
+			if err != nil {
+				t.Fatalf("xmlnotice: error = %v, stderr = %v", err, stderr)
+				return
+			}
+			if stderr.Len() > 0 {
+				t.Errorf("xmlnotice: gotStderr = %v, want none", stderr)
+			}
+
+			t.Logf("got stdout: %s", stdout.String())
+
+			t.Logf("want stdout: %s", matcherList(tt.expectedOut).String())
+
+			out := bufio.NewScanner(stdout)
+			lineno := 0
+			inBody := false
+			outOfBody := true
+			for out.Scan() {
+				line := out.Text()
+				if strings.TrimLeft(line, " ") == "" {
+					continue
+				}
+				if lineno == 0 && !inBody && `<?xml version="1.0" encoding="utf-8"?>` == line {
+					continue
+				}
+				if !inBody {
+					if "<licenses>" == line {
+						inBody = true
+						outOfBody = false
+					}
+					continue
+				} else if "</licenses>" == line {
+					outOfBody = true
+					continue
+				}
+
+				if len(tt.expectedOut) <= lineno {
+					t.Errorf("xmlnotice: unexpected output at line %d: got %q, want nothing (wanted %d lines)", lineno+1, line, len(tt.expectedOut))
+				} else if !tt.expectedOut[lineno].isMatch(line) {
+					t.Errorf("xmlnotice: unexpected output at line %d: got %q, want %q", lineno+1, line, tt.expectedOut[lineno].String())
+				}
+				lineno++
+			}
+			if !inBody {
+				t.Errorf("xmlnotice: missing <licenses> tag: got no <licenses> tag, want <licenses> tag on 2nd line")
+			}
+			if !outOfBody {
+				t.Errorf("xmlnotice: missing </licenses> tag: got no </licenses> tag, want </licenses> tag on last line")
+			}
+			for ; lineno < len(tt.expectedOut); lineno++ {
+				t.Errorf("xmlnotice: missing output line %d: ended early, want %q", lineno+1, tt.expectedOut[lineno].String())
+			}
+
+			t.Logf("got deps: %q", deps)
+
+			t.Logf("want deps: %q", tt.expectedDeps)
+
+			if g, w := deps, tt.expectedDeps; !reflect.DeepEqual(g, w) {
+				t.Errorf("unexpected deps, wanted:\n%s\ngot:\n%s\n",
+					strings.Join(w, "\n"), strings.Join(g, "\n"))
+			}
+		})
+	}
+}
+
+func escape(s string) string {
+	b := &bytes.Buffer{}
+	xml.EscapeText(b, []byte(s))
+	return b.String()
+}
+
+type matcher interface {
+	isMatch(line string) bool
+	String() string
+}
+
+type target struct {
+	name string
+	lib string
+}
+
+func (m target) isMatch(line string) bool {
+	groups := installTarget.FindStringSubmatch(line)
+	if len(groups) != 3 {
+		return false
+	}
+	return groups[1] == escape(m.lib) && strings.HasPrefix(groups[2], "out/") && strings.HasSuffix(groups[2], "/"+escape(m.name))
+}
+
+func (m target) String() string {
+	return `<file-name contentId="hash" lib="` + escape(m.lib) + `">` + escape(m.name) + `</file-name>`
+}
+
+func matchesText(line, text string) bool {
+	groups := licenseText.FindStringSubmatch(line)
+	if len(groups) != 2 {
+		return false
+	}
+	return groups[1] == escape(text + "\n")
+}
+
+func expectedText(text string) string {
+	return `<file-content contentId="hash"><![CDATA[` + escape(text + "\n") + `]]></file-content>`
+}
+
+type firstParty struct{}
+
+func (m firstParty) isMatch(line string) bool {
+	return matchesText(line, "&&&First Party License&&&")
+}
+
+func (m firstParty) String() string {
+	return expectedText("&&&First Party License&&&")
+}
+
+type notice struct{}
+
+func (m notice) isMatch(line string) bool {
+	return matchesText(line, "%%%Notice License%%%")
+}
+
+func (m notice) String() string {
+	return expectedText("%%%Notice License%%%")
+}
+
+type reciprocal struct{}
+
+func (m reciprocal) isMatch(line string) bool {
+	return matchesText(line, "$$$Reciprocal License$$$")
+}
+
+func (m reciprocal) String() string {
+	return expectedText("$$$Reciprocal License$$$")
+}
+
+type restricted struct{}
+
+func (m restricted) isMatch(line string) bool {
+	return matchesText(line, "###Restricted License###")
+}
+
+func (m restricted) String() string {
+	return expectedText("###Restricted License###")
+}
+
+type proprietary struct{}
+
+func (m proprietary) isMatch(line string) bool {
+	return matchesText(line, "@@@Proprietary License@@@")
+}
+
+func (m proprietary) String() string {
+	return expectedText("@@@Proprietary License@@@")
+}
+
+type matcherList []matcher
+
+func (l matcherList) String() string {
+	var sb strings.Builder
+	fmt.Fprintln(&sb, `<?xml version="1.0" encoding="utf-8"?>`)
+	fmt.Fprintln(&sb, `<licenses>`)
+	for _, m := range l {
+		s := m.String()
+		fmt.Fprintln(&sb, s)
+		if _, ok := m.(target); !ok {
+			fmt.Fprintln(&sb)
+		}
+	}
+	fmt.Fprintln(&sb, `/<licenses>`)
+	return sb.String()
+}
diff --git a/tools/releasetools/OWNERS b/tools/releasetools/OWNERS
index 9962836..d0b8627 100644
--- a/tools/releasetools/OWNERS
+++ b/tools/releasetools/OWNERS
@@ -1,6 +1,7 @@
 elsk@google.com
 nhdo@google.com
 xunchang@google.com
+zhangkelvin@google.com
 
 per-file merge_*.py = danielnorman@google.com
 
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index 88e6fd2..9a9fba1 100644
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -54,6 +54,7 @@
 import stat
 import sys
 import uuid
+import tempfile
 import zipfile
 
 import build_image
@@ -104,9 +105,10 @@
     if self._output_zip:
       self._zip_name = os.path.join(*args)
 
-  def Write(self):
+  def Write(self, compress_type=None):
     if self._output_zip:
-      common.ZipWrite(self._output_zip, self.name, self._zip_name)
+      common.ZipWrite(self._output_zip, self.name,
+                      self._zip_name, compress_type=compress_type)
 
 
 def AddSystem(output_zip, recovery_img=None, boot_img=None):
@@ -134,12 +136,13 @@
       "board_uses_vendorimage") == "true"
 
   if (OPTIONS.rebuild_recovery and not board_uses_vendorimage and
-      recovery_img is not None and boot_img is not None):
+          recovery_img is not None and boot_img is not None):
     logger.info("Building new recovery patch on system at system/vendor")
     common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img,
                              boot_img, info_dict=OPTIONS.info_dict)
 
-  block_list = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "system.map")
+  block_list = OutputFile(output_zip, OPTIONS.input_tmp,
+                          "IMAGES", "system.map")
   CreateImage(OPTIONS.input_tmp, OPTIONS.info_dict, "system", img,
               block_list=block_list)
   return img.name
@@ -182,12 +185,13 @@
       "board_uses_vendorimage") == "true"
 
   if (OPTIONS.rebuild_recovery and board_uses_vendorimage and
-      recovery_img is not None and boot_img is not None):
+          recovery_img is not None and boot_img is not None):
     logger.info("Building new recovery patch on vendor")
     common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img,
                              boot_img, info_dict=OPTIONS.info_dict)
 
-  block_list = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "vendor.map")
+  block_list = OutputFile(output_zip, OPTIONS.input_tmp,
+                          "IMAGES", "vendor.map")
   CreateImage(OPTIONS.input_tmp, OPTIONS.info_dict, "vendor", img,
               block_list=block_list)
   return img.name
@@ -389,15 +393,16 @@
       key_path, algorithm, extra_args)
 
   for img_name in OPTIONS.info_dict.get(
-      "avb_{}_image_list".format(partition_name)).split():
-    custom_image = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", img_name)
+          "avb_{}_image_list".format(partition_name)).split():
+    custom_image = OutputFile(
+        output_zip, OPTIONS.input_tmp, "IMAGES", img_name)
     if os.path.exists(custom_image.name):
       continue
 
     custom_image_prebuilt_path = os.path.join(
         OPTIONS.input_tmp, "PREBUILT_IMAGES", img_name)
     assert os.path.exists(custom_image_prebuilt_path), \
-      "Failed to find %s at %s" % (img_name, custom_image_prebuilt_path)
+        "Failed to find %s at %s" % (img_name, custom_image_prebuilt_path)
 
     shutil.copy(custom_image_prebuilt_path, custom_image.name)
 
@@ -499,7 +504,9 @@
   build_image.BuildImage(user_dir, image_props, img.name)
 
   common.CheckSize(img.name, "userdata.img", OPTIONS.info_dict)
-  img.Write()
+  # Always use compression for useradata image.
+  # As it's likely huge and consist of lots of 0s.
+  img.Write(zipfile.ZIP_DEFLATED)
 
 
 def AddVBMeta(output_zip, partitions, name, needed_partitions):
@@ -696,11 +703,11 @@
 
   return ((os.path.isdir(
       os.path.join(OPTIONS.input_tmp, partition_name.upper())) and
-           OPTIONS.info_dict.get(
-               "building_{}_image".format(partition_name)) == "true") or
-          os.path.exists(
-              os.path.join(OPTIONS.input_tmp, "IMAGES",
-                           "{}.img".format(partition_name))))
+      OPTIONS.info_dict.get(
+      "building_{}_image".format(partition_name)) == "true") or
+      os.path.exists(
+      os.path.join(OPTIONS.input_tmp, "IMAGES",
+                   "{}.img".format(partition_name))))
 
 
 def AddApexInfo(output_zip):
@@ -732,7 +739,7 @@
   boot_container = boot_images and (
       len(boot_images.split()) >= 2 or boot_images.split()[0] != 'boot.img')
   if (OPTIONS.info_dict.get("avb_enable") == "true" and not boot_container and
-      OPTIONS.info_dict.get("avb_building_vbmeta_image") == "true"):
+          OPTIONS.info_dict.get("avb_building_vbmeta_image") == "true"):
     avbtool = OPTIONS.info_dict["avb_avbtool"]
     digest = verity_utils.CalculateVbmetaDigest(OPTIONS.input_tmp, avbtool)
     vbmeta_digest_txt = os.path.join(OPTIONS.input_tmp, "META",
@@ -820,7 +827,7 @@
     boot_images = OPTIONS.info_dict.get("boot_images")
     if boot_images is None:
       boot_images = "boot.img"
-    for index,b in enumerate(boot_images.split()):
+    for index, b in enumerate(boot_images.split()):
       # common.GetBootableImage() returns the image directly if present.
       boot_image = common.GetBootableImage(
           "IMAGES/" + b, b, OPTIONS.input_tmp, "BOOT")
@@ -841,7 +848,8 @@
     init_boot_image = common.GetBootableImage(
         "IMAGES/init_boot.img", "init_boot.img", OPTIONS.input_tmp, "INIT_BOOT")
     if init_boot_image:
-      partitions['init_boot'] = os.path.join(OPTIONS.input_tmp, "IMAGES", "init_boot.img")
+      partitions['init_boot'] = os.path.join(
+          OPTIONS.input_tmp, "IMAGES", "init_boot.img")
       if not os.path.exists(partitions['init_boot']):
         init_boot_image.WriteToDir(OPTIONS.input_tmp)
         if output_zip:
@@ -968,7 +976,7 @@
 
   if OPTIONS.info_dict.get("build_super_partition") == "true":
     if OPTIONS.info_dict.get(
-        "build_retrofit_dynamic_partitions_ota_package") == "true":
+            "build_retrofit_dynamic_partitions_ota_package") == "true":
       banner("super split images")
       AddSuperSplit(output_zip)
 
@@ -1005,6 +1013,35 @@
                           OPTIONS.replace_updated_files_list)
 
 
+def OptimizeCompressedEntries(zipfile_path):
+  """Convert files that do not compress well to uncompressed storage
+
+  EROFS images tend to be compressed already, so compressing them again
+  yields little space savings. Leaving them uncompressed will make
+  downstream tooling's job easier, and save compute time.
+  """
+  if not zipfile.is_zipfile(zipfile_path):
+    return
+  entries_to_store = []
+  with tempfile.TemporaryDirectory() as tmpdir:
+    with zipfile.ZipFile(zipfile_path, "r", allowZip64=True) as zfp:
+      for zinfo in zfp.filelist:
+        if not zinfo.filename.startswith("IMAGES/") and not zinfo.filename.startswith("META"):
+          continue
+        # Don't try to store userdata.img uncompressed, it's usually huge.
+        if zinfo.filename.endswith("userdata.img"):
+          continue
+        if zinfo.compress_size > zinfo.file_size * 0.80 and zinfo.compress_type != zipfile.ZIP_STORED:
+          entries_to_store.append(zinfo)
+          zfp.extract(zinfo, tmpdir)
+    # Remove these entries, then re-add them as ZIP_STORED
+    common.RunAndCheckOutput(
+        ["zip", "-d", zipfile_path] + [entry.filename for entry in entries_to_store])
+    with zipfile.ZipFile(zipfile_path, "a", allowZip64=True) as zfp:
+      for entry in entries_to_store:
+        zfp.write(os.path.join(tmpdir, entry.filename), entry.filename, compress_type=zipfile.ZIP_STORED)
+
+
 def main(argv):
   def option_handler(o, a):
     if o in ("-a", "--add_missing"):
@@ -1036,8 +1073,10 @@
   common.InitLogging()
 
   AddImagesToTargetFiles(args[0])
+  OptimizeCompressedEntries(args[0])
   logger.info("done.")
 
+
 if __name__ == '__main__':
   try:
     common.CloseInheritedPipes()
diff --git a/tools/releasetools/check_target_files_signatures.py b/tools/releasetools/check_target_files_signatures.py
index 0f56fb9..d935607 100755
--- a/tools/releasetools/check_target_files_signatures.py
+++ b/tools/releasetools/check_target_files_signatures.py
@@ -237,9 +237,11 @@
     # Signer #1 certificate DN: ...
     # Signer #1 certificate SHA-256 digest: ...
     # Signer #1 certificate SHA-1 digest: ...
+    # Signer (minSdkVersion=24, maxSdkVersion=32) certificate SHA-256 digest: 56be132b780656fe2444cd34326eb5d7aac91d2096abf0fe673a99270622ec87
+    # Signer (minSdkVersion=24, maxSdkVersion=32) certificate SHA-1 digest: 19da94896ce4078c38ca695701f1dec741ec6d67
     # ...
     certs_info = {}
-    certificate_regex = re.compile(r"(Signer #[0-9]+) (certificate .*):(.*)")
+    certificate_regex = re.compile(r"(Signer (?:#[0-9]+|\(.*\))) (certificate .*):(.*)")
     for line in output.splitlines():
       m = certificate_regex.match(line)
       if not m:
@@ -342,8 +344,8 @@
           apk = APK(fullname, displayname)
           self.apks[apk.filename] = apk
           self.apks_by_basename[os.path.basename(apk.filename)] = apk
-
-          self.max_pkg_len = max(self.max_pkg_len, len(apk.package))
+          if apk.package:
+            self.max_pkg_len = max(self.max_pkg_len, len(apk.package))
           self.max_fn_len = max(self.max_fn_len, len(apk.filename))
 
   def CheckSharedUids(self):
@@ -396,7 +398,8 @@
     by_digest = {}
     for apk in self.apks.values():
       for digest in apk.cert_digests:
-        by_digest.setdefault(digest, []).append((apk.package, apk))
+        if apk.package:
+          by_digest.setdefault(digest, []).append((apk.package, apk))
 
     order = [(-len(v), k) for (k, v) in by_digest.items()]
     order.sort()