{"id":3140,"date":"2017-06-01T13:59:13","date_gmt":"2017-06-01T08:29:13","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=3140"},"modified":"2017-06-01T13:59:13","modified_gmt":"2017-06-01T08:29:13","slug":"using-proguard-in-android-application","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/","title":{"rendered":"Using Proguard in Android Application"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Proguard is an optimizer for java bytecode. It detects and removes unused code from app and included libraries, also optimizes the bytecode. Proguard obfuscate code makes difficult to reverse engineer.<\/p>\n<p>Proguard is a valuable tool for working around the 64k reference limit. Resource shrinking also works well in conjunction with code shrinking.<\/p>\n<p>To enable code shrinking add minifyEnabled true to the release build type in build.gradle file.<\/p>\n<pre class=\"lang:java decode:true\">android\r\n{\r\n\tbuildTypes\r\n\t{\r\n\t\trelease\r\n\t\t{\r\n\t\t\tminifyEnabled true\r\n\t\t\tproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r\n\t\t}\r\n\t}\r\n...\r\n}<\/pre>\n<p>Add custom proguard rules in proguard-rules.pro i.e. next to build.gradle file. Following common lines used in proguard-rules.pro file:-<\/p>\n<p>To keeping source file and line number to view crash logs in crashlytics (Fabrics or Firebase)<\/p>\n<pre class=\"lang:java decode:true\">-keepattributes SourceFile,LineNumberTable<\/pre>\n<p>Rename attributes to make it difficult for reverse engineering the file and package name.<\/p>\n<pre class=\"lang:java decode:true\">-renamesourcefileattribute ANYNAME<\/pre>\n<p>For Jackson library add following lines:-<br \/>\n<code><\/code><\/p>\n<pre class=\"lang:java decode:true\">-dontwarn com.fasterxml.jackson.databind.**\r\n-keepnames class com.fasterxml.jackson.** { *; }\r\n-keep class com.fasterxml.jackson.databind.ObjectMapper {\r\npublic ;\r\nprotected ;\r\n}\r\n-keep class com.fasterxml.jackson.databind.ObjectWriter {\r\npublic ** writeValueAsString(**);\r\n}<\/pre>\n<p>Also remove network model classes and methods from obfuscation as these class and method names are used by Jackson library for JSON parsing<br \/>\n<code><\/code><\/p>\n<pre class=\"lang:java decode:true\">-keepclassmembers class PACKAGE_NAME.responsemodel.* {\r\nprivate ;\r\n}\r\n-keepclassmembers class PACKAGE_NAME.requestmodel.* {\r\nprivate ;\r\n}\r\n-keep public class PACKAGE_NAME.responsemodel.* {\r\npublic void set*(***);\r\npublic *** get*();\r\n}\r\n-keep public class PACKAGE_NAME.requestmodel.* {\r\npublic void set*(***);\r\npublic *** get*();\r\n}<\/pre>\n<p>For Facebook Library<br \/>\n<code><\/code><\/p>\n<pre class=\"lang:java decode:true\">-keep class com.facebook.** { *; }\r\n-keepattributes Signature<\/pre>\n<p>Similarly for other libraries\/sdk, we can check documentation for proguard setting and add these in our proguard-rules.pro file.<\/p>\n<p><strong>Decode obfuscated stack trace:<\/strong> Proguard creates a mapping.txt in the app \/build\/outputs\/mapping\/release\/ directory. This mapping file is required to convert obfuscated stack trace to readable format. On Windows we can use retrace.bat for conversion to readable format (retrace.sh on Mac\/Linux).<\/p>\n<pre class=\"lang:java decode:true\">retrace.bat -verbose mapping.txt obfuscated_trace.txt<\/pre>\n<p>It is important to keep this mapping.txt file whenever we release build on play store. Firebase crash reporting also use this file to convert obfuscated stack trace into readable text.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Proguard is an optimizer for java bytecode. It detects and removes unused code from app and included libraries, also optimizes the bytecode. Proguard obfuscate code makes difficult to reverse engineer. Proguard is a valuable tool for working around the 64k reference limit. Resource shrinking also works well in conjunction with code shrinking. To enable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3150,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71],"tags":[],"class_list":["post-3140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using Proguard in Android Application | InnovationM Blog<\/title>\n<meta name=\"description\" content=\"Proguard is a tool to help minify, obfuscate, and optimize your code. It reduces the size of the Android app as well as removes unused codes from the app.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Proguard in Android Application | InnovationM Blog\" \/>\n<meta property=\"og:description\" content=\"Proguard is a tool to help minify, obfuscate, and optimize your code. It reduces the size of the Android app as well as removes unused codes from the app.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-01T08:29:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/05\/proguard.png\" \/>\n\t<meta property=\"og:image:width\" content=\"624\" \/>\n\t<meta property=\"og:image:height\" content=\"347\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Using Proguard in Android Application\",\"datePublished\":\"2017-06-01T08:29:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/\"},\"wordCount\":258,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/proguard.png\",\"articleSection\":[\"Mobile\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/\",\"name\":\"Using Proguard in Android Application | InnovationM Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/proguard.png\",\"datePublished\":\"2017-06-01T08:29:13+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"description\":\"Proguard is a tool to help minify, obfuscate, and optimize your code. It reduces the size of the Android app as well as removes unused codes from the app.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/proguard.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/05\\\/proguard.png\",\"width\":624,\"height\":347},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/using-proguard-in-android-application\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Proguard in Android Application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Proguard in Android Application | InnovationM Blog","description":"Proguard is a tool to help minify, obfuscate, and optimize your code. It reduces the size of the Android app as well as removes unused codes from the app.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/","og_locale":"en_US","og_type":"article","og_title":"Using Proguard in Android Application | InnovationM Blog","og_description":"Proguard is a tool to help minify, obfuscate, and optimize your code. It reduces the size of the Android app as well as removes unused codes from the app.","og_url":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/","og_site_name":"InnovationM - Blog","article_published_time":"2017-06-01T08:29:13+00:00","og_image":[{"width":624,"height":347,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/05\/proguard.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Using Proguard in Android Application","datePublished":"2017-06-01T08:29:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/"},"wordCount":258,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/05\/proguard.png","articleSection":["Mobile"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/","url":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/","name":"Using Proguard in Android Application | InnovationM Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/05\/proguard.png","datePublished":"2017-06-01T08:29:13+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"description":"Proguard is a tool to help minify, obfuscate, and optimize your code. It reduces the size of the Android app as well as removes unused codes from the app.","breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/05\/proguard.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2017\/05\/proguard.png","width":624,"height":347},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/using-proguard-in-android-application\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using Proguard in Android Application"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/3140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=3140"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/3140\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/3150"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=3140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=3140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=3140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}