Loading tools/aapt2/java/ProguardRules.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -365,7 +365,7 @@ void WriteKeepSet(const KeepSet& keep_set, OutputStream* out) { for (const UsageLocation& location : entry.second) { for (const UsageLocation& location : entry.second) { printer.Print("# Referenced at ").Println(location.source.to_string()); printer.Print("# Referenced at ").Println(location.source.to_string()); } } printer.Print("-keep class ").Print(entry.first).Println(" { <init>(...); }"); printer.Print("-keep class ").Print(entry.first).Println(" { <init>(); }"); } } for (const auto& entry : keep_set.conditional_class_set_) { for (const auto& entry : keep_set.conditional_class_set_) { Loading tools/aapt2/java/ProguardRules_test.cpp +25 −0 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,31 @@ std::string GetKeepSetString(const proguard::KeepSet& set) { return out; return out; } } TEST(ProguardRulesTest, ManifestRuleDefaultConstructorOnly) { std::unique_ptr<xml::XmlResource> manifest = test::BuildXmlDom(R"( <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:backupAgent="com.foo.BarBackupAgent"> <activity android:name="com.foo.BarActivity"/> <service android:name="com.foo.BarService"/> <receiver android:name="com.foo.BarReceiver"/> <provider android:name="com.foo.BarProvider"/> </application> <instrumentation android:name="com.foo.BarInstrumentation"/> </manifest>)"); proguard::KeepSet set; ASSERT_TRUE(proguard::CollectProguardRulesForManifest(manifest.get(), &set, false)); std::string actual = GetKeepSetString(set); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarBackupAgent { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarActivity { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarService { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarReceiver { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarProvider { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarInstrumentation { <init>(); }")); } TEST(ProguardRulesTest, FragmentNameRuleIsEmitted) { TEST(ProguardRulesTest, FragmentNameRuleIsEmitted) { std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( Loading Loading
tools/aapt2/java/ProguardRules.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -365,7 +365,7 @@ void WriteKeepSet(const KeepSet& keep_set, OutputStream* out) { for (const UsageLocation& location : entry.second) { for (const UsageLocation& location : entry.second) { printer.Print("# Referenced at ").Println(location.source.to_string()); printer.Print("# Referenced at ").Println(location.source.to_string()); } } printer.Print("-keep class ").Print(entry.first).Println(" { <init>(...); }"); printer.Print("-keep class ").Print(entry.first).Println(" { <init>(); }"); } } for (const auto& entry : keep_set.conditional_class_set_) { for (const auto& entry : keep_set.conditional_class_set_) { Loading
tools/aapt2/java/ProguardRules_test.cpp +25 −0 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,31 @@ std::string GetKeepSetString(const proguard::KeepSet& set) { return out; return out; } } TEST(ProguardRulesTest, ManifestRuleDefaultConstructorOnly) { std::unique_ptr<xml::XmlResource> manifest = test::BuildXmlDom(R"( <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:backupAgent="com.foo.BarBackupAgent"> <activity android:name="com.foo.BarActivity"/> <service android:name="com.foo.BarService"/> <receiver android:name="com.foo.BarReceiver"/> <provider android:name="com.foo.BarProvider"/> </application> <instrumentation android:name="com.foo.BarInstrumentation"/> </manifest>)"); proguard::KeepSet set; ASSERT_TRUE(proguard::CollectProguardRulesForManifest(manifest.get(), &set, false)); std::string actual = GetKeepSetString(set); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarBackupAgent { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarActivity { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarService { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarReceiver { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarProvider { <init>(); }")); EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarInstrumentation { <init>(); }")); } TEST(ProguardRulesTest, FragmentNameRuleIsEmitted) { TEST(ProguardRulesTest, FragmentNameRuleIsEmitted) { std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( Loading