diff --git a/java/hiddenapi.go b/java/hiddenapi.go index de72e7c79..29f23b1a8 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -68,18 +68,27 @@ var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", bluepr ` echo "--input-dex=$${INPUT_DEX}"; ` + ` echo "--output-dex=$tmpDir/dex-output/$$(basename $${INPUT_DEX})"; ` + `done | xargs ${config.HiddenAPI} encode --api-flags=$flags && ` + - `${config.SoongZipCmd} -o $tmpDir/dex.jar -C $tmpDir/dex-output -f "$tmpDir/dex-output/classes*.dex" && ` + + `${config.SoongZipCmd} $soongZipFlags -o $tmpDir/dex.jar -C $tmpDir/dex-output -f "$tmpDir/dex-output/classes*.dex" && ` + `${config.MergeZipsCmd} -D -zipToNotStrip $tmpDir/dex.jar -stripFile "classes*.dex" $out $tmpDir/dex.jar $in`, CommandDeps: []string{ "${config.HiddenAPI}", "${config.SoongZipCmd}", "${config.MergeZipsCmd}", }, -}, "flags", "tmpDir") +}, "flags", "tmpDir", "soongZipFlags") + +func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath, dexInput android.WritablePath, + uncompressDex bool) { -func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath, dexInput android.WritablePath) { flags := &bootImagePath{ctx.Config().HiddenAPIFlags()} + // The encode dex rule requires unzipping and rezipping the classes.dex files, ensure that if it was uncompressed + // in the input it stays uncompressed in the output. + soongZipFlags := "" + if uncompressDex { + soongZipFlags = "-L 0" + } + ctx.Build(pctx, android.BuildParams{ Rule: hiddenAPIEncodeDexRule, Description: "hiddenapi encode dex", @@ -87,8 +96,9 @@ func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath, Output: output, Implicit: flags, Args: map[string]string{ - "flags": flags.String(), - "tmpDir": android.PathForModuleOut(ctx, "hiddenapi", "dex").String(), + "flags": flags.String(), + "tmpDir": android.PathForModuleOut(ctx, "hiddenapi", "dex").String(), + "soongZipFlags": soongZipFlags, }, }) diff --git a/java/java.go b/java/java.go index 209d0a703..9c4bd869e 100644 --- a/java/java.go +++ b/java/java.go @@ -1188,7 +1188,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path } if isBootJar { hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", jarName) - hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexOutputFile) + hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexOutputFile, j.deviceProperties.UncompressDex) dexOutputFile = hiddenAPIJar } }