我已经在android studio中创建了一个Android应用程序,对于编程语言,我使用了[[Kotlin。现在我的应用程序完成了,我想构建我的应用程序,但是构建应用程序后,我的APK文件大小变为35mb!我的[[可绘制文件夹大小为2mb,但是我没有任何大文件,但是为什么我的应用程序大小为35mb?!
为了生成测试apk版本,我使用了Android Studio菜单中的Build-> Generate Signed Build / APK。但是当我使用java作为语言时,该大小为
7mb
!!!我使用了这些依赖项: 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"
}
我该如何解决?
删除未使用的资源
如果在应用程序的shrinkResources
文件中启用build.gradle
,Gradle可以代表您自动删除资源。
android {
// Other settings
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
按照这两件事来减小apk的大小。如果需要帮助,请分享您的Analyze APK
屏幕截图。
希望对您有帮助。.
implementation"com.thoughtbot:expandablerecyclerview:$expandable_recycler_version"
使用除png以外的Svg可绘制对象,因为您可以在所有屏幕尺寸上使用相同的svg文件。
删除未使用的资源
最后,如果您尝试了所有这些方法,请使用ABI
。尽管这样,您可以为不同的设备创建多重构建。将此粘贴到build.gradle文件的android
块中>
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
}
}