简体   繁体   English

Multidex Android库模块

[英]Multidex Android Library Module

I have a library module in a gradle project that has connected Android tests, but the test APK references too many methods and needs to be multidexed or ProGuard should be enabled. 我在gradle项目中有一个已连接Android测试的库模块,但测试APK引用了太多方法,需要进行多索引或应启用ProGuard。

Is there a way to enable multidex or ProGuard just for the connected Android test's application? 有没有办法为连接的Android测试应用程序启用multidex或ProGuard?

It doesn't make sense to enable ProGuard directly on a library, but if there is a way to enable it only for the androidTest configuration, that would work nicely. 直接在库上启用ProGuard是没有意义的,但如果有一种方法只能为androidTest配置启用它,那就可以很好地工作。

We do have ProGuard enabled for the application module, so it can safely depend on this library module and successfully build the app's APK. 我们确实为应用程序模块启用了ProGuard,因此它可以安全地依赖于此库模块并成功构建应用程序的APK。

It's been difficult to search for solutions to this question since I can only find information about using the Multidex support library. 由于我只能找到有关使用Multidex支持库的信息,因此很难搜索此问题的解决方案。 I understand how to enable it for a typical application. 我了解如何为典型应用程序启用它。

Is there a way to enable multidex or ProGuard just for the connected Android test's application? 有没有办法为连接的Android测试应用程序启用multidex或ProGuard?

Yes, you can enable ProGuard only for tests using a dedicated test build type. 是的,您只能为使用专用测试构建类型的测试启用ProGuard。 The default one is debug . 默认的是debug In the follow example, the dedicated test build type is named minifiedTest . 在以下示例中,专用测试构建类型名为minifiedTest

android {

    defaultConfig {

        /* Your configs here. */

        // Specify the name of the dedicated test build type.
        testBuildType 'minifiedTest'
    }

    buildTypes {
        debug {
            // Your debug configurations.
        }

        release {
            // Your release configurations.
        }

        minifiedTest {
            // Use this to get the initial configurations from another build type.
            // Some of them will be overridden from the configurations specified in this build type.
            // You can avoid to use this or you can get them from your release build type for example.
            initWith(debug)
            // Enable proguard.
            minifyEnabled true
            // Specify the proguard file.
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM