Merge "Use `python2.7` instead of `python2`"
diff --git a/android/androidmk.go b/android/androidmk.go
index 319f711..5ce486d 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -243,7 +243,11 @@
 	}
 
 	if host {
-		fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", amod.Os().String())
+		makeOs := amod.Os().String()
+		if amod.Os() == Linux || amod.Os() == LinuxBionic {
+			makeOs = "linux"
+		}
+		fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", makeOs)
 		fmt.Fprintln(&data.preamble, "LOCAL_IS_HOST_MODULE := true")
 	}
 
diff --git a/android/arch.go b/android/arch.go
index 05887a1..3fe0345 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -192,7 +192,7 @@
 	commonTargetMap = make(map[string]Target)
 
 	NoOsType    OsType
-	Linux       = NewOsType("linux", Host, false)
+	Linux       = NewOsType("linux_glibc", Host, false)
 	Darwin      = NewOsType("darwin", Host, false)
 	LinuxBionic = NewOsType("linux_bionic", Host, true)
 	Windows     = NewOsType("windows", HostCross, true)
@@ -242,6 +242,14 @@
 	return os.Name
 }
 
+func (os OsType) Bionic() bool {
+	return os == Android || os == LinuxBionic
+}
+
+func (os OsType) Linux() bool {
+	return os == Android || os == Linux || os == LinuxBionic
+}
+
 func NewOsType(name string, class OsClass, defDisabled bool) OsType {
 	os := OsType{
 		Name:  name,
@@ -459,6 +467,8 @@
 		"Host",
 		"Android64",
 		"Android32",
+		"Bionic",
+		"Linux",
 		"Not_windows",
 		"Arm_on_x86",
 		"Arm_on_x86_64",
@@ -468,6 +478,19 @@
 
 		for _, archType := range osArchTypeMap[os] {
 			targets = append(targets, os.Field+"_"+archType.Name)
+
+			if os == Linux { // TODO(dwillemsen): os.Linux()
+				target := "Linux_" + archType.Name
+				if !inList(target, targets) {
+					targets = append(targets, target)
+				}
+			}
+			if os.Bionic() {
+				target := "Bionic_" + archType.Name
+				if !inList(target, targets) {
+					targets = append(targets, target)
+				}
+			}
 		}
 	}
 
@@ -663,18 +686,47 @@
 			a.appendProperties(ctx, genProps, targetProp, field, prefix)
 		}
 
+		// Handle target OS generalities of the form:
+		// target: {
+		//     bionic: {
+		//         key: value,
+		//     },
+		//     bionic_x86: {
+		//         key: value,
+		//     },
+		// }
+		if os == Linux { // TODO(dwillemsen): os.Linux()
+			field = "Linux"
+			prefix = "target.linux"
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+
+			field = "Linux_" + t.Name
+			prefix = "target.linux_" + t.Name
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+		}
+
+		if os.Bionic() {
+			field = "Bionic"
+			prefix = "target.bionic"
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+
+			field = "Bionic_" + t.Name
+			prefix = "target.bionic_" + t.Name
+			a.appendProperties(ctx, genProps, targetProp, field, prefix)
+		}
+
 		// Handle target OS properties in the form:
 		// target: {
-		//     linux: {
+		//     linux_glibc: {
 		//         key: value,
 		//     },
 		//     not_windows: {
 		//         key: value,
 		//     },
-		//     linux_x86: {
+		//     linux_glibc_x86: {
 		//         key: value,
 		//     },
-		//     linux_arm: {
+		//     linux_glibc_arm: {
 		//         key: value,
 		//     },
 		//     android {
@@ -687,7 +739,6 @@
 		//         key: value,
 		//     },
 		// },
-		// },
 		field = os.Field
 		prefix = "target." + os.Name
 		a.appendProperties(ctx, genProps, targetProp, field, prefix)
diff --git a/android/paths.go b/android/paths.go
index 9c8e93a..69a7b0d 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -247,6 +247,9 @@
 // each string.
 func pathsForModuleSrcFromFullPath(ctx ModuleContext, paths []string) Paths {
 	prefix := filepath.Join(ctx.AConfig().srcDir, ctx.ModuleDir()) + "/"
+	if prefix == "./" {
+		prefix = ""
+	}
 	ret := make(Paths, 0, len(paths))
 	for _, p := range paths {
 		path := filepath.Clean(p)
@@ -714,7 +717,15 @@
 		}
 		outPaths = []string{"target", "product", ctx.AConfig().DeviceName(), partition}
 	} else {
-		outPaths = []string{"host", ctx.Os().String() + "-x86"}
+		switch ctx.Os() {
+		case Linux:
+			outPaths = []string{"host", "linux-x86"}
+		case LinuxBionic:
+			// TODO: should this be a separate top level, or shared with linux-x86?
+			outPaths = []string{"host", "linux_bionic-x86"}
+		default:
+			outPaths = []string{"host", ctx.Os().String() + "-x86"}
+		}
 	}
 	if ctx.Debug() {
 		outPaths = append([]string{"debug"}, outPaths...)
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index 469e960..6797312 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -107,7 +107,7 @@
 			"LOCAL_RENDERSCRIPT_INCLUDES": "renderscript.include_dirs",
 			"LOCAL_RENDERSCRIPT_FLAGS":    "renderscript.flags",
 
-			"LOCAL_JAVA_RESOURCE_DIRS":    "resource_dirs",
+			"LOCAL_JAVA_RESOURCE_DIRS":    "java_resource_dirs",
 			"LOCAL_JAVACFLAGS":            "javacflags",
 			"LOCAL_DX_FLAGS":              "dxflags",
 			"LOCAL_JAVA_LIBRARIES":        "libs",
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 2db9d86..eb63065 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -155,7 +155,11 @@
 			}
 
 			if host {
-				fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", ctx.Target().Os.String())
+				makeOs := ctx.Target().Os.String()
+				if ctx.Target().Os == android.Linux || ctx.Target().Os == android.LinuxBionic {
+					makeOs = "linux"
+				}
+				fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
 				fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
 			} else if ctx.vndk() {
 				fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index 65fa1ed..3f079a4 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -89,6 +89,7 @@
 		"10.10",
 		"10.11",
 		"10.12",
+		"10.13",
 	}
 
 	darwinAvailableLibraries = append(
@@ -99,7 +100,6 @@
 			"ncurses",
 			"objc",
 			"pthread",
-			"z",
 		}, "-l"),
 		"-framework AppKit",
 		"-framework CoreFoundation",
diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go
index 80e9289..75416bd 100644
--- a/cc/config/x86_linux_host.go
+++ b/cc/config/x86_linux_host.go
@@ -123,7 +123,6 @@
 		"resolv",
 		"rt",
 		"util",
-		"z",
 	}, "-l")
 )
 
diff --git a/cc/linker.go b/cc/linker.go
index 2a6c909..02d3ba5 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -211,11 +211,12 @@
 			flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
 
 			if !ctx.Windows() {
-				// Add -ldl, -lpthread and -lrt to host builds to match the default behavior of device
+				// Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of device
 				// builds
 				flags.LdFlags = append(flags.LdFlags,
 					"-ldl",
 					"-lpthread",
+					"-lm",
 				)
 				if !ctx.Darwin() {
 					flags.LdFlags = append(flags.LdFlags, "-lrt")
diff --git a/cc/makevars.go b/cc/makevars.go
index 8bdcf9f..2c6af70 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -259,6 +259,10 @@
 		ctx.Strict(makePrefix+"NDK_TRIPLE", toolchain.ClangTriple())
 	}
 
+	if target.Os.Class == android.Host || target.Os.Class == android.HostCross {
+		ctx.Strict(makePrefix+"AVAILABLE_LIBRARIES", strings.Join(toolchain.AvailableLibraries(), " "))
+	}
+
 	ctx.Strict(makePrefix+"TOOLCHAIN_ROOT", toolchain.GccRoot())
 	ctx.Strict(makePrefix+"TOOLS_PREFIX", gccCmd(toolchain, ""))
 	ctx.Strict(makePrefix+"SHLIB_SUFFIX", toolchain.ShlibSuffix())
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 7e43373..090d490 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -330,7 +330,6 @@
 		if ctx.Host() {
 			// -nodefaultlibs (provided with libc++) prevents the driver from linking
 			// libraries needed with -fsanitize=address. http://b/18650275 (WAI)
-			flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
 			flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed")
 		} else {
 			flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0")
@@ -387,10 +386,6 @@
 		if ctx.Host() {
 			flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all")
 			flags.LdFlags = append(flags.LdFlags, sanitizeArg)
-			if ctx.Os() == android.Linux {
-				flags.LdFlags = append(flags.LdFlags, "-lrt")
-			}
-			flags.LdFlags = append(flags.LdFlags, "-ldl")
 			// Host sanitizers only link symbols in the final executable, so
 			// there will always be undefined symbols in intermediate libraries.
 			_, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags)
diff --git a/cc/stl.go b/cc/stl.go
index a123d77..17cde59 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -134,7 +134,6 @@
 		if !ctx.toolchain().Bionic() {
 			flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
 			flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
-			flags.LdFlags = append(flags.LdFlags, "-lpthread", "-lm")
 			if ctx.staticBinary() {
 				flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
 			} else {
diff --git a/cc/test.go b/cc/test.go
index fddbe4a..12cc2ad 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -145,10 +145,8 @@
 			flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
 		case android.Linux:
 			flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX")
-			flags.LdFlags = append(flags.LdFlags, "-lpthread")
 		case android.Darwin:
 			flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC")
-			flags.LdFlags = append(flags.LdFlags, "-lpthread")
 		}
 	} else {
 		flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID")
diff --git a/jar/jar.go b/jar/jar.go
index f17bc98..08fa1ab 100644
--- a/jar/jar.go
+++ b/jar/jar.go
@@ -94,6 +94,8 @@
 		Method:             zip.Store,
 		UncompressedSize64: uint64(len(b)),
 	}
+	fh.SetMode(0700)
+	fh.SetModTime(DefaultTime)
 
 	return fh, b, nil
 }
diff --git a/java/app.go b/java/app.go
index 80d62fd..e40478a 100644
--- a/java/app.go
+++ b/java/app.go
@@ -53,8 +53,8 @@
 	Asset_dirs []string
 
 	// list of directories relative to the Blueprints file containing
-	// Java resources
-	Android_resource_dirs []string
+	// Android resources
+	Resource_dirs []string
 }
 
 type AndroidApp struct {
@@ -183,7 +183,7 @@
 	}
 
 	assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.appProperties.Asset_dirs, "assets")
-	resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.appProperties.Android_resource_dirs, "res")
+	resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.appProperties.Resource_dirs, "res")
 
 	var overlayResourceDirs android.Paths
 	// For every resource directory, check if there is an overlay directory with the same path.
diff --git a/java/builder.go b/java/builder.go
index b8332ad..95345d4 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -129,14 +129,6 @@
 	javaVersion   string
 }
 
-type jarSpec struct {
-	fileList, dir android.Path
-}
-
-func (j jarSpec) soongJarArgs() string {
-	return "-C " + j.dir.String() + " -l " + j.fileList.String()
-}
-
 func TransformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists android.Paths,
 	flags javaBuilderFlags, deps android.Paths) android.ModuleOutPath {
 
@@ -206,18 +198,11 @@
 	return classFileList
 }
 
-func TransformResourcesToJar(ctx android.ModuleContext, resources []jarSpec,
+func TransformResourcesToJar(ctx android.ModuleContext, jarArgs []string,
 	deps android.Paths) android.Path {
 
 	outputFile := android.PathForModuleOut(ctx, "res.jar")
 
-	jarArgs := []string{}
-
-	for _, j := range resources {
-		deps = append(deps, j.fileList)
-		jarArgs = append(jarArgs, j.soongJarArgs())
-	}
-
 	ctx.ModuleBuild(pctx, android.ModuleBuildParams{
 		Rule:        jar,
 		Description: "jar",
diff --git a/java/config/config.go b/java/config/config.go
index 3029a5a..4f74ef2 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -26,7 +26,8 @@
 var (
 	pctx = android.NewPackageContext("android/soong/java/config")
 
-	DefaultLibraries = []string{"core-oj", "core-libart", "ext", "framework", "okhttp"}
+	DefaultBootclasspathLibraries = []string{"core-oj", "core-libart"}
+	DefaultLibraries              = []string{"ext", "framework", "okhttp"}
 )
 
 func init() {
diff --git a/java/config/makevars.go b/java/config/makevars.go
index eda6c09..937d597 100644
--- a/java/config/makevars.go
+++ b/java/config/makevars.go
@@ -26,6 +26,7 @@
 
 func makeVarsProvider(ctx android.MakeVarsContext) {
 	ctx.Strict("TARGET_DEFAULT_JAVA_LIBRARIES", strings.Join(DefaultLibraries, " "))
+	ctx.Strict("TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES", strings.Join(DefaultBootclasspathLibraries, " "))
 
 	ctx.Strict("DEFAULT_JAVA_LANGUAGE_VERSION", "${DefaultJavaVersion}")
 
diff --git a/java/java.go b/java/java.go
index 43f97ac..805e06a 100644
--- a/java/java.go
+++ b/java/java.go
@@ -70,10 +70,16 @@
 	Exclude_srcs []string `android:"arch_variant"`
 
 	// list of directories containing Java resources
-	Resource_dirs []string `android:"arch_variant"`
+	Java_resource_dirs []string `android:"arch_variant"`
 
-	// list of directories that should be excluded from resource_dirs
-	Exclude_resource_dirs []string `android:"arch_variant"`
+	// list of directories that should be excluded from java_resource_dirs
+	Exclude_java_resource_dirs []string `android:"arch_variant"`
+
+	// list of files to use as Java resources
+	Java_resources []string `android:"arch_variant"`
+
+	// list of files that should be excluded from java_resources
+	Exclude_java_resources []string `android:"arch_variant"`
 
 	// don't build against the default libraries (legacy-test, core-junit,
 	// ext, and framework for device targets)
@@ -100,6 +106,9 @@
 	// If set to false, don't allow this module to be installed.  Defaults to true.
 	Installable *bool
 
+	// If set to true, include sources used to compile the module in to the final jar
+	Include_srcs *bool
+
 	// List of modules to use as annotation processors
 	Annotation_processors []string
 
@@ -227,13 +236,7 @@
 		}
 	}
 
-	if ctx.AConfig().UnbundledBuild() {
-		if v == "" {
-			if ctx, ok := ctx.(android.ModuleContext); ok {
-				ctx.AddMissingDependencies([]string{"sdk_version_must_be_set_for_modules_used_in_unbundled_builds"})
-			}
-			return sdkDep{}
-		}
+	if ctx.AConfig().UnbundledBuild() && v != "" {
 		return toFile(v)
 	}
 
@@ -258,7 +261,7 @@
 		if ctx.Device() {
 			sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version)
 			if sdkDep.useDefaultLibs {
-				ctx.AddDependency(ctx.Module(), bootClasspathTag, "core-oj", "core-libart")
+				ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
 				ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
 			}
 			if sdkDep.useModule {
@@ -266,7 +269,7 @@
 			}
 		} else {
 			if j.deviceProperties.Dex {
-				ctx.AddDependency(ctx.Module(), bootClasspathTag, "core-oj", "core-libart")
+				ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
 			}
 		}
 	}
@@ -275,6 +278,7 @@
 	ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
 
 	android.ExtractSourcesDeps(ctx, j.properties.Srcs)
+	android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
 }
 
 func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
@@ -377,8 +381,6 @@
 		flags.javaVersion = "${config.DefaultJavaVersion}"
 	}
 
-	var extraDeps android.Paths
-
 	flags.bootClasspath.AddPaths(deps.bootClasspath)
 	flags.classpath.AddPaths(deps.classpath)
 
@@ -405,35 +407,50 @@
 
 	deps.srcFileLists = append(deps.srcFileLists, j.ExtraSrcLists...)
 
-	var extraJarDeps android.Paths
-
 	var jars android.Paths
 
 	if len(srcFiles) > 0 {
-		// Compile java sources into .class files
-		classes := TransformJavaToClasses(ctx, srcFiles, deps.srcFileLists, flags, extraDeps)
-		if ctx.Failed() {
-			return
-		}
-
+		var extraJarDeps android.Paths
 		if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") {
 			// If error-prone is enabled, add an additional rule to compile the java files into
 			// a separate set of classes (so that they don't overwrite the normal ones and require
-			// a rebuild when error-prone is turned off).  Add the classes as a dependency to
-			// the jar command so the two compiles can run in parallel.
+			// a rebuild when error-prone is turned off).
 			// TODO(ccross): Once we always compile with javac9 we may be able to conditionally
 			//    enable error-prone without affecting the output class files.
-			errorprone := RunErrorProne(ctx, srcFiles, deps.srcFileLists, flags, extraDeps)
+			errorprone := RunErrorProne(ctx, srcFiles, deps.srcFileLists, flags, nil)
 			extraJarDeps = append(extraJarDeps, errorprone)
 		}
 
+		// Compile java sources into .class files
+		classes := TransformJavaToClasses(ctx, srcFiles, deps.srcFileLists, flags, extraJarDeps)
+		if ctx.Failed() {
+			return
+		}
+
 		jars = append(jars, classes)
 	}
 
-	resourceJarSpecs := ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs, j.properties.Exclude_resource_dirs)
-	if len(resourceJarSpecs) > 0 {
+	dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
+	fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
+
+	var resArgs []string
+	var resDeps android.Paths
+
+	resArgs = append(resArgs, dirArgs...)
+	resDeps = append(resDeps, dirDeps...)
+
+	resArgs = append(resArgs, fileArgs...)
+	resDeps = append(resDeps, fileDeps...)
+
+	if proptools.Bool(j.properties.Include_srcs) {
+		srcArgs, srcDeps := ResourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
+		resArgs = append(resArgs, srcArgs...)
+		resDeps = append(resDeps, srcDeps...)
+	}
+
+	if len(resArgs) > 0 {
 		// Combine classes + resources into classes-full-debug.jar
-		resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, extraJarDeps)
+		resourceJar := TransformResourcesToJar(ctx, resArgs, resDeps)
 		if ctx.Failed() {
 			return
 		}
@@ -452,12 +469,12 @@
 	manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
 
 	// Combine the classes built from sources, any manifests, and any static libraries into
-	// classes-combined.jar.  If there is only one input jar this step will be skipped.
+	// classes.jar.  If there is only one input jar this step will be skipped.
 	outputFile := TransformJarsToJar(ctx, "classes.jar", jars, manifest, false)
 
 	if j.properties.Jarjar_rules != nil {
 		jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
-		// Transform classes-combined.jar into classes-jarjar.jar
+		// Transform classes.jar into classes-jarjar.jar
 		outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
 		if ctx.Failed() {
 			return
@@ -467,7 +484,7 @@
 	j.classpathFile = outputFile
 
 	// TODO(ccross): handle hostdex
-	if ctx.Device() && len(srcFiles) > 0 {
+	if ctx.Device() && len(srcFiles) > 0 && j.installable() {
 		dxFlags := j.deviceProperties.Dxflags
 		if false /* emma enabled */ {
 			// If you instrument class files that have local variable debug information in
@@ -520,10 +537,6 @@
 			return
 		}
 
-		// TODO(ccross): For now, use the desugared jar as the classpath file.  Eventually this
-		// might cause problems because desugar wants non-desugared jars in its class path.
-		j.classpathFile = desugarJar
-
 		// Compile classes.jar into classes.dex
 		dexJarFile := TransformClassesJarToDexJar(ctx, desugarJar, flags)
 		if ctx.Failed() {
@@ -541,6 +554,10 @@
 	j.outputFile = outputFile
 }
 
+func (j *Module) installable() bool {
+	return j.properties.Installable == nil || *j.properties.Installable
+}
+
 var _ Dependency = (*Library)(nil)
 
 func (j *Module) ClasspathFiles() android.Paths {
@@ -572,7 +589,7 @@
 func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
 	j.compile(ctx)
 
-	if j.properties.Installable == nil || *j.properties.Installable == true {
+	if j.installable() {
 		j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
 			ctx.ModuleName()+".jar", j.outputFile)
 	}
diff --git a/java/java_test.go b/java/java_test.go
index 7159e3f..7154f5e 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -16,6 +16,7 @@
 
 import (
 	"android/soong/android"
+	"android/soong/genrule"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -59,6 +60,7 @@
 	ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory))
 	ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory))
 	ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
+	ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(genrule.FileGroupFactory))
 	ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
 	ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
 	ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
@@ -92,6 +94,8 @@
 		"c.java":     nil,
 		"a.jar":      nil,
 		"b.jar":      nil,
+		"res/a":      nil,
+		"res/b":      nil,
 		"prebuilts/sdk/14/android.jar":    nil,
 		"prebuilts/sdk/14/framework.aidl": nil,
 	})
@@ -111,7 +115,7 @@
 	case strings.HasSuffix(name, ".jar"):
 		return name
 	default:
-		return filepath.Join(buildDir, ".intermediates", name, "android_common", "classes-desugar.jar")
+		return filepath.Join(buildDir, ".intermediates", name, "android_common", "classes-compiled.jar")
 	}
 }
 
@@ -142,8 +146,8 @@
 		t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
 	}
 
-	bar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "classes-desugar.jar")
-	baz := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "classes-desugar.jar")
+	bar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "classes-compiled.jar")
+	baz := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "classes-compiled.jar")
 
 	if !strings.Contains(javac.Args["classpath"], bar) {
 		t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
@@ -349,17 +353,87 @@
 		t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
 	}
 
-	bar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "classes-desugar.jar")
+	bar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "classes-compiled.jar")
 	if !strings.Contains(javac.Args["classpath"], bar) {
 		t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
 	}
 
-	baz := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "classes-desugar.jar")
+	baz := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "classes-compiled.jar")
 	if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
 		t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
 	}
 }
 
+func TestResources(t *testing.T) {
+	var table = []struct {
+		name  string
+		prop  string
+		extra string
+		args  string
+	}{
+		{
+			// Test that a module with java_resource_dirs includes a file list file
+			name: "resource dirs",
+			prop: `java_resource_dirs: ["res"]`,
+			args: "-C res -l ",
+		},
+		{
+			// Test that a module with java_resources includes the files
+			name: "resource files",
+			prop: `java_resources: ["res/a", "res/b"]`,
+			args: "-C . -f res/a -C . -f res/b",
+		},
+		{
+			// Test that a module with a filegroup in java_resources includes the files with the
+			// path prefix
+			name: "resource filegroup",
+			prop: `java_resources: [":foo-res"]`,
+			extra: `
+				filegroup {
+					name: "foo-res",
+					path: "res",
+					srcs: ["res/a", "res/b"],
+				}`,
+			args: "-C res -f res/a -C res -f res/b",
+		},
+		{
+			// Test that a module with "include_srcs: true" includes its source files in the resources jar
+			name: "include sources",
+			prop: `include_srcs: true`,
+			args: "-C . -f a.java -C . -f b.java -C . -f c.java",
+		},
+	}
+
+	for _, test := range table {
+		t.Run(test.name, func(t *testing.T) {
+			ctx := testJava(t, `
+				java_library {
+					name: "foo",
+					srcs: [
+						"a.java",
+						"b.java",
+						"c.java",
+					],
+					`+test.prop+`,
+				}
+			`+test.extra)
+
+			foo := ctx.ModuleForTests("foo", "android_common").Output("classes.jar")
+			fooRes := ctx.ModuleForTests("foo", "android_common").Output("res.jar")
+
+			if !inList(fooRes.Output.String(), foo.Inputs.Strings()) {
+				t.Errorf("foo combined jars %v does not contain %q",
+					foo.Inputs.Strings(), fooRes.Output.String())
+			}
+
+			if !strings.Contains(fooRes.Args["jarArgs"], test.args) {
+				t.Errorf("foo resource jar args %q does not contain %q",
+					fooRes.Args["jarArgs"], test.args)
+			}
+		})
+	}
+}
+
 func fail(t *testing.T, errs []error) {
 	if len(errs) > 0 {
 		for _, err := range errs {
diff --git a/java/resources.go b/java/resources.go
index 60dc934..9f5e5e0 100644
--- a/java/resources.go
+++ b/java/resources.go
@@ -15,7 +15,9 @@
 package java
 
 import (
+	"fmt"
 	"path/filepath"
+	"strings"
 
 	"github.com/google/blueprint/bootstrap"
 
@@ -40,7 +42,8 @@
 	return false
 }
 
-func ResourceDirsToJarSpecs(ctx android.ModuleContext, resourceDirs, excludeDirs []string) []jarSpec {
+func ResourceDirsToJarArgs(ctx android.ModuleContext,
+	resourceDirs, excludeDirs []string) (args []string, deps android.Paths) {
 	var excludes []string
 
 	for _, exclude := range excludeDirs {
@@ -49,8 +52,6 @@
 
 	excludes = append(excludes, resourceExcludes...)
 
-	var jarSpecs []jarSpec
-
 	for _, resourceDir := range resourceDirs {
 		if isStringInSlice(resourceDir, excludeDirs) {
 			continue
@@ -63,9 +64,29 @@
 
 			pattern := filepath.Join(dir.String(), "**/*")
 			bootstrap.GlobFile(ctx, pattern, excludes, fileListFile.String(), depFile)
-			jarSpecs = append(jarSpecs, jarSpec{fileListFile, dir})
+			args = append(args,
+				"-C", dir.String(),
+				"-l", fileListFile.String())
+			deps = append(deps, fileListFile)
 		}
 	}
 
-	return jarSpecs
+	return args, deps
+}
+
+func ResourceFilesToJarArgs(ctx android.ModuleContext,
+	res, exclude []string) (args []string, deps android.Paths) {
+	files := ctx.ExpandSources(res, exclude)
+
+	for _, f := range files {
+		rel := f.Rel()
+		path := f.String()
+		if !strings.HasSuffix(path, rel) {
+			panic(fmt.Errorf("path %q does not end with %q", path, rel))
+		}
+		path = filepath.Clean(strings.TrimSuffix(path, rel))
+		args = append(args, "-C", filepath.Clean(path), "-f", f.String())
+	}
+
+	return args, files
 }
diff --git a/root.bp b/root.bp
index f27d28b..6788fa7 100644
--- a/root.bp
+++ b/root.bp
@@ -37,6 +37,7 @@
     "test/vts",
     "test/vts-testcase/*",
     "tools/*",
+    "tools/tradefederation/*",
     "toolchain/*",
     "vendor/*/*",
 ]