Get dex jar resources from classpath jar

Dex jars were getting their resources from the res.jar files of
their transitive static dependencies.  This accidentally bypassed
jarjar on resources, since the jarjar pass only happened once the
resources jar was combined into the classpath jar.  Switch to
getting the resources out of the classpath jar by merging it
with the dex jar while skipping *.class.

Test: m -j checkbuild
Test: compare ext.jar to one generated by make
Change-Id: I5f6f3da738dcb0af56ab9a1bd7174ed5359de2b2
This commit is contained in:
Colin Cross
2017-10-04 17:07:09 -07:00
parent 0cf45cdc1e
commit 7db5d6332f
2 changed files with 9 additions and 30 deletions

View File

@@ -99,10 +99,12 @@ var (
blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`${config.DxCmd} --dex --output=$outDir $dxFlags $in && ` +
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
`${config.SoongZipCmd} -o $outDir/classes.dex.jar -C $outDir -D $outDir && ` +
`${config.MergeZipsCmd} -D -stripFile "*.class" $out $outDir/classes.dex.jar $in`,
CommandDeps: []string{
"${config.DxCmd}",
"${config.SoongZipCmd}",
"${config.MergeZipsCmd}",
},
},
"outDir", "dxFlags")
@@ -298,11 +300,13 @@ func TransformDesugar(ctx android.ModuleContext, classesJar android.Path,
return outputFile
}
func TransformClassesJarToDexJar(ctx android.ModuleContext, classesJar android.Path,
// Converts a classes.jar file to classes*.dex, then combines the dex files with any resources
// in the classes.jar file into a dex jar.
func TransformClassesJarToDexJar(ctx android.ModuleContext, stem string, classesJar android.Path,
flags javaBuilderFlags) android.Path {
outDir := android.PathForModuleOut(ctx, "dex")
outputFile := android.PathForModuleOut(ctx, "classes.dex.jar")
outputFile := android.PathForModuleOut(ctx, stem)
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: dx,

View File

@@ -153,9 +153,6 @@ type Module struct {
// output file containing classes.dex
dexJarFile android.Path
// output files containing resources
resourceJarFiles android.Paths
// output file suitable for installing or running
outputFile android.Path
@@ -173,7 +170,6 @@ type Module struct {
type Dependency interface {
ClasspathFiles() android.Paths
ResourceJarFiles() android.Paths
AidlIncludeDirs() android.Paths
}
@@ -380,7 +376,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
case staticLibTag:
deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...)
deps.staticJarResources = append(deps.staticJarResources, dep.ResourceJarFiles()...)
case frameworkResTag:
if ctx.ModuleName() == "framework" {
// framework.jar has a one-off dependency on the R.java and Manifest.java files
@@ -492,20 +487,14 @@ func (j *Module) compile(ctx android.ModuleContext) {
}
if len(resArgs) > 0 {
// Combine classes + resources into classes-full-debug.jar
resourceJar := TransformResourcesToJar(ctx, resArgs, resDeps)
if ctx.Failed() {
return
}
j.resourceJarFiles = append(j.resourceJarFiles, resourceJar)
jars = append(jars, resourceJar)
}
// Propagate the resources from the transitive closure of static dependencies for copying
// into dex jars
j.resourceJarFiles = append(j.resourceJarFiles, deps.staticJarResources...)
// static classpath jars have the resources in them, so the resource jars aren't necessary here
jars = append(jars, deps.staticJars...)
@@ -580,17 +569,12 @@ func (j *Module) compile(ctx android.ModuleContext) {
return
}
// Compile classes.jar into classes.dex
dexJarFile := TransformClassesJarToDexJar(ctx, desugarJar, flags)
// Compile classes.jar into classes.dex and then javalib.jar
outputFile = TransformClassesJarToDexJar(ctx, "javalib.jar", desugarJar, flags)
if ctx.Failed() {
return
}
jars := android.Paths{dexJarFile}
jars = append(jars, j.resourceJarFiles...)
outputFile = TransformJarsToJar(ctx, "javalib.jar", jars, android.OptionalPath{}, true)
j.dexJarFile = outputFile
}
ctx.CheckbuildFile(outputFile)
@@ -607,10 +591,6 @@ func (j *Module) ClasspathFiles() android.Paths {
return android.Paths{j.classpathFile}
}
func (j *Module) ResourceJarFiles() android.Paths {
return j.resourceJarFiles
}
func (j *Module) AidlIncludeDirs() android.Paths {
return j.exportAidlIncludeDirs
}
@@ -777,11 +757,6 @@ func (j *Import) ClasspathFiles() android.Paths {
return j.classpathFiles
}
func (j *Import) ResourceJarFiles() android.Paths {
// resources are in the ClasspathFiles
return nil
}
func (j *Import) AidlIncludeDirs() android.Paths {
return nil
}