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
This commit is contained in:
parent
a0d58893fc
commit
094cde4430
3 changed files with 24 additions and 6 deletions
|
@ -2871,18 +2871,20 @@ func TestApexWithApps(t *testing.T) {
|
||||||
android_app {
|
android_app {
|
||||||
name: "AppFoo",
|
name: "AppFoo",
|
||||||
srcs: ["foo/bar/MyClass.java"],
|
srcs: ["foo/bar/MyClass.java"],
|
||||||
sdk_version: "none",
|
sdk_version: "current",
|
||||||
system_modules: "none",
|
system_modules: "none",
|
||||||
jni_libs: ["libjni"],
|
jni_libs: ["libjni"],
|
||||||
|
stl: "none",
|
||||||
apex_available: [ "myapex" ],
|
apex_available: [ "myapex" ],
|
||||||
}
|
}
|
||||||
|
|
||||||
android_app {
|
android_app {
|
||||||
name: "AppFooPriv",
|
name: "AppFooPriv",
|
||||||
srcs: ["foo/bar/MyClass.java"],
|
srcs: ["foo/bar/MyClass.java"],
|
||||||
sdk_version: "none",
|
sdk_version: "current",
|
||||||
system_modules: "none",
|
system_modules: "none",
|
||||||
privileged: true,
|
privileged: true,
|
||||||
|
stl: "none",
|
||||||
apex_available: [ "myapex" ],
|
apex_available: [ "myapex" ],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2892,6 +2894,7 @@ func TestApexWithApps(t *testing.T) {
|
||||||
stl: "none",
|
stl: "none",
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
apex_available: [ "myapex" ],
|
apex_available: [ "myapex" ],
|
||||||
|
sdk_version: "current",
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
|
21
java/app.go
21
java/app.go
|
@ -491,7 +491,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
|
||||||
dexJarFile := a.dexBuildActions(ctx)
|
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)
|
jniJarFile := a.jniBuildActions(jniLibs, ctx)
|
||||||
|
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
|
@ -527,7 +527,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 jniLibs []jniLib
|
||||||
var certificates []Certificate
|
var certificates []Certificate
|
||||||
seenModulePaths := make(map[string]bool)
|
seenModulePaths := make(map[string]bool)
|
||||||
|
@ -549,6 +550,18 @@ func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps
|
||||||
}
|
}
|
||||||
seenModulePaths[path.String()] = true
|
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() {
|
if lib.Valid() {
|
||||||
jniLibs = append(jniLibs, jniLib{
|
jniLibs = append(jniLibs, jniLib{
|
||||||
name: ctx.OtherModuleName(module),
|
name: ctx.OtherModuleName(module),
|
||||||
|
@ -1045,7 +1058,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")
|
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_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
|
||||||
// TODO: LOCAL_PACKAGE_SPLITS
|
// TODO: LOCAL_PACKAGE_SPLITS
|
||||||
|
@ -1300,7 +1313,7 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC
|
||||||
r.aapt.buildActions(ctx, r, "--no-resource-deduping", "--no-resource-removal")
|
r.aapt.buildActions(ctx, r, "--no-resource-deduping", "--no-resource-removal")
|
||||||
|
|
||||||
// Sign the built package
|
// Sign the built package
|
||||||
_, certificates := collectAppDeps(ctx, false)
|
_, certificates := collectAppDeps(ctx, false, false)
|
||||||
certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
|
certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
|
||||||
signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
|
signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
|
||||||
SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates)
|
SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates)
|
||||||
|
|
|
@ -903,6 +903,7 @@ func TestJNIPackaging(t *testing.T) {
|
||||||
name: "libjni",
|
name: "libjni",
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
stl: "none",
|
stl: "none",
|
||||||
|
sdk_version: "current",
|
||||||
}
|
}
|
||||||
|
|
||||||
android_app {
|
android_app {
|
||||||
|
@ -2112,6 +2113,7 @@ func TestEmbedNotice(t *testing.T) {
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
stl: "none",
|
stl: "none",
|
||||||
notice: "LIB_NOTICE",
|
notice: "LIB_NOTICE",
|
||||||
|
sdk_version: "current",
|
||||||
}
|
}
|
||||||
|
|
||||||
java_library {
|
java_library {
|
||||||
|
|
Loading…
Reference in a new issue