[在Android Project中使用kotlin后,APK文件大小增加

问题描述 投票:0回答:6

我已经在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" } 我该如何解决?

android android-studio kotlin android-studio-3.0
6个回答
1
投票

0
投票
在Android Studio中->构建=>分析APK。

从文件系统中选择生成的APK,然后查看哪些资源正在使APK膨胀。

enter image description here

如果还有其他疑问,请告诉我。


0
投票
这里是官方文档Here的链接

0
投票
第一步是,按住Control并单击要转换的图形,然后选择转换为WebP。然后,选择当编码结果大于原始图像时跳过图像,然后单击确定以转换图像。

删除未使用的资源

如果在应用程序的shrinkResources文件中启用build.gradle,Gradle可以代表您自动删除资源。

android { // Other settings buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }

按照这两件事来减小apk的大小。如果需要帮助,请分享您的Analyze APK屏幕截图。

希望对您有帮助。.

0
投票
您可以看到哪个文件使您的应用太大了。

enter image description here


UPDATE 1:

build.gradle(Module:app)文件中进行这些更改。它将APK大小减少近(40-50)%。

android { // Other settings buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }

0
投票

    使用您自己的组件,然后使用外部库例如您正在使用Expendable recyclerview库implementation"com.thoughtbot:expandablerecyclerview:$expandable_recycler_version"
  1. 使用除png以外的Svg可绘制对象,因为您可以在所有屏幕尺寸上使用相同的svg文件。

  2. 删除未使用的资源

  3. 最后,如果您尝试了所有这些方法,请使用ABI。尽管这样,您可以为不同的设备创建多重构建。将此粘贴到build.gradle文件的android块中>

  4. 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 } }
© www.soinside.com 2019 - 2024. All rights reserved.