Merge "Use and export proguard flags from static dependencies"
diff --git a/java/aar.go b/java/aar.go
index 16d82af..47676fd 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -25,6 +25,7 @@
 type AndroidLibraryDependency interface {
 	Dependency
 	ExportPackage() android.Path
+	ExportedProguardFlagFiles() android.Paths
 }
 
 func init() {
@@ -247,6 +248,12 @@
 	androidLibraryProperties androidLibraryProperties
 
 	aarFile android.WritablePath
+
+	exportedProguardFlagFiles android.Paths
+}
+
+func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths {
+	return a.exportedProguardFlagFiles
 }
 
 var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
@@ -279,6 +286,14 @@
 		BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res)
 		ctx.CheckbuildFile(a.aarFile)
 	}
+
+	ctx.VisitDirectDeps(func(m android.Module) {
+		if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
+			a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
+		}
+	})
+
+	a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
 }
 
 func AndroidLibraryFactory() android.Module {
@@ -327,6 +342,10 @@
 	return a.exportPackage
 }
 
+func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
+	return android.Paths{a.proguardFlags}
+}
+
 func (a *AARImport) Prebuilt() *android.Prebuilt {
 	return &a.prebuilt
 }
diff --git a/java/androidmk.go b/java/androidmk.go
index fc93cfb..1e77d05 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -244,7 +244,8 @@
 
 		fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
 		fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
-		fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", a.proguardOptionsFile.String())
+		fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
+			strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
 		fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
 		fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
 	})
diff --git a/java/app.go b/java/app.go
index dd83a0a..1fdce12 100644
--- a/java/app.go
+++ b/java/app.go
@@ -63,6 +63,10 @@
 	appProperties appProperties
 }
 
+func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
+	return nil
+}
+
 var _ AndroidLibraryDependency = (*AndroidApp)(nil)
 
 type certificate struct {
@@ -116,8 +120,17 @@
 	// apps manifests are handled by aapt, don't let Module see them
 	a.properties.Manifest = nil
 
-	a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
-		a.proguardOptionsFile)
+	var staticLibProguardFlagFiles android.Paths
+	ctx.VisitDirectDeps(func(m android.Module) {
+		if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
+			staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
+		}
+	})
+
+	staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
+
+	a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
+	a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
 
 	if ctx.ModuleName() != "framework-res" {
 		a.Module.compile(ctx, a.aaptSrcJar)