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?
Create a Signed APK FileCreate the project in Android Studio. Select Build > Signed Bundle/APK from the toolbar menu. Configure the settings for your APK file and possibly create a new key store and key.
You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With