Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b259ede3 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge changes from topics "soong-aar", "soong-bundle"

* changes:
  Pass AAR to make
  Create bundle modules suitable for bundletool
parents b551a777 a54974c8
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -188,3 +188,18 @@ func aapt2Link(ctx android.ModuleContext,
		},
	})
}

var aapt2ConvertRule = pctx.AndroidStaticRule("aapt2Convert",
	blueprint.RuleParams{
		Command:     `${config.Aapt2Cmd} convert --output-format proto $in -o $out`,
		CommandDeps: []string{"${config.Aapt2Cmd}"},
	})

func aapt2Convert(ctx android.ModuleContext, out android.WritablePath, in android.Path) {
	ctx.Build(pctx, android.BuildParams{
		Rule:        aapt2ConvertRule,
		Input:       in,
		Output:      out,
		Description: "convert to proto",
	})
}
+6 −0
Original line number Diff line number Diff line
@@ -209,6 +209,9 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData {
				if app.headerJarFile != nil {
					fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())
				}
				if app.bundleFile != nil {
					fmt.Fprintln(w, "LOCAL_SOONG_BUNDLE :=", app.bundleFile.String())
				}
				if app.jacocoReportClassesFile != nil {
					fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", app.jacocoReportClassesFile.String())
				}
@@ -290,6 +293,9 @@ func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
	data := a.Library.AndroidMk()

	data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
		if a.aarFile != nil {
			fmt.Fprintln(w, "LOCAL_SOONG_AAR :=", a.aarFile.String())
		}
		if a.proguardDictionary != nil {
			fmt.Fprintln(w, "LOCAL_SOONG_PROGUARD_DICT :=", a.proguardDictionary.String())
		}
+6 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ type AndroidApp struct {
	extraLinkFlags []string

	installJniLibs []jniLib

	bundleFile android.Path
}

func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
@@ -277,6 +279,10 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
	CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates)
	a.outputFile = packageFile

	bundleFile := android.PathForModuleOut(ctx, "base.zip")
	BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
	a.bundleFile = bundleFile

	if ctx.ModuleName() == "framework-res" {
		// framework-res.apk is installed as system/framework/framework-res.apk
		ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile)
+44 −0
Original line number Diff line number Diff line
@@ -134,6 +134,50 @@ func BuildAAR(ctx android.ModuleContext, outputFile android.WritablePath,
	})
}

var buildBundleModule = pctx.AndroidStaticRule("buildBundleModule",
	blueprint.RuleParams{
		Command: `${config.Zip2ZipCmd} -i ${in} -o ${out}.res.zip AndroidManifest.xml:manifest/AndroidManifest.xml resources.pb "res/**/*" "assets/**/*" &&` +
			`${config.Zip2ZipCmd} -i ${dexJar} -o ${out}.dex.zip "classes*.dex:dex/" && ` +
			`${config.MergeZipsCmd} ${out} ${out}.res.zip ${out}.dex.zip ${jniJar} && ` +
			`rm ${out}.res.zip ${out}.dex.zip`,
		CommandDeps: []string{
			"${config.Zip2ZipCmd}",
			"${config.MergeZipsCmd}",
		},
	}, "dexJar", "jniJar")

// Builds an app into a module suitable for input to bundletool
func BuildBundleModule(ctx android.ModuleContext, outputFile android.WritablePath,
	resJarFile, jniJarFile, dexJarFile android.Path) {

	protoResJarFile := android.PathForModuleOut(ctx, "package-res.pb.apk")
	aapt2Convert(ctx, protoResJarFile, resJarFile)

	var deps android.Paths
	var jniPath string
	var dexPath string
	if dexJarFile != nil {
		deps = append(deps, dexJarFile)
		dexPath = dexJarFile.String()
	}
	if jniJarFile != nil {
		deps = append(deps, jniJarFile)
		jniPath = jniJarFile.String()
	}

	ctx.Build(pctx, android.BuildParams{
		Rule:        buildBundleModule,
		Implicits:   deps,
		Input:       protoResJarFile,
		Output:      outputFile,
		Description: "bundle",
		Args: map[string]string{
			"dexJar": dexPath,
			"jniJar": jniPath,
		},
	})
}

func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.WritablePath,
	jniLibs []jniLib) {