Loading tools/aapt2/cmd/Link.h +5 −0 Original line number Diff line number Diff line Loading @@ -206,6 +206,11 @@ class LinkCommand : public Command { AddOptionalFlag("--compile-sdk-version-name", "Version name to inject into the AndroidManifest.xml if none is present.", &options_.manifest_fixer_options.compile_sdk_version_codename); AddOptionalSwitch( "--no-compile-sdk-metadata", "Suppresses output of compile SDK-related attributes in AndroidManifest.xml,\n" "including android:compileSdkVersion and platformBuildVersion.", &options_.manifest_fixer_options.no_compile_sdk_metadata); AddOptionalSwitch("--shared-lib", "Generates a shared Android runtime library.", &shared_lib_); AddOptionalSwitch("--static-lib", "Generate a static Android library.", &static_lib_); Loading tools/aapt2/link/ManifestFixer.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -635,7 +635,7 @@ bool ManifestFixer::Consume(IAaptContext* context, xml::XmlResource* doc) { root->InsertChild(0, std::move(uses_sdk)); } if (options_.compile_sdk_version) { if (!options_.no_compile_sdk_metadata && options_.compile_sdk_version) { xml::Attribute* attr = root->FindOrCreateAttribute(xml::kSchemaAndroid, "compileSdkVersion"); // Make sure we un-compile the value if it was set to something else. Loading @@ -647,10 +647,9 @@ bool ManifestFixer::Consume(IAaptContext* context, xml::XmlResource* doc) { // Make sure we un-compile the value if it was set to something else. attr->compiled_value = {}; attr->value = options_.compile_sdk_version.value(); } if (options_.compile_sdk_version_codename) { if (!options_.no_compile_sdk_metadata && options_.compile_sdk_version_codename) { xml::Attribute* attr = root->FindOrCreateAttribute(xml::kSchemaAndroid, "compileSdkVersionCodename"); Loading tools/aapt2/link/ManifestFixer.h +6 −2 Original line number Diff line number Diff line Loading @@ -68,11 +68,12 @@ struct ManifestFixerOptions { std::optional<std::string> revision_code_default; // The version of the framework being compiled against to set for 'android:compileSdkVersion' in // the <manifest> tag. // the <manifest> tag. Not used if no_compile_sdk_metadata is set. std::optional<std::string> compile_sdk_version; // The version codename of the framework being compiled against to set for // 'android:compileSdkVersionCodename' in the <manifest> tag. // 'android:compileSdkVersionCodename' in the <manifest> tag. Not used if no_compile_sdk_metadata // is set. std::optional<std::string> compile_sdk_version_codename; // Whether validation errors should be treated only as warnings. If this is 'true', then an Loading @@ -85,6 +86,9 @@ struct ManifestFixerOptions { // Whether to replace the manifest version with the the command line version bool replace_version = false; // Whether to suppress `android:compileSdkVersion*` and `platformBuildVersion*` attributes. bool no_compile_sdk_metadata = false; }; // Verifies that the manifest is correctly formed and inserts defaults where specified with Loading tools/aapt2/link/ManifestFixer_test.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -892,6 +892,35 @@ TEST_F(ManifestFixerTest, InsertCompileSdkVersions) { EXPECT_THAT(attr->value, StrEq("P")); } TEST_F(ManifestFixerTest, DoNotInsertCompileSdkVersions) { std::string input = R"(<manifest package="com.pkg" />)"; ManifestFixerOptions options; options.no_compile_sdk_metadata = true; options.compile_sdk_version = {"28"}; options.compile_sdk_version_codename = {"P"}; std::unique_ptr<xml::XmlResource> manifest = VerifyWithOptions(input, options); ASSERT_THAT(manifest, NotNull()); // There should be a declaration of kSchemaAndroid, even when the input // didn't have one. EXPECT_EQ(manifest->root->namespace_decls.size(), 1); EXPECT_EQ(manifest->root->namespace_decls[0].prefix, "android"); EXPECT_EQ(manifest->root->namespace_decls[0].uri, xml::kSchemaAndroid); xml::Attribute* attr = manifest->root->FindAttribute(xml::kSchemaAndroid, "compileSdkVersion"); ASSERT_THAT(attr, IsNull()); attr = manifest->root->FindAttribute(xml::kSchemaAndroid, "compileSdkVersionCodename"); ASSERT_THAT(attr, IsNull()); attr = manifest->root->FindAttribute("", "platformBuildVersionCode"); ASSERT_THAT(attr, IsNull()); attr = manifest->root->FindAttribute("", "platformBuildVersionName"); ASSERT_THAT(attr, IsNull()); } TEST_F(ManifestFixerTest, OverrideCompileSdkVersions) { std::string input = R"( <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android" Loading Loading
tools/aapt2/cmd/Link.h +5 −0 Original line number Diff line number Diff line Loading @@ -206,6 +206,11 @@ class LinkCommand : public Command { AddOptionalFlag("--compile-sdk-version-name", "Version name to inject into the AndroidManifest.xml if none is present.", &options_.manifest_fixer_options.compile_sdk_version_codename); AddOptionalSwitch( "--no-compile-sdk-metadata", "Suppresses output of compile SDK-related attributes in AndroidManifest.xml,\n" "including android:compileSdkVersion and platformBuildVersion.", &options_.manifest_fixer_options.no_compile_sdk_metadata); AddOptionalSwitch("--shared-lib", "Generates a shared Android runtime library.", &shared_lib_); AddOptionalSwitch("--static-lib", "Generate a static Android library.", &static_lib_); Loading
tools/aapt2/link/ManifestFixer.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -635,7 +635,7 @@ bool ManifestFixer::Consume(IAaptContext* context, xml::XmlResource* doc) { root->InsertChild(0, std::move(uses_sdk)); } if (options_.compile_sdk_version) { if (!options_.no_compile_sdk_metadata && options_.compile_sdk_version) { xml::Attribute* attr = root->FindOrCreateAttribute(xml::kSchemaAndroid, "compileSdkVersion"); // Make sure we un-compile the value if it was set to something else. Loading @@ -647,10 +647,9 @@ bool ManifestFixer::Consume(IAaptContext* context, xml::XmlResource* doc) { // Make sure we un-compile the value if it was set to something else. attr->compiled_value = {}; attr->value = options_.compile_sdk_version.value(); } if (options_.compile_sdk_version_codename) { if (!options_.no_compile_sdk_metadata && options_.compile_sdk_version_codename) { xml::Attribute* attr = root->FindOrCreateAttribute(xml::kSchemaAndroid, "compileSdkVersionCodename"); Loading
tools/aapt2/link/ManifestFixer.h +6 −2 Original line number Diff line number Diff line Loading @@ -68,11 +68,12 @@ struct ManifestFixerOptions { std::optional<std::string> revision_code_default; // The version of the framework being compiled against to set for 'android:compileSdkVersion' in // the <manifest> tag. // the <manifest> tag. Not used if no_compile_sdk_metadata is set. std::optional<std::string> compile_sdk_version; // The version codename of the framework being compiled against to set for // 'android:compileSdkVersionCodename' in the <manifest> tag. // 'android:compileSdkVersionCodename' in the <manifest> tag. Not used if no_compile_sdk_metadata // is set. std::optional<std::string> compile_sdk_version_codename; // Whether validation errors should be treated only as warnings. If this is 'true', then an Loading @@ -85,6 +86,9 @@ struct ManifestFixerOptions { // Whether to replace the manifest version with the the command line version bool replace_version = false; // Whether to suppress `android:compileSdkVersion*` and `platformBuildVersion*` attributes. bool no_compile_sdk_metadata = false; }; // Verifies that the manifest is correctly formed and inserts defaults where specified with Loading
tools/aapt2/link/ManifestFixer_test.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -892,6 +892,35 @@ TEST_F(ManifestFixerTest, InsertCompileSdkVersions) { EXPECT_THAT(attr->value, StrEq("P")); } TEST_F(ManifestFixerTest, DoNotInsertCompileSdkVersions) { std::string input = R"(<manifest package="com.pkg" />)"; ManifestFixerOptions options; options.no_compile_sdk_metadata = true; options.compile_sdk_version = {"28"}; options.compile_sdk_version_codename = {"P"}; std::unique_ptr<xml::XmlResource> manifest = VerifyWithOptions(input, options); ASSERT_THAT(manifest, NotNull()); // There should be a declaration of kSchemaAndroid, even when the input // didn't have one. EXPECT_EQ(manifest->root->namespace_decls.size(), 1); EXPECT_EQ(manifest->root->namespace_decls[0].prefix, "android"); EXPECT_EQ(manifest->root->namespace_decls[0].uri, xml::kSchemaAndroid); xml::Attribute* attr = manifest->root->FindAttribute(xml::kSchemaAndroid, "compileSdkVersion"); ASSERT_THAT(attr, IsNull()); attr = manifest->root->FindAttribute(xml::kSchemaAndroid, "compileSdkVersionCodename"); ASSERT_THAT(attr, IsNull()); attr = manifest->root->FindAttribute("", "platformBuildVersionCode"); ASSERT_THAT(attr, IsNull()); attr = manifest->root->FindAttribute("", "platformBuildVersionName"); ASSERT_THAT(attr, IsNull()); } TEST_F(ManifestFixerTest, OverrideCompileSdkVersions) { std::string input = R"( <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android" Loading