简体   繁体   中英

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.

Is there a way to enable multidex or ProGuard just for the connected Android test's application?

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.

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.

It's been difficult to search for solutions to this question since I can only find information about using the Multidex support library. 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?

Yes, you can enable ProGuard only for tests using a dedicated test build type. The default one is debug . In the follow example, the dedicated test build type is named 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'
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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