使用单独的仪器测试模块时,测试应用程序的 APK 大小巨大

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

我有一个多模块应用程序,最近,我将仪器测试移至单个单独的模块。

我的设置看起来不错,因为我可以构建、运行单元测试以及仪器测试。

我刚刚注意到仪器 APK 很大(~170MB),而应用程序 APK 本身较小(~20Mb)。

检查 APK,我注意到测试应用程序中添加了很多字体 (.ttf)。

以下是我的设置:

plugins {
    alias (libs.plugins.android.test) // "com.android.test"
    alias (libs.plugins.kotlin.android)
    alias (libs.plugins.ksp)
    alias (libs.plugins.hilt.dagger)
}

android {

    targetProjectPath = ":example:app:application"

    namespace = "com.example.androidtest"

    defaultConfig.apply {
        testInstrumentationRunner = "com.example.tests.TestRunner"
    }
    ....
}

运行后:

./gradlew :example:app:application:assembleFullDebug :example:androidtest:assembleFullDebug

or

./gradlew :example:androidtest:connectedFullDebugAndroidTest

我得到两个 APK:

// Instrumentation app.. This is the problematic one
./example/app/androidtest/build/outputs/apk/full/debug/androidtest-full-debug.apk

// Actual app. Its size is normal.
./example/app/application/build/outputs/apk/full/debug/full_debug_v2.0.0.apk

有人知道这些字体是从哪里来的吗? 如果我分析实际的应用程序 APK,这些字体不存在。它们仅添加到此仪器辅助 APK 中。

android android-instrumentation
1个回答
0
投票

我发现的一个可能的解决方案是使用

/fonts
选项从 APK 中删除
packing
文件夹:

    packaging {
        resources.excludes += "/fonts/*"
    }

仅通过此更改,APK 大小就减少至 ~40Mb

© www.soinside.com 2019 - 2024. All rights reserved.