I've created an Android application in android studio and for programming language I used Kotlin.
Now my application finished and I want to build my app, but after building the app, my APK file size becomes 35mb !!!
My drawable folders size is 2mb and I dont have any large size files, but why my application size is 35mb ?!
For generating test apk version, I used Build -> Generate Signed Build/APK from android studio menu.
But when I use java for language this size is 7mb!!!
I used these dependencies :
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:$androidx_version"
implementation "androidx.core:core-ktx:$androidx_version"
implementation "androidx.constraintlayout:constraintlayout:$constrant_layout_version"
implementation "androidx.recyclerview:recyclerview:$material_version"
implementation "com.google.android.material:material:$material_version"
implementation "androidx.legacy:legacy-support-v4:$material_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation "junit:junit:$junit_version"
androidTestImplementation "androidx.test.ext:junit:$androidx_junit_version"
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
//Anko lib
implementation "org.jetbrains.anko:anko-commons:$anko_version"
//Rx
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
//OkHttp
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
//Gson
implementation "com.google.code.gson:gson:$gson_version"
//Image
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
//Calligraphy
implementation "io.github.inflationx:calligraphy3:$calligraphy_version"
implementation "io.github.inflationx:viewpump:$viewpump_version"
//Preferences lib
implementation "com.github.MrNouri:GoodPrefs:$nourilib_versions"
//Dynamic ui sizes
implementation "com.github.MrNouri:DynamicSizes:$nourilib_versions"
//Support MultiDex
implementation "androidx.multidex:multidex:$multidex_version"
//Animations
implementation "com.daimajia.easing:library:$yoyoanimation_version"
implementation "com.daimajia.androidanimations:library:$nineoldandroid_version"
//Map
implementation "ir.map.sdk:sdk_map:$mapir"
implementation "com.mapbox.mapboxsdk:mapbox-sdk-services:$mapbox_service"
implementation "com.mapbox.mapboxsdk:mapbox-sdk-geojson:$mapbox_service"
implementation "com.mapbox.mapboxsdk:mapbox-android-telemetry:$mapbox_telemetry"
implementation "com.mapbox.mapboxsdk:mapbox-android-gestures:$mapbox_gestures"
//Permission
implementation "ru.superjob:kotlin-permissions:$permission_version"
//Expandable recyclerview
implementation "com.thoughtbot:expandablerecyclerview:$expandable_recycler_version"
//Firebase messaging
implementation "com.google.firebase:firebase-messaging:$firebase_messaging_version"
//Firebase crashlytics
implementation "com.google.firebase:firebase-analytics:$firebase_analytics_version"
implementation "com.crashlytics.sdk.android:crashlytics:$firebase_crashlytics_version"
}
How can I fix it?
First thing you are using lots of library might be this is reason for big app size. Few thing you can to reduce app size
Use your own component other then external library
for example you are using Expendable recyclerview library
implementation"com.thoughtbot:expandablerecyclerview:$expandable_recycler_version"
Use Svg drawable other then png etc .Because you can use same svg file all screen size .
Remove unused resources
And last if you tried all of this then Use ABI
. Though this you can create multi build for different device.
Paste this in android
block in build.gradle file
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a', 'armeabi', 'mips',
'mips64'
universalApk true
}
}
project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a':
3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
android.applicationVariants.all { variant ->
variant.outputs.each { output -> output.versionCodeOverride =
project.ext.versionCodes.get(
output.getFilter(com.android.build.OutputFile.ABI), 0
) * 1000000 + android.defaultConfig.versionCode
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With