简体   繁体   中英

Testing the release app in android with the test apk not being `proguarded`

I want to test the release apk in android which has proguard enabled. But I dont want the android test apk to be proguard enabled.

Is there some way to disable proguarding the android test apk.

I added this

defaultConfig { 
   ....
   testBuildType 'release'`
  }

and

    buildTypes {
        release {
            minifyEnabled true
            signingConfig signingConfigs.Release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            //proguard files for the android test apk
            testProguardFile('proguard-test-rules.pro')
        }
}

Looking for a method which disable the proguard for the android test.

Got it to working as follows.

android {

    defaultConfig {

        /**
         * switch to testBuildType release when the parameter has androidTestRelease
         * ./gradlew :app:assembleReleaseAndroidTest -PandroidTestRelease
         **/
        if (project.hasProperty('androidTestRelease')) {
            testBuildType 'release'
        } else {
            testBuildType 'debug'
        }
    }


    buildTypes {
        release {

            /***
             * Disable proguard when building the android test release apk
             * ./gradlew :app:assembleReleaseAndroidTest -PandroidTestRelease
             */
            if (project.hasProperty('androidTestRelease')) {
                minifyEnabled false
            } else {
                minifyEnabled true
            }

            signingConfig signingConfigs.Release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testCoverageEnabled = true
        }
    }

}

You can build the apk using

./gradlew :app:assembleReleaseAndroidTest -PandroidTestRelease

it's (probably) useless to disable ProGuard ...better create a debuggable package:

staging {

    signingConfig signingConfigs.Release
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    testCoverageEnabled true
    minifyEnabled false
    zipAlignEnabled true
    shrinkResources true
    pseudoLocalesEnabled false
    renderscriptDebuggable true
    jniDebuggable true
    debuggable true
}

while it's not even certain, that one can have tests for release builds (by design).

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