proguard gradle debug build but not the tests

后端 未结 3 1952
长情又很酷
长情又很酷 2020-12-05 15:37

I enabled proguard for the debug build using:

android {
    buildTypes {
        debug {
            runProguard true
            proguardFile \'proguard-deb         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 16:01

    Put

    gradle.projectsEvaluated {
        proguardDebugTest.enabled = false
    }
    

    it in your build script.

    There are two things to know here:

    • The general Gradle feature to enable / disable tasks.
    • The Android Gradle plugin specific deferred creation of tasks in afterEvaluate, so you need to also defer disabling of the task to afterEvaluate.

    EDIT:

    One small note: It disables the task but fails the build. This is because the :preDexDebugTest task wont run with proguard on. The best solution i've found so far is to have debug specific proguard config. More details here. Create a separate proguard config file, include the regular proguard file like so:

    -include proguard.cfg
    

    and add test config. For me it was:

    -dontwarn org.mockito.**
    -dontwarn sun.reflect.**
    -dontwarn android.test.**
    

提交回复
热议问题