{"_id":"5851441f025add2500add159","category":{"_id":"55781fe35129590d003ff4fc","pages":["55781fe45129590d003ff50d","55781fe45129590d003ff50e","55781fe45129590d003ff50f","55781fe45129590d003ff510","55781fe45129590d003ff511","55781fe45129590d003ff512","55781fe45129590d003ff513","55781fe45129590d003ff514","55781fe45129590d003ff515","55781fe45129590d003ff516","55f692b4fe4cce21005c78b0","55f7e91e60cc850d008a7a45","56333cab9c607719001b85e4","564462ed9ce94c0d00068ce9","564f54fa48a1df1700836653","565ee9e7413e06170093dde0","5661a8fdb401c70d00dde6fa","5671348860c8e70d006c96a1","568ce9707d3bf02300aa7734"],"version":"55781fe25129590d003ff4f7","__v":10,"project":"54aa7f773b56130b0056c86e","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-01-05T12:44:00.338Z","from_sync":false,"order":4,"slug":"android-sdk","title":"Android SDK"},"githubsync":"","parentDoc":null,"user":"57bc3654b9c7f0220009c77b","__v":0,"project":"54aa7f773b56130b0056c86e","version":{"_id":"55781fe25129590d003ff4f7","project":"54aa7f773b56130b0056c86e","forked_from":"54aa7f773b56130b0056c871","__v":8,"createdAt":"2015-06-10T11:30:42.700Z","releaseDate":"2015-06-10T11:30:42.700Z","categories":["55781fe35129590d003ff4f8","55781fe35129590d003ff4f9","55781fe35129590d003ff4fa","55781fe35129590d003ff4fb","55781fe35129590d003ff4fc","55781fe35129590d003ff4fd","55781fe35129590d003ff4fe","564bbc7e8841060d00abb2ee","565b66c446118c0d00dcb0bb","56898269f8dc340d00308c13","582318b23b961a0f009516a1","594a848c9f4771001a43c959","5c73dd27e8fdc000572a206a","5c77ac5af94a920045cb80ca"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Developers","version_clean":"2.0.0","version":"2.0"},"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-14T13:07:43.160Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":27,"body":"[block:api-header]\n{\n  \"title\": \"Android App Bundle\"\n}\n[/block]\nIf you publish your app to Google Play, you should build and upload an Android App Bundle. When you do so, Google Play automatically generates and serves optimized APKs for each user’s device configuration, so they download only the code and resources they need to run your app. Publishing multiple APKs is useful if you are not publishing to Google Play, but you must build, sign, and manage each APK yourself. For more info read - https://developer.android.com/guide/app-bundle/\n[block:api-header]\n{\n  \"title\": \"Proguard\"\n}\n[/block]\nBy using Proguard Developers can shrink, obfuscate, and optimize their apps. To enable proguard just add \"*minifyEnabled true*\" in your build config.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"buildTypes {\\n\\trelease {\\n\\t\\tminifyEnabled true\\n    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\\n  }\\n  debug {\\n    minifyEnabled false\\n    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\\n  }\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nAs of version 2.13.6 the PulsateSDK imports with Proguard settings, turning on Proguard will automatically run the PulsateSDK settings.\n[block:api-header]\n{\n  \"title\": \"APK Splitting\"\n}\n[/block]\nIf you can't use Android App Bundles you can manually split your APK into multiple APKs and upload them to Google Play. Google Play makes sure that the user gets the APK that is for his device.\nAll you need to do is add the following block of code to your app gradle file under android.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"splits {\\n    abi {\\n        enable true\\n        reset()\\n        include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'\\n        universalApk false\\n    }\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nWhen releasing an app Android Studio will now build multiple APKs (one for every architecture). This will reduce the size of your app, but you will need to now manage multiple different APKs. For more info read - https://developer.android.com/google/play/publishing/multiple-apks.html\n[block:api-header]\n{\n  \"title\": \"ABI filters\"\n}\n[/block]\nInstead of building multiple APKs you can create a single APK with just the architectures that you need. This APK will be larger than the APKs we get from using APK Splitting, but we have only one APK to manage. ABI filters allow us to filter certain kind of architecture(s) that we want to include into single APK file.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"buildTypes {\\n    release {\\n        ndk {\\n            abiFilters \\\"arm64-v8a\\\", \\\"armeabi-v7a\\\"\\n        }\\n    }\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nBy removing unnecessary architectures we can generate a single APK file that is much smaller (notice that there are not many devices that support x86 architecture for Android, but the libraries for this architecture are the biggest ones). \n[block:api-header]\n{\n  \"title\": \"Other\"\n}\n[/block]\nFor more ways to reduce App Size please read:\n1. https://developer.android.com/studio/build/shrink-code\n2. https://developer.android.com/topic/performance/reduce-apk-size\n3. https://developer.android.com/google/play/publishing/multiple-apks.html\n4. https://developer.android.com/guide/app-bundle/","excerpt":"","slug":"reducing-apk-size","type":"basic","title":"Reducing APK size"}
[block:api-header] { "title": "Android App Bundle" } [/block] If you publish your app to Google Play, you should build and upload an Android App Bundle. When you do so, Google Play automatically generates and serves optimized APKs for each user’s device configuration, so they download only the code and resources they need to run your app. Publishing multiple APKs is useful if you are not publishing to Google Play, but you must build, sign, and manage each APK yourself. For more info read - https://developer.android.com/guide/app-bundle/ [block:api-header] { "title": "Proguard" } [/block] By using Proguard Developers can shrink, obfuscate, and optimize their apps. To enable proguard just add "*minifyEnabled true*" in your build config. [block:code] { "codes": [ { "code": "buildTypes {\n\trelease {\n\t\tminifyEnabled true\n proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n }\n debug {\n minifyEnabled false\n proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n }\n}", "language": "text" } ] } [/block] As of version 2.13.6 the PulsateSDK imports with Proguard settings, turning on Proguard will automatically run the PulsateSDK settings. [block:api-header] { "title": "APK Splitting" } [/block] If you can't use Android App Bundles you can manually split your APK into multiple APKs and upload them to Google Play. Google Play makes sure that the user gets the APK that is for his device. All you need to do is add the following block of code to your app gradle file under android. [block:code] { "codes": [ { "code": "splits {\n abi {\n enable true\n reset()\n include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'\n universalApk false\n }\n}", "language": "text" } ] } [/block] When releasing an app Android Studio will now build multiple APKs (one for every architecture). This will reduce the size of your app, but you will need to now manage multiple different APKs. For more info read - https://developer.android.com/google/play/publishing/multiple-apks.html [block:api-header] { "title": "ABI filters" } [/block] Instead of building multiple APKs you can create a single APK with just the architectures that you need. This APK will be larger than the APKs we get from using APK Splitting, but we have only one APK to manage. ABI filters allow us to filter certain kind of architecture(s) that we want to include into single APK file. [block:code] { "codes": [ { "code": "buildTypes {\n release {\n ndk {\n abiFilters \"arm64-v8a\", \"armeabi-v7a\"\n }\n }\n}", "language": "text" } ] } [/block] By removing unnecessary architectures we can generate a single APK file that is much smaller (notice that there are not many devices that support x86 architecture for Android, but the libraries for this architecture are the biggest ones). [block:api-header] { "title": "Other" } [/block] For more ways to reduce App Size please read: 1. https://developer.android.com/studio/build/shrink-code 2. https://developer.android.com/topic/performance/reduce-apk-size 3. https://developer.android.com/google/play/publishing/multiple-apks.html 4. https://developer.android.com/guide/app-bundle/