AAPT2: Embed version of framework an app was compiled against.
This change injects the 'android:compileSdkVersion' and
'android:compileSdkVersionCodename' into an app's AndroidManifest.xml,
whose values are dervied from the version name and version code of the
framework AndroidManifest.xml that is being linked against.
Bug: 63388434
Test: make aapt2_tests
Change-Id: I7b607192ecb337307c4bcb5770e7f716c6d4c9d2
diff --git a/tools/aapt2/link/ManifestFixer.h b/tools/aapt2/link/ManifestFixer.h
index 470f65e..f5715f6 100644
--- a/tools/aapt2/link/ManifestFixer.h
+++ b/tools/aapt2/link/ManifestFixer.h
@@ -29,22 +29,42 @@
namespace aapt {
struct ManifestFixerOptions {
+ // The minimum SDK version to set if no 'android:minSdkVersion' is defined in a <uses-sdk> tag.
Maybe<std::string> min_sdk_version_default;
+
+ // The target SDK version to set if no 'android:targetSdkVersion' is defined in a <uses-sdk> tag.
Maybe<std::string> target_sdk_version_default;
+
+ // The Android package to use instead of the one defined in 'package' in <manifest>.
+ // This also renames all relative package/class names in the manifest to fully qualified
+ // Java names.
Maybe<std::string> rename_manifest_package;
+
+ // The Android package to use instead of the one defined in 'android:targetPackage' in
+ // <instrumentation>.
Maybe<std::string> rename_instrumentation_target_package;
+
+ // The version name to set if 'android:versionName' is not defined in <manifest>.
Maybe<std::string> version_name_default;
+
+ // The version code to set if 'android:versionCode' is not defined in <manifest>.
Maybe<std::string> version_code_default;
+
+ // The version of the framework being compiled against to set for 'android:compileSdkVersion' in
+ // the <manifest> tag.
+ Maybe<std::string> compile_sdk_version;
+
+ // The version codename of the framework being compiled against to set for
+ // 'android:compileSdkVersionCodename' in the <manifest> tag.
+ Maybe<std::string> compile_sdk_version_codename;
};
-/**
- * Verifies that the manifest is correctly formed and inserts defaults
- * where specified with ManifestFixerOptions.
- */
+// Verifies that the manifest is correctly formed and inserts defaults where specified with
+// ManifestFixerOptions.
class ManifestFixer : public IXmlResourceConsumer {
public:
- explicit ManifestFixer(const ManifestFixerOptions& options)
- : options_(options) {}
+ explicit ManifestFixer(const ManifestFixerOptions& options) : options_(options) {
+ }
bool Consume(IAaptContext* context, xml::XmlResource* doc) override;