aboutsummaryrefslogtreecommitdiffstats
path: root/java/app.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2020-02-15 10:38:00 -0800
committerColin Cross <ccross@android.com>2020-04-27 14:45:05 -0700
commit1c93c299fb0036b823e821237a8e52febe82679a (patch)
tree6454ccd1397779d2492b1054f8fc7c71008c8ac0 /java/app.go
parente3643da7444a14ad13f400136fc4c18a4160b4c5 (diff)
downloadbuild_soong-1c93c299fb0036b823e821237a8e52febe82679a.tar.gz
build_soong-1c93c299fb0036b823e821237a8e52febe82679a.tar.bz2
build_soong-1c93c299fb0036b823e821237a8e52febe82679a.zip
Require apps built against the SDK to use JNI built against the NDK
Apps that expect to run on older platforms should use JNI libraries that will also run on older platforms. Require that apps that set sdk_version have jni_libs modules that also set sdk_version, or set jni_uses_platform_apis: true to bypass the check. Fixes: 149591057 Test: app_test.go Change-Id: I76b9b45fb5773bc4dfc10520108f4f3578723909 Merged-In: I76b9b45fb5773bc4dfc10520108f4f3578723909
Diffstat (limited to 'java/app.go')
-rwxr-xr-xjava/app.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/java/app.go b/java/app.go
index 0ec2502b..d9376540 100755
--- a/java/app.go
+++ b/java/app.go
@@ -542,7 +542,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
dexJarFile := a.dexBuildActions(ctx)
- jniLibs, certificateDeps := collectAppDeps(ctx, a.shouldEmbedJnis(ctx))
+ jniLibs, certificateDeps := collectAppDeps(ctx, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
jniJarFile := a.jniBuildActions(jniLibs, ctx)
if ctx.Failed() {
@@ -592,7 +592,8 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
}
}
-func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps bool) ([]jniLib, []Certificate) {
+func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps bool,
+ checkNativeSdkVersion bool) ([]jniLib, []Certificate) {
var jniLibs []jniLib
var certificates []Certificate
seenModulePaths := make(map[string]bool)
@@ -614,6 +615,18 @@ func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps
}
seenModulePaths[path.String()] = true
+ if checkNativeSdkVersion {
+ if app, ok := ctx.Module().(interface{ sdkVersion() sdkSpec }); ok {
+ if app.sdkVersion().specified() &&
+ app.sdkVersion().kind != sdkCorePlatform &&
+ dep.SdkVersion() == "" {
+ ctx.PropertyErrorf("jni_libs",
+ "JNI dependency %q uses platform APIs, but this module does not",
+ otherName)
+ }
+ }
+ }
+
if lib.Valid() {
jniLibs = append(jniLibs, jniLib{
name: ctx.OtherModuleName(module),
@@ -1133,7 +1146,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext
ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
}
- _, certificates := collectAppDeps(ctx, false)
+ _, certificates := collectAppDeps(ctx, false, false)
// TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
// TODO: LOCAL_PACKAGE_SPLITS
@@ -1405,7 +1418,7 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC
r.aapt.buildActions(ctx, r, "--no-resource-deduping", "--no-resource-removal")
// Sign the built package
- _, certificates := collectAppDeps(ctx, false)
+ _, certificates := collectAppDeps(ctx, false, false)
certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, nil)