summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/androidmk.go5
-rw-r--r--java/app.go19
-rw-r--r--java/java.go63
3 files changed, 74 insertions, 13 deletions
diff --git a/java/androidmk.go b/java/androidmk.go
index 05106806a..c97373926 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -262,6 +262,11 @@ func (binary *Binary) AndroidMkEntries() android.AndroidMkEntries {
}
func (app *AndroidApp) AndroidMkEntries() android.AndroidMkEntries {
+ if !app.IsForPlatform() {
+ return android.AndroidMkEntries{
+ Disabled: true,
+ }
+ }
return android.AndroidMkEntries{
Class: "APPS",
OutputFile: android.OptionalPathForPath(app.outputFile),
diff --git a/java/app.go b/java/app.go
index d53d62614..30cd6cb68 100644
--- a/java/app.go
+++ b/java/app.go
@@ -78,8 +78,9 @@ type appProperties struct {
// 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.
+ // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to true for
+ // android_app modules that are embedded to APEXes, defaults to false for other module types where the native
+ // libraries are generally preinstalled outside the APK.
Use_embedded_native_libs *bool
// Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that
@@ -217,7 +218,8 @@ func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
}
- return minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)
+ return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
+ !a.IsForPlatform()
}
// Returns whether this module should have the dex file stored uncompressed in the APK.
@@ -241,7 +243,7 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
- a.appProperties.AlwaysPackageNativeLibs
+ !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
}
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
@@ -496,9 +498,11 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
a.bundleFile = bundleFile
// Install the app package.
- ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
- for _, extra := range a.extraOutputFiles {
- ctx.InstallFile(a.installDir, extra.Base(), extra)
+ if (Bool(a.Module.properties.Installable) || ctx.Host()) && a.IsForPlatform() {
+ ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
+ for _, extra := range a.extraOutputFiles {
+ ctx.InstallFile(a.installDir, extra.Base(), extra)
+ }
}
}
@@ -585,6 +589,7 @@ func AndroidAppFactory() android.Module {
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
android.InitOverridableModule(module, &module.appProperties.Overrides)
+ android.InitApexModule(module)
return module
}
diff --git a/java/java.go b/java/java.go
index 9bbdff74c..d4f65ba42 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1664,6 +1664,57 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
j.deps(ctx)
}
+const (
+ aidlIncludeDir = "aidl"
+ javaStubDir = "java"
+ javaStubFileSuffix = ".jar"
+)
+
+// path to the stub file of a java library. Relative to <sdk_root>/<api_dir>
+func (j *Library) javaStubFilePathFor() string {
+ return filepath.Join(javaStubDir, j.Name()+javaStubFileSuffix)
+}
+
+func (j *Library) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder) {
+ headerJars := j.HeaderJars()
+ if len(headerJars) != 1 {
+ panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
+ }
+ snapshotRelativeJavaLibPath := j.javaStubFilePathFor()
+ builder.CopyToSnapshot(headerJars[0], snapshotRelativeJavaLibPath)
+
+ for _, dir := range j.AidlIncludeDirs() {
+ // TODO(jiyong): copy parcelable declarations only
+ aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
+ for _, file := range aidlFiles {
+ builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
+ }
+ }
+
+ name := j.Name()
+ bp := builder.AndroidBpFile()
+ bp.Printfln("java_import {")
+ bp.Indent()
+ bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
+ bp.Printfln("sdk_member_name: %q,", name)
+ bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath)
+ bp.Dedent()
+ bp.Printfln("}")
+ bp.Printfln("")
+
+ // This module is for the case when the source tree for the unversioned module
+ // doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
+ // so that this module does not eclipse the unversioned module if it exists.
+ bp.Printfln("java_import {")
+ bp.Indent()
+ bp.Printfln("name: %q,", name)
+ bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath)
+ bp.Printfln("prefer: false,")
+ bp.Dedent()
+ bp.Printfln("}")
+ bp.Printfln("")
+}
+
// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
//
// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
@@ -1684,9 +1735,9 @@ func LibraryFactory() android.Module {
&module.Module.dexpreoptProperties,
&module.Module.protoProperties)
- InitJavaModule(module, android.HostAndDeviceSupported)
android.InitApexModule(module)
android.InitSdkAwareModule(module)
+ InitJavaModule(module, android.HostAndDeviceSupported)
return module
}
@@ -1708,8 +1759,8 @@ func LibraryHostFactory() android.Module {
module.Module.properties.Installable = proptools.BoolPtr(true)
- InitJavaModule(module, android.HostSupported)
android.InitApexModule(module)
+ InitJavaModule(module, android.HostSupported)
return module
}
@@ -2135,9 +2186,9 @@ func ImportFactory() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- InitJavaModule(module, android.HostAndDeviceSupported)
android.InitApexModule(module)
android.InitSdkAwareModule(module)
+ InitJavaModule(module, android.HostAndDeviceSupported)
return module
}
@@ -2152,8 +2203,8 @@ func ImportFactoryHost() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- InitJavaModule(module, android.HostSupported)
android.InitApexModule(module)
+ InitJavaModule(module, android.HostSupported)
return module
}
@@ -2264,8 +2315,8 @@ func DexImportFactory() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- InitJavaModule(module, android.DeviceSupported)
android.InitApexModule(module)
+ InitJavaModule(module, android.DeviceSupported)
return module
}
@@ -2331,10 +2382,10 @@ func DefaultsFactory(props ...interface{}) android.Module {
&AARImportProperties{},
&sdkLibraryProperties{},
&DexImportProperties{},
+ &android.ApexProperties{},
)
android.InitDefaultsModule(module)
- android.InitApexModule(module)
return module
}