Reputation: 465
I know, with the Gradle command assembleAndroidTest
I can build a test APK.
But I can use this test APK only for debug builds of my app, right? If I use it with a release build, I get error messages like "[SDR.handleImages] Unable to find test for com.xxx.xxx (packagename)"
How can I build a test APK in release mode with Gradle?
Upvotes: 25
Views: 9928
Reputation: 65
You can also try
if (project.hasProperty('androidTestRelease')) {
testBuildType 'release'
}else {
testBuildType 'debug'
}
and to run tests in release build just add
-PandroidTest
to your command
Upvotes: 1
Reputation: 5338
Add this line to your defaultConfig
.
android {
defaultConfig {
...
testBuildType System.getProperty('testBuildType', 'debug')
}
}
Now you can run below command to get the release version of test apk
./gradlew assembleAndroidTest -DtestBuildType=release
Upvotes: 12
Reputation: 2502
To build a release test apk from gradle first you need to add followin test config in your build.gradle file:
android {
..
..
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-test-rules.pro'
signingConfig signingConfigs.release
}
}
testBuildType "release"
}
After this you will start to see the assembleReleaseAndroidTest
command. Through which you can run tests on release build.
In the process you may also need to create a proguard-test-rules.pro
file, for test proguard rules
Upvotes: 9