Merge "Make manifest and APK agree on uncompressed native libs" am: 53d312637f
am: d33cdc21bb
am: 7ea16f4cdf
Change-Id: I0a90e565c358ceb5eabb97e104176461dfef3171
This commit is contained in:
@@ -75,6 +75,7 @@ type aapt struct {
|
||||
rTxt android.Path
|
||||
extraAaptPackagesFile android.Path
|
||||
isLibrary bool
|
||||
uncompressedJNI bool
|
||||
|
||||
aaptProperties aaptProperties
|
||||
}
|
||||
@@ -181,7 +182,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
||||
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
||||
|
||||
manifestPath := manifestMerger(ctx, manifestSrcPath, sdkContext, staticLibManifests, a.isLibrary)
|
||||
manifestPath := manifestMerger(ctx, manifestSrcPath, sdkContext, staticLibManifests, a.isLibrary, a.uncompressedJNI)
|
||||
|
||||
linkFlags, linkDeps, resDirs, overlayDirs, rroDirs := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
||||
|
||||
@@ -330,7 +331,7 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.isLibrary = true
|
||||
a.aapt.isLibrary = true
|
||||
a.aapt.buildActions(ctx, sdkContext(a))
|
||||
|
||||
ctx.CheckbuildFile(a.proguardOptionsFile)
|
||||
|
@@ -15,12 +15,13 @@
|
||||
package java
|
||||
|
||||
import (
|
||||
"android/soong/java/config"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java/config"
|
||||
)
|
||||
|
||||
var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer",
|
||||
@@ -43,11 +44,22 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
|
||||
"libs")
|
||||
|
||||
func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
|
||||
staticLibManifests android.Paths, isLibrary bool) android.Path {
|
||||
staticLibManifests android.Paths, isLibrary bool, uncompressedJNI bool) android.Path {
|
||||
|
||||
var args []string
|
||||
if isLibrary {
|
||||
args = append(args, "--library")
|
||||
} else {
|
||||
minSdkVersion, err := sdkVersionToNumber(ctx, sdkContext.minSdkVersion())
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
|
||||
}
|
||||
if minSdkVersion >= 23 {
|
||||
args = append(args, fmt.Sprintf("--extract-native-libs=%v", !uncompressedJNI))
|
||||
} else if uncompressedJNI {
|
||||
ctx.ModuleErrorf("module attempted to store uncompressed native libraries, but minSdkVersion=%d doesn't support it",
|
||||
minSdkVersion)
|
||||
}
|
||||
}
|
||||
|
||||
// Inject minSdkVersion into the manifest
|
||||
|
26
java/app.go
26
java/app.go
@@ -68,7 +68,11 @@ type appProperties struct {
|
||||
// list of native libraries that will be provided in or alongside the resulting jar
|
||||
Jni_libs []string `android:"arch_variant"`
|
||||
|
||||
EmbedJNI bool `blueprint:"mutated"`
|
||||
// Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest
|
||||
// flag so that they are used from inside the APK at runtime. Defaults to true for android_test modules unless
|
||||
// sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to false for other
|
||||
// module types where the native libraries are generally preinstalled outside the APK.
|
||||
Use_embedded_native_libs *bool
|
||||
}
|
||||
|
||||
type AndroidApp struct {
|
||||
@@ -136,9 +140,21 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.aapt.uncompressedJNI = a.shouldUncompressJNI(ctx)
|
||||
a.generateAndroidBuildActions(ctx)
|
||||
}
|
||||
|
||||
// shouldUncompressJNI returns true if the native libraries should be stored in the APK uncompressed and the
|
||||
// extractNativeLibs application flag should be set to false in the manifest.
|
||||
func (a *AndroidApp) shouldUncompressJNI(ctx android.ModuleContext) bool {
|
||||
minSdkVersion, err := sdkVersionToNumber(ctx, a.minSdkVersion())
|
||||
if err != nil {
|
||||
ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
|
||||
}
|
||||
|
||||
return minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)
|
||||
}
|
||||
|
||||
// Returns whether this module should have the dex file stored uncompressed in the APK.
|
||||
func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
|
||||
if ctx.Config().UnbundledBuild() {
|
||||
@@ -230,10 +246,10 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
|
||||
func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath {
|
||||
var jniJarFile android.WritablePath
|
||||
if len(jniLibs) > 0 {
|
||||
embedJni := ctx.Config().UnbundledBuild() || a.appProperties.EmbedJNI
|
||||
embedJni := ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs)
|
||||
if embedJni {
|
||||
jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
|
||||
TransformJniLibsToJar(ctx, jniJarFile, jniLibs)
|
||||
TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.shouldUncompressJNI(ctx))
|
||||
} else {
|
||||
a.installJniLibs = jniLibs
|
||||
}
|
||||
@@ -428,7 +444,7 @@ func AndroidTestFactory() android.Module {
|
||||
|
||||
module.Module.properties.Instrument = true
|
||||
module.Module.properties.Installable = proptools.BoolPtr(true)
|
||||
module.appProperties.EmbedJNI = true
|
||||
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
|
||||
module.Module.dexpreopter.isTest = true
|
||||
|
||||
module.AddProperties(
|
||||
@@ -464,7 +480,7 @@ func AndroidTestHelperAppFactory() android.Module {
|
||||
module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
|
||||
|
||||
module.Module.properties.Installable = proptools.BoolPtr(true)
|
||||
module.appProperties.EmbedJNI = true
|
||||
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
|
||||
module.Module.dexpreopter.isTest = true
|
||||
|
||||
module.AddProperties(
|
||||
|
@@ -200,14 +200,14 @@ func BuildBundleModule(ctx android.ModuleContext, outputFile android.WritablePat
|
||||
}
|
||||
|
||||
func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
jniLibs []jniLib) {
|
||||
jniLibs []jniLib, uncompressJNI bool) {
|
||||
|
||||
var deps android.Paths
|
||||
jarArgs := []string{
|
||||
"-j", // junk paths, they will be added back with -P arguments
|
||||
}
|
||||
|
||||
if !ctx.Config().UnbundledBuild() {
|
||||
if uncompressJNI {
|
||||
jarArgs = append(jarArgs, "-L 0")
|
||||
}
|
||||
|
||||
|
@@ -122,8 +122,8 @@ var (
|
||||
|
||||
zipalign = pctx.AndroidStaticRule("zipalign",
|
||||
blueprint.RuleParams{
|
||||
Command: "if ! ${config.ZipAlign} -c 4 $in > /dev/null; then " +
|
||||
"${config.ZipAlign} -f 4 $in $out; " +
|
||||
Command: "if ! ${config.ZipAlign} -c -p 4 $in > /dev/null; then " +
|
||||
"${config.ZipAlign} -f -p 4 $in $out; " +
|
||||
"else " +
|
||||
"cp -f $in $out; " +
|
||||
"fi",
|
||||
|
Reference in New Issue
Block a user