2015-04-13 22:58:27 +02:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
// This file generates the final rules for compiling all Java. All properties related to
|
|
|
|
// compiling should have been translated into javaBuilderFlags or another argument to the Transform*
|
|
|
|
// functions.
|
|
|
|
|
|
|
|
import (
|
2018-10-03 07:03:40 +02:00
|
|
|
"path/filepath"
|
2015-04-13 22:58:27 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2018-10-03 07:03:40 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-04-13 22:58:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-10-30 13:20:05 +01:00
|
|
|
Signapk = pctx.AndroidStaticRule("signapk",
|
2015-04-13 22:58:27 +02:00
|
|
|
blueprint.RuleParams{
|
2017-11-23 01:20:45 +01:00
|
|
|
Command: `${config.JavaCmd} -Djava.library.path=$$(dirname $signapkJniLibrary) ` +
|
|
|
|
`-jar $signapkCmd $certificates $in $out`,
|
|
|
|
CommandDeps: []string{"$signapkCmd", "$signapkJniLibrary"},
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
"certificates")
|
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger",
|
2015-04-13 22:58:27 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " +
|
|
|
|
"--main $in --libs $libsManifests --out $out",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$androidManifestMergerCmd"},
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "merge manifest files",
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
"libsManifests")
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-09-24 00:26:20 +02:00
|
|
|
pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar")
|
|
|
|
pctx.HostBinToolVariable("aaptCmd", "aapt")
|
|
|
|
pctx.HostJavaToolVariable("signapkCmd", "signapk.jar")
|
2017-11-23 01:20:45 +01:00
|
|
|
// TODO(ccross): this should come from the signapk dependencies, but we don't have any way
|
|
|
|
// to express host JNI dependencies yet.
|
|
|
|
pctx.HostJNIToolVariable("signapkJniLibrary", "libconscrypt_openjdk_jni")
|
2015-04-13 22:58:27 +02:00
|
|
|
}
|
|
|
|
|
2017-11-23 01:19:37 +01:00
|
|
|
var combineApk = pctx.AndroidStaticRule("combineApk",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `${config.MergeZipsCmd} $out $in`,
|
|
|
|
CommandDeps: []string{"${config.MergeZipsCmd}"},
|
2015-04-13 22:58:27 +02:00
|
|
|
})
|
|
|
|
|
2017-11-23 01:19:37 +01:00
|
|
|
func CreateAppPackage(ctx android.ModuleContext, outputFile android.WritablePath,
|
2018-10-30 13:20:05 +01:00
|
|
|
resJarFile, jniJarFile, dexJarFile android.Path, certificates []Certificate) {
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2017-11-23 01:19:37 +01:00
|
|
|
unsignedApk := android.PathForModuleOut(ctx, "unsigned.apk")
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2018-10-03 07:03:40 +02:00
|
|
|
var inputs android.Paths
|
2017-11-23 01:19:37 +01:00
|
|
|
if dexJarFile != nil {
|
|
|
|
inputs = append(inputs, dexJarFile)
|
|
|
|
}
|
2018-10-03 07:03:40 +02:00
|
|
|
inputs = append(inputs, resJarFile)
|
|
|
|
if jniJarFile != nil {
|
|
|
|
inputs = append(inputs, jniJarFile)
|
|
|
|
}
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-11-23 01:19:37 +01:00
|
|
|
Rule: combineApk,
|
|
|
|
Inputs: inputs,
|
|
|
|
Output: unsignedApk,
|
2015-04-13 22:58:27 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
var certificateArgs []string
|
|
|
|
for _, c := range certificates {
|
2018-10-30 13:20:05 +01:00
|
|
|
certificateArgs = append(certificateArgs, c.Pem.String(), c.Key.String())
|
2015-04-13 22:58:27 +02:00
|
|
|
}
|
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2018-10-30 13:20:05 +01:00
|
|
|
Rule: Signapk,
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "signapk",
|
|
|
|
Output: outputFile,
|
2017-11-23 01:19:37 +01:00
|
|
|
Input: unsignedApk,
|
2015-04-13 22:58:27 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"certificates": strings.Join(certificateArgs, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
var buildAAR = pctx.AndroidStaticRule("buildAAR",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `rm -rf ${outDir} && mkdir -p ${outDir} && ` +
|
|
|
|
`cp ${manifest} ${outDir}/AndroidManifest.xml && ` +
|
|
|
|
`cp ${classesJar} ${outDir}/classes.jar && ` +
|
|
|
|
`cp ${rTxt} ${outDir}/R.txt && ` +
|
2018-09-19 02:05:15 +02:00
|
|
|
`${config.SoongZipCmd} -jar -o $out -C ${outDir} -D ${outDir}`,
|
2018-03-28 23:58:31 +02:00
|
|
|
CommandDeps: []string{"${config.SoongZipCmd}"},
|
|
|
|
},
|
2018-09-19 02:05:15 +02:00
|
|
|
"manifest", "classesJar", "rTxt", "outDir")
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
func BuildAAR(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
classesJar, manifest, rTxt android.Path, res android.Paths) {
|
|
|
|
|
|
|
|
// TODO(ccross): uniquify and copy resources with dependencies
|
|
|
|
|
|
|
|
deps := android.Paths{manifest, rTxt}
|
|
|
|
classesJarPath := ""
|
|
|
|
if classesJar != nil {
|
|
|
|
deps = append(deps, classesJar)
|
|
|
|
classesJarPath = classesJar.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: buildAAR,
|
|
|
|
Implicits: deps,
|
|
|
|
Output: outputFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"manifest": manifest.String(),
|
|
|
|
"classesJar": classesJarPath,
|
|
|
|
"rTxt": rTxt.String(),
|
|
|
|
"outDir": android.PathForModuleOut(ctx, "aar").String(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-10-03 07:03:40 +02:00
|
|
|
|
2018-10-30 07:14:58 +01:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-03 07:03:40 +02:00
|
|
|
func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
jniLibs []jniLib) {
|
|
|
|
|
|
|
|
var deps android.Paths
|
|
|
|
jarArgs := []string{
|
|
|
|
"-j", // junk paths, they will be added back with -P arguments
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ctx.Config().UnbundledBuild() {
|
|
|
|
jarArgs = append(jarArgs, "-L 0")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, j := range jniLibs {
|
|
|
|
deps = append(deps, j.path)
|
|
|
|
jarArgs = append(jarArgs,
|
|
|
|
"-P "+targetToJniDir(j.target),
|
|
|
|
"-f "+j.path.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: zip,
|
|
|
|
Description: "zip jni libs",
|
|
|
|
Output: outputFile,
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"jarArgs": strings.Join(proptools.NinjaAndShellEscape(jarArgs), " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func targetToJniDir(target android.Target) string {
|
|
|
|
return filepath.Join("lib", target.Arch.Abi[0])
|
|
|
|
}
|