添加大的 png 图像后 .SO 创建导致应用程序大小增加

After adding large png images .SO created leading to increase in app size

我替换了项目中的一些 png 图像,但应用程序包未能成功构建,因为 png 文件太大,每个 2-3mb。然后我用一些 jpeg 文件更改了图像,每个文件的大小为几百 kb。在那之后,当我构建应用程序时,应用程序的大小从 9mb 变成了 27mb。我分析了 apk,大部分大小是由于一些 lib 文件

我删除了 build 文件夹以删除所有旧文件,但它没有 help.I 排除所有 .so 文件,但没有它们就无法安装 apk。我试着做一个捆绑包,但大小也是一样的。 我应该怎么做才能恢复到旧的 apk 大小。

我认为图像不是您创建的 dex 文件的问题我认为您包含了大库或许多库?

尝试设置 minifyEnabled true 以缩减 gradle 文件中的资源。

在您的应用程序模块的 build.gradle 中使用 NDK abiFilters,如下所示:

android {
 defaultConfig {
        //...
        ndk {
            abiFilters "armeabi-v7a", "x86", "armeabi"
        }
    }
}

您还可以排除不需要的特定 *.so 文件:

packagingOptions {
  exclude 'lib/arm64-v8a/lib.so'
  exclude 'lib/mips/lib.so'
}

阅读Add multi-density vector graphics

Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources. Using vector drawables instead of bitmaps reduces the size of your APK because the same file can be resized for different screen densities without loss of image quality.

您应该使用 SVG 图像而不是 JPG/PNG。

要使您的应用尽可能小,您应该在发布版本中启用收缩以删除未使用的代码和资源。启用收缩时,您还可以受益于混淆(缩短应用程序 类 和成员的名称)和优化(应用更积极的策略来进一步减小应用程序的大小)。

阅读Shrink, obfuscate, and optimize your app

  android {
    buildTypes {
        release {
            // Enables code shrinking, obfuscation, and optimization for only
            // your project's release build type.
            minifyEnabled true

            // Enables resource shrinking, which is performed by the
            // Android Gradle plugin.
            shrinkResources true

            // Includes the default ProGuard rules files that are packaged with
            // the Android Gradle plugin. To learn more, go to the section about
            // R8 configuration files.
            proguardFiles getDefaultProguardFile(
                    'proguard-android-optimize.txt'),
                    'proguard-rules.pro'
        }
    }

}