Fix multi-dex builds
Building with --multi-dex requires passing an output directory instead of an output file to dx. Change-Id: I9ffcfe8ff6b96dbdda3eec1076124cd38ae5077f
This commit is contained in:
@@ -58,7 +58,9 @@ var (
|
|||||||
|
|
||||||
dx = pctx.StaticRule("dx",
|
dx = pctx.StaticRule("dx",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "$dxCmd --dex --output=$out $dxFlags $in",
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||||
|
`$dxCmd --dex --output=$outDir $dxFlags $in || ( rm -rf "$outDir"; exit 41 ) && ` +
|
||||||
|
`find "$outDir" -name "classes*.dex" > $out`,
|
||||||
Description: "dex $out",
|
Description: "dex $out",
|
||||||
},
|
},
|
||||||
"outDir", "dxFlags")
|
"outDir", "dxFlags")
|
||||||
@@ -164,9 +166,10 @@ func TransformClassesToJar(ctx common.AndroidModuleContext, classes []jarSpec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TransformClassesJarToDex(ctx common.AndroidModuleContext, classesJar string,
|
func TransformClassesJarToDex(ctx common.AndroidModuleContext, classesJar string,
|
||||||
flags javaBuilderFlags) string {
|
flags javaBuilderFlags) jarSpec {
|
||||||
|
|
||||||
outputFile := filepath.Join(common.ModuleOutDir(ctx), "classes.dex")
|
outDir := filepath.Join(common.ModuleOutDir(ctx), "dex")
|
||||||
|
outputFile := filepath.Join(common.ModuleOutDir(ctx), "dex.filelist")
|
||||||
|
|
||||||
ctx.Build(pctx, blueprint.BuildParams{
|
ctx.Build(pctx, blueprint.BuildParams{
|
||||||
Rule: dx,
|
Rule: dx,
|
||||||
@@ -175,14 +178,15 @@ func TransformClassesJarToDex(ctx common.AndroidModuleContext, classesJar string
|
|||||||
Implicits: []string{"$dxCmd"},
|
Implicits: []string{"$dxCmd"},
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"dxFlags": flags.dxFlags,
|
"dxFlags": flags.dxFlags,
|
||||||
|
"outDir": outDir,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return outputFile
|
return jarSpec{outputFile, outDir}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformDexToJavaLib(ctx common.AndroidModuleContext, resources []jarSpec,
|
func TransformDexToJavaLib(ctx common.AndroidModuleContext, resources []jarSpec,
|
||||||
dexFile string) string {
|
dexJarSpec jarSpec) string {
|
||||||
|
|
||||||
outputFile := filepath.Join(common.ModuleOutDir(ctx), "javalib.jar")
|
outputFile := filepath.Join(common.ModuleOutDir(ctx), "javalib.jar")
|
||||||
var deps []string
|
var deps []string
|
||||||
@@ -193,10 +197,8 @@ func TransformDexToJavaLib(ctx common.AndroidModuleContext, resources []jarSpec,
|
|||||||
jarArgs = append(jarArgs, j.soongJarArgs())
|
jarArgs = append(jarArgs, j.soongJarArgs())
|
||||||
}
|
}
|
||||||
|
|
||||||
dexDir, _ := filepath.Split(dexFile)
|
deps = append(deps, dexJarSpec.fileList)
|
||||||
jarArgs = append(jarArgs, "-C "+dexDir+" -f "+dexFile)
|
jarArgs = append(jarArgs, dexJarSpec.soongJarArgs())
|
||||||
|
|
||||||
deps = append(deps, "$jarCmd", dexFile)
|
|
||||||
|
|
||||||
ctx.Build(pctx, blueprint.BuildParams{
|
ctx.Build(pctx, blueprint.BuildParams{
|
||||||
Rule: jar,
|
Rule: jar,
|
||||||
|
@@ -326,13 +326,13 @@ func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
|
|||||||
flags.dxFlags = strings.Join(dxFlags, " ")
|
flags.dxFlags = strings.Join(dxFlags, " ")
|
||||||
|
|
||||||
// Compile classes.jar into classes.dex
|
// Compile classes.jar into classes.dex
|
||||||
dexFile := TransformClassesJarToDex(ctx, outputFile, flags)
|
dexJarSpec := TransformClassesJarToDex(ctx, outputFile, flags)
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine classes.dex + resources into javalib.jar
|
// Combine classes.dex + resources into javalib.jar
|
||||||
outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexFile)
|
outputFile = TransformDexToJavaLib(ctx, resourceJarSpecs, dexJarSpec)
|
||||||
}
|
}
|
||||||
|
|
||||||
j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", outputFile)
|
j.installFile = ctx.InstallFileName("framework", ctx.ModuleName()+".jar", outputFile)
|
||||||
|
Reference in New Issue
Block a user