I currently have an Android project using gradle and integrated with travis.ci which has different productFlavors and buildTypes. When the "connectedCheck" task is then executed on travis.ci, it tries to package all build variants (all combinations of flavors and types). Some of them fail as the release builds need password input which I can't automate at the moment. Is there a way to tell travis.ci to build and test only a certain build variant of an Android project?
Say you only want to run the product flavor Trial and the build type Debug.
Instead of running ./gradlew assemble connectedCheck, which is similar to what you're doing, run this instead:
./gradlew assembleTrialDebug connectedCheckTrialDebug
So here's how I made it work:
Run a connectedAndroidTest<productFlavor><buildType> task instead of connectedCheck.
Also set the assemble task in the install section of the .travis.yml:
install: - TERM=dumb ./gradlew -s assemble<productFlavor><buildType>
Related
I am currently testing my sample app using Android instrumentation test. By default, the project creates AndroidTest folder for me. I simply just added more test cases into the folder.
I used to use expresso to trigger the UI buttons, but now I want to test use androidTest only, However, the androidTest does not seem to test my release build. I have two variants productionRelease and stageDebug in this case.
Every time I started the project by
./gradlew mysample:connectedCheck
or
./gradlew mysample:connectedAndroidTest
it tests only
Task :mysample:connectedStageDebugAndroidTest
If I want to manually start a task
./gradlew mysample:connectedProductionReleaeAndroidCheck
It complains tasks not found in mysample
* What went wrong:
Task 'connectedProductionReleaseAndroidTest' not found in project ':mysample'.
Isn't connectCheck supposed to test all the variants in my project? (StageDebug and ProductionRelease)
from task --all
mysample:connectedCheck - Runs all device checks on currently connected devices.
mysample:connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
Just tried... one can simply run ./gradlew mysample:testDebugUnitTest and ./gradlew mysample:testReleaseUnitTest - which runs the tests for either debug or release build. one can add the annotation #RequiresDevice to tests, in case eg. one requires hardware sensors.
productionRelease and stageDebug seem over-complicated (and it also not matches the rest of the naming - unless there would be productionDebug and stageRelease as well), resulting in even longer task names, would suggest to shorten...
buildTypes {
debug {}
release {}
}
Here when I run ./gradlew mysample:connectedAndroidTest I rather get a
Execution failed for task ':mysample:connectedDebugAndroidTest'.
com.android.builder.testing.api.DeviceException: No connected devices!
After closing Android Studio (and the ADB daemon it started), I can run the tests on hardware device. there only is a installDebugAndroidTest task, but no installReleaseAndroidTest task. testBuildType 'release' might run the tests against the release build - the problem is just that androidTestImplementation most likely is not contained then (quite useless).
I have more than 10 different productFlavors and whenever I change my project I have to change select build variant and then build apk for each of them.
Is there any way that build all productFlavors at the same time?
You can use gradle for it - first clean, and then assembleRelease Both you can find on right side: Gradle -> app -> Tasks -> build and then first clean, and after this assembleRelease (that should build all products flavours)
If you want to make Debug builds, then you can use assembleDebug
Running ./gradlew tasks shows options to assemble all builds for a particular flavor, or all flavors for a particular build. Does there exist an option to assemble for a specific flavor and build combination?
Yes - you're referring to a specific build variant
./gradlew assembleFlavoraBuildb
Where your flavor is called flavora and your build is buildb
Read more here:
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Building-and-Tasks
I want to export apk file "release apk" from command line
when I run this command : gradlew installRelease
and I found this
Android Studio Task 'install Release' not found in root project ''.
Some candidates are: 'uninstall Release'.
How can I solve it?
My experience has been that the installRelease task does not become available until you define the signingConfigs in the buildTypes.release block of your build file, as shown in step 3 of Signing in Release Mode. Without signingConfigs, you will get other release tasks, such as assembleRelease, but not installRelease.
So there is no such task. You can see all available tasks calling gradlew tasks. To assemble release version of apk call gradlew assembleRelease and then using adb install it.
You may build with Android Studio Build/Generate Signed APK.... In this case you'll get .apk file in your repository. You then can use adb install .apk to install it. You'll have no changes in build.gradle file in this case.
Alternatively you may change build.gradle file as mentioned here. In this case you will have installRelease task. You may get these changes in build.gradle using Open Module Settings menu. See details in Gradle for Android and Java course from Udacity.
In my case, the installRelease option didn't show up until I deleted the line
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
I've currently set my TeamCity instance to run connectedCheck on all my Android-projects. This is fine, all tests run and everything is good. Except, connectedCheck runs all tests for all product flavors. I currently have a lot of flavors, so this is wasted work for my projects as I do not really have any different code in the flavors. Any idea how I can make connectedCheck only run for one flavor?
./gradlew connected[Flavor]DebugAndroidTest
./gradlew connectedBuildVariantAndroidTest
Example:
./gradlew connectedDevelopmentDebugAndroidTest
As vida said you can run ./gradlew tasks to check all possibilities to run gradle commands.
I'd like to suggest the following:
./gradlew tasks | grep connected.
This filter all connectedAndroidTest variants that can be runned.
I see there is a new task since I checked this the last time, "connectedAndroidTestProductFalvor_buildvariant".
I haven't had time to check this task yet, but the description reads "Installs and runs the tests for build ProductFlavor_buildvariant on connected devices."
Will post a result when I've been able to test this.
and if you want to generate the apk for the android test :
./gradlew assemble[flavour]DebugAndroidTest