My app is using native library , in order to reduce apk size I used apk splitting as following
splits {
abi{
enable true
reset()
include 'x86_64','x86','armeabi-v7a','arm64-v8a'
universalApk false
}
}
Now my question is , if I generate app bundle instead of apk , do I need to keep the above snippet in my gradle file ? Or app bundle will automatically reduce the app size based on cpu architecture ?
You can get rid of this entire snippet, App Bundle is configured by default to generate APKs split by three dimensions: ABI, DPI and language.
Related
I make a App.I created its bundle to publish.This is my first time to publish a app.
I google so that i don't mess up with my first publish.i Find this
https://medium.com/#AndreSand/android-app-bundle-96ac16b36875
it say to add this code to gradle file
bundle {
language {
enableSplit = true
}
density {
enableSplit = true
}
abi {
enableSplit = true
}
}
Now I am confused should i add this code and rebuild my bundle or my simple build bundle is enough to publish app.Is there any benefit to add this code to project? I am looking for the best way to build bundles so that i don't mess up with publish.
I've published apps with App Bundles and never added such code to my Gradle files. I'd say just use the default settings unless you have a good reason to customize them.
Just do Build -> Generate Signed Bundle / APK, and select Android App Bundle.
Android app bundle upload failed with error
Invalid SplitApkBundle. The bundle targets unknown languages: [gr]
Android Studio version 3.5
I tried
Clean & rebuild
Invalidate cache/restart
I had the same issue.
Invalid SplitApkBundle. The bundle targets unknown languages:[cb]
I solved by setting DSL to stop aapt package building the wrong language targets.
My app supports English and Chinese, therefore resConfigs only needs en and zh.
defaultConfig {
...
resConfigs "en", "zh-rTW", "zh-rCN"
}
Apply this to Android{}
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
in my case i was because i was using facebook account kit see wells answer it helped me out , i am in lining it here for future references
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
I had the same issue after downgrading facebook login implimentation to 5.8 it's fixed
implementation 'com.facebook.android:facebook-login:5.8.0'
In my case, I was working with Localization and Translation also. It worked. no more code.
Put this code in app-level build.gradle.
android {
bundle {
language {
enableSplit = false
}
}
...
}
I'm facing the same issue, I guess it is related to some resources added for Facebook's Account Kit (specifically the values inside /res/values-cb/values-cb.xml) I've tried uploading a version without this SDK and the playstore proccessed it properly
Switching to Facebook sdk version 5.13.0 solved the problem for me.
implementation 'com.facebook.android:facebook-login:5.13.0'
Android app bundle upload failed with error
Invalid SplitApkBundle. The bundle targets unknown languages: [gr]
Android Studio version 3.5
I tried
Clean & rebuild
Invalidate cache/restart
I had the same issue.
Invalid SplitApkBundle. The bundle targets unknown languages:[cb]
I solved by setting DSL to stop aapt package building the wrong language targets.
My app supports English and Chinese, therefore resConfigs only needs en and zh.
defaultConfig {
...
resConfigs "en", "zh-rTW", "zh-rCN"
}
Apply this to Android{}
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
in my case i was because i was using facebook account kit see wells answer it helped me out , i am in lining it here for future references
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
I had the same issue after downgrading facebook login implimentation to 5.8 it's fixed
implementation 'com.facebook.android:facebook-login:5.8.0'
In my case, I was working with Localization and Translation also. It worked. no more code.
Put this code in app-level build.gradle.
android {
bundle {
language {
enableSplit = false
}
}
...
}
I'm facing the same issue, I guess it is related to some resources added for Facebook's Account Kit (specifically the values inside /res/values-cb/values-cb.xml) I've tried uploading a version without this SDK and the playstore proccessed it properly
Switching to Facebook sdk version 5.13.0 solved the problem for me.
implementation 'com.facebook.android:facebook-login:5.13.0'
We included this AndroidPdfViewer library to support viewing of PDF reports in the app. It lead to massive increase in APK size from 4.7Mb to 20.1Mb .
Is there a way to reduce this size. Let me know where and what to tinker around to help or solve this.
I am familiar with proguard and have it configure for my app with reasonable success.
Why resulting apk is so big?
As stated in the documentation by barteksc/AndroidPdfViewer
Android PdfViewer depends on PdfiumAndroid, which is set of native
libraries (almost 16 MB) for many architectures. Apk must contain all
this libraries to run on every device available on market.
Fortunately, Google Play allows us to upload multiple apks, e.g. one
per every architecture. There is good article on automatically
splitting your application into multiple apks, available here.
Most important section is Improving multiple APKs creation and
versionCode handling with APK Splits, but whole article is worth
reading. You only need to do this in your application, no need for
forking PdfiumAndroid or so.
API: https://github.com/barteksc/AndroidPdfViewer
You have to generate Multiple APKs for different devices, by doing this you can reduce the size of apk up to 10 MB less than previous. Add below code to build.gradle (Module:App)
android{
.....
splits {
abi {
enable true
reset()
include 'x86_64', 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips'
universalApk false
}
}
.....
}
ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, mips: 4, 'x86': 5, 'x86_64': 6]
import com.android.build.OutputFile
// For each APK output variant, override versionCode with a combination of
// ABI APK value * 1000 + defaultConfig.versionCode
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) * 1000 + android.defaultConfig.versionCode
}
}
Whatch video here https://youtu.be/bP05Vpp49hs for detail explanation on how to do it.
If anyone is looking for a lightweight pdf viewer for your app, then try this one
Use this library
It helped me to reduce the app size from 27MB to 10MB because of the barteksc-androidpdfviewer requires more space
I also faced the same problem, but this is very easy as of now to reduce the apk sizes by using android app bundles.
Firstly in build.gradle(Module: app) add these lines inside android { } brackets.
bundle {
abi {
enableSplit = true
}
}
This will handle apk splits on the basis of architecture.
Now, also remember to add this line in proguard-rules.pro
-keep class com.shockwave.**
If you will not add this line in proguard-rules.pro then your app will crash in release version.
Now, after this go to Build and then select, Generate Signed Bundle/apk. From here, generate a signed bundle. Bundles are generated in very same way, as the apk's are generated.
Then, upload your bundle(.aab file) on Google Play Console and you will see that every device gets different apks depending upon their architecture.
This is the most easiest way to reduce the app size.Multiple apk concept is more complicated.
So,I suggest you to use this way.
I want to release my apk on play store. Initially I will release it on alpha, then beta and if everything goes well I will release it on production. Can we define different api endpoint for each in buildType inside gradle. if yes then how? As I just want to change the end point of API I am calling throughout my application. Like if I release my apk on alpha the api that it points will be http://test.alpha.bla.bla
for beta: http://test.beta.bla.bla
for production: http://test.production.bla.bla.
so in this my all version of app (alpha/beta/production) will be having same version code without any need to upload new apk.
Thanks.
I assume that you mean you want 3 different build targets (and thus 3 different uploads to google play):
in your build.gradle you have the android part, in there you can define productFlavors like the following:
productFlavors{
alpha{
buildConfigField 'string', 'server','http://test.alpha.bla.bla'
}
}
But you could also make enums and refere those (instead of the type "string" you would have to specifiy the full package name + enum type , and in the last part (the value), the full package name + enum )
you can then reference the server by using (in java)
BuildConfig.server; //this would be http://test.alpha.bla.bla
I would put it in strings.xml. Each build variant can have its own copy with a different value.