{"id":498,"date":"2018-02-12T20:39:58","date_gmt":"2018-02-13T01:39:58","guid":{"rendered":"http:\/\/jebware.com\/blog\/?p=498"},"modified":"2018-02-12T20:39:58","modified_gmt":"2018-02-13T01:39:58","slug":"feeding-proguards-inputs-where-are-all-of-these-rules-coming-from","status":"publish","type":"post","link":"https:\/\/jebware.com\/blog\/?p=498","title":{"rendered":"Feeding ProGuard\u2019s inputs: where are all of these rules coming from?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">When ProGuard runs on your Android app, it\u2019s not only using the rules that you\u2019ve explicitly added, but rules from a couple of other sources as well.\u00a0 Below are four sources to watch out for:<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Rules explicitly added by the developer<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">These are the rules in a file that you add with `proguardFile` in your build.gradle. \u00a0If you\u2019ve used ProGuard at all, you\u2019re probably accustomed to adding configuration rules here.<\/span><\/p>\n<figure id=\"attachment_502\" aria-describedby=\"caption-attachment-502\" style=\"width: 612px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/gradle-include-rules.png\"><img loading=\"lazy\" class=\"wp-image-502 size-full\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/gradle-include-rules.png\" alt=\"\" width=\"612\" height=\"64\" \/><\/a><figcaption id=\"caption-attachment-502\" class=\"wp-caption-text\">build.gradle snippet showing the proguardFiles method<\/figcaption><\/figure>\n<h3><span style=\"font-weight: 400;\">Default ProGuard file<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">A base set of widely-applicable rules get added by that &#8220;getDefaultProguardFile&#8221; line above, which you\u2019ll see in the template build.gradle file. \u00a0It protects things like Parcelables, view getters and setters (to enable animations on view properties) and anything with the @Keep annotation. \u00a0You should walk through this file to see what ProGuard rules get added by default. \u00a0It\u2019s also a great source of example rules when you\u2019re trying to make your own.<\/span><\/p>\n<figure id=\"attachment_501\" aria-describedby=\"caption-attachment-501\" style=\"width: 609px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/default-android.png\"><img loading=\"lazy\" class=\"wp-image-501 size-full\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/default-android.png\" alt=\"\" width=\"609\" height=\"157\" \/><\/a><figcaption id=\"caption-attachment-501\" class=\"wp-caption-text\">snippet of example rules from the default Android ProGuard file<\/figcaption><\/figure>\n<h3><span style=\"font-weight: 400;\">AAPT generated rules<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">When AAPT processes the resources in your app, it generates rules to protect, for example, View classes that are referenced from layout files, and Activities referenced in your manifest. Each rule comes with one or more comments saying where the class was referenced, so you can track down the offending resource if need be. \u00a0You can find these rules in:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">build\/intermediates\/proguard-rules\/{buildType}\/aapt_rules.txt.<\/span><\/pre>\n<figure id=\"attachment_507\" aria-describedby=\"caption-attachment-507\" style=\"width: 896px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/aapt-rules-redacted.png\"><img loading=\"lazy\" class=\"wp-image-507 size-full\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/aapt-rules-redacted.png\" alt=\"snippet of example ProGuard rules generated by AAPT\" width=\"896\" height=\"99\" \/><\/a><figcaption id=\"caption-attachment-507\" class=\"wp-caption-text\">snippet of example ProGuard rules generated by AAPT<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Note that this source isn\u2019t explicitly added in your build.gradle, the Android Gradle Plugin takes care of including these rules for you.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Rules from libraries<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">If an Android library has ProGuard configs that apps should use when they include that library, the library can declare those rules with the consumerProguardFile method in its build.gradle. \u00a0For example, here\u2019s a snippet from <a href=\"https:\/\/github.com\/JakeWharton\/butterknife\/blob\/master\/butterknife\/build.gradle#L9\">Butterknife&#8217;s build.gradle.<\/a><\/span><\/p>\n<figure id=\"attachment_499\" aria-describedby=\"caption-attachment-499\" style=\"width: 574px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/butterknife-consumer.png\"><img loading=\"lazy\" class=\"wp-image-499 size-full\" src=\"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/butterknife-consumer.png\" alt=\"\" width=\"574\" height=\"112\" \/><\/a><figcaption id=\"caption-attachment-499\" class=\"wp-caption-text\">snippet of Butterknife&#8217;s build.gradle showing the consumerProguardFiles method<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<h1><span style=\"font-weight: 400;\">Bringing it all together<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">Rather than trying to track down every single source of ProGuard config that\u2019s getting added to your app, you can look at them all together. \u00a0You can specify<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">-printconfiguration proguard-config.txt<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">in your rules file and ProGuard will print out all of the configuration rules to the specified file. \u00a0Note that they\u2019re not in the same order that they were originally specified, so it can be hard to figure out where a particular rule is coming from. \u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When ProGuard runs on your Android app, it\u2019s not only using the rules that you\u2019ve explicitly added, but rules from a couple of other sources as well.\u00a0 Below are four sources to watch out for: Rules explicitly added by the developer These are the rules in a file that you add with `proguardFile` in your &hellip; <a href=\"https:\/\/jebware.com\/blog\/?p=498\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Feeding ProGuard\u2019s inputs: where are all of these rules coming from?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"twitterCardType":"summary_large_image","cardImageID":0,"cardImage":"http:\/\/jebware.com\/blog\/wp-content\/uploads\/2018\/02\/butterknife-consumer.png","cardTitle":"","cardDesc":"","cardImageAlt":"","cardPlayer":"","cardPlayerWidth":0,"cardPlayerHeight":0,"cardPlayerStream":"","cardPlayerCodec":""},"categories":[4,16],"tags":[],"_links":{"self":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/498"}],"collection":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=498"}],"version-history":[{"count":5,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/498\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/498\/revisions\/508"}],"wp:attachment":[{"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jebware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}