I want to use firebaseAppDistribution in my project and I want to customize it fo every build type.
I have three buildType debug, staging and release. Each buildtype has a different destination group inside firebaseAppDistribution.
When I run the command to distribute the app on AppDistribute I noticed that group are always missing (but the artificat is correctly uploaded)
I think that the problem is related to how gradle work. I found a post on medium (https://medium.com/#anthony_m_cannon/android-firebase-app-distribution-for-multiple-build-types-4b50ff751ef0) that has the same problem for CI. The author solved it by using an ENV variable and run firebaseAppDistribution outside the buildType scope.
How can I solve in my local environment? Can I discrimante inside build.gradle.kts which buildType is currently running?
Gradle Version 7.6
Related
I added a new Java source folder release (app/src/release/java) for our release buildType. For this Android Studio automatically added this line to my app/build.gradle:
sourceSets { release { java.srcDirs = ['src/release/java', 'src/release/java/'] } }
We already had some code in the debug folder (app/src/debug/java) for our debug buildType. And there is no entry in the app/build.gradle file for debug source set.
And our release and debug builds are working as expected with and without the sourceSet entry.
So, is it that gradle looks for the source for build type x in app/src/x/java by default while building.
If yes, why did Android-Studio added the sourceSet line in build.gradle for me?
As far as I know you can create different "sourceSets" which basically just help you to organize code between different variants of your application. Every sourceSet except for the "main" set is optional.
You can find more in depth information about this topic on the android developer hub.
Ok, so Android Studio had added sourceSet to build.gradle cause I had marked 'Change Folder Location' while adding folder 'release' for buildType 'release'.
And by default Gradle does look for the source for build type x in app/src/x/java.
For example, for debug build type, there's no sourceSet entry in build.gradle. And on ./gradlew sourceSets it gives:
So there's no need to add sourceSet to build.gradle if you are not using custom folder structure.
I am using Jenkins for CI for my Android Project.
There I am having two build, QA and Dev.
For both some of the configurations are different like url and all which i have in my adroid project.
Now my task is to provide some variable in jenkins, and according to that variable only that apk should be built with required config only. Like if i apply for QA build, so only apk with QA config should be generated.
Is there any way to achieve this?
As far as I understand you have 2 flavors in your gradle file, QA and DEV.
If that is the case you can do that from the configuration of your Job.
In Jenkins go to your Job and then to Configurations
Go to the "Build" section and then to task.
That is a textField where you can define which flavor to compile, for example if you want QA you can define the task:
assembleQARelease
and for DEV
assembleDEVRelease
In the same way you can define if instead of Release version you want the Debug version or if you create any other flavor for your app just Change QA or DEV for this new one.
Also you can add another task before as Clean or even you can define the 3 of them
clean
assembleQARelease
assembleDEVRelease
It will clean the project then create the QA release version and then DEV release.
So ultimately I'm trying to separate my integration tests from the unit tests in an Android Studio project. I've found a few resources on the subject:
http://selimober.com/blog/2014/01/24/separate-unit-and-integration-tests-using-gradle/
https://blog.safaribooksonline.com/2013/08/22/gradle-test-organization/
Separating integration tests from unit tests in Android Studio
All these seem to indicate that the way to go is to create a new sourceSet for the integration tests, and then to create a new test task which builds and runs the tests in that source set. I can't get past the first step of creating a source set which is recognized by Android Studio.
Here's what I have within app/build.gradle, which builds without errors, but does not result in an integrationTest source root I can add classes to:
android{
...
sourceSets{
integrationTest {
java.srcDir('src/integrationTest/java')
}
}
}
My questions are:
Where precisely do I have to add the sourceSets block? In build.gradle? in app/build.gradle? In app/build.gradle inside the android block?
Once I've added my source set in he right place using the correct syntax, is this sufficient for Android Studio to detect and present it in the UI along side the main and test sources, or are there additional steps?
edit:
I've attempted to follow the instructions in marius' answer, but integrationTest isn't showing up in my build variants. Here's what I'm seeing:
This is enough:
android{
...
productFlavors{
integrationTest {
}
}
}
Regarding your 1st question: The productFlavors block should be in your app/build.gradle, inside android block.
Regarding your 2nd question: Once you add this to your build.gradle file, you also need to create your folders /src/integrationTest and /src/integrationTest/java . Once that is done, sync your gradle files and choose your new Build Variant from the Build Variant window, in order for the IDE to detect it as the active source folder.
I have a project with three different build types: debug, beta, and release. My test package is always created for debug builds, but QA uses the beta build and we want QA to run these tests on their vast array of devices.
I'm trying to create a testing apk for QA that is signed by the same key as the beta build. Looking through the Android-Gradle documentation, I don't see anything telling me that I can't do this, but I don't see anyway to configure this. Is there anyway I can configure which keystore is used when assembling a test apk? Or is there a way to create an unsigned test apk?
You can now point this to a different target, I don't know when this happened, but from the docs:
Currently only one Build Type is tested. By default it is the debug
Build Type, but this can be reconfigured with:
android {
...
testBuildType "staging"
}
This is an incomplete answer to your question in that it documents what you can't do, but the connectedAndroidTest task, which is what runs the androidTest tests in your project, is hardcoded to run against the debug build type, and I don't see a way to point it at a different build type.
Taking the advice from Is there a way to list task dependencies in Gradle? and examining the task dependency tree, if you run:
./gradlew tasks --all
you get this in your output:
Verification tasks
------------------
app:check - Runs all checks. [app:lint]
app:connectedAndroidTest - Installs and runs the tests for Build 'debug' on connected devices. [app:assembleDebug, app:assembleDebugTest]
app:connectedCheck - Runs all device checks on currently connected devices. [app:connectedAndroidTest]
app:deviceCheck - Runs all device checks using Device Providers and Test Servers.
The documentation for the connectedAndroidTest task claims it runs tests against debug, and the task dependencies (which you see with the -all flag) confirm that the task depends on assembleDebug.
Adding additional build types and flavors doesn't seem to affect the dependency on the built-in debug type.
It's possible that with greater Gradle-fu than mine, you could rewire the tasks to make the tests depend on a different build type, but doing this is likely to be fragile since it's bound to depend on things that aren't supported API in the Android Gradle plugin.
To answer your question most directly, though, if all you want is to run tests against a build with a different certificate, you could change the signing config on your debug build to use the beta certificate:
android {
signingConfigs {
beta {
keyAlias 'key'
keyPassword 'password'
storeFile file('/path/to/beta_keystore.jks')
storePassword 'password'
}
}
buildTypes {
debug {
signingConfig signingConfigs.beta
}
beta {
signingConfig signingConfigs.beta
}
}
}
I tested it and I am able to run androidTest targets against debug builds that use a custom keystore in this way. However, I doubt this solves your problem, because I suspect you want to run your tests against the beta build, not a debug build with the beta certificate.
To add a testing source set for your build variant, follow these steps:
In the Project window on the left, click the drop-down menu and
select the Project view.
Within the appropriate module folder,
right-click the src folder and click New > Directory.
For the directory name, enter "androidTestVariantName." For example,
if you have a build variant called "MyFlavor" then the directory name
shoulbe "androidTestMyFlavor." Then click OK.
Right-click on the new directory and click New > Directory. Enter
"java" as the directory name, and then click OK.
Now you can add tests to this new source set by following the steps above to add a new test. When you reach the Choose Destination Directory dialog, select the new variant test source set.
The instrumented tests in src/androidTest/ source set are shared by all build variants. When building a test APK for the "MyFlavor" variant of your app, Gradle combines both the src/androidTest/ and src/androidTestMyFlavor/ source sets.
Another way is to put following line your in default config.
Currently only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with:
android {
...
testBuildType "staging"
}
When I use the 'gradlew connectedCheck' command it always build the debug version and test against the debug version of my app. Is it also possible to test against the release version of my app?
I want to enable proguard and want to make sure that it doesn't filter anything out that is needed during runtime.
You can only test against a single build type right now (though that may change).
To set the build type to test against:
android {
testBuildType "release"
}
You could set this dynamically through a env var to not have to edit build.gradle all the time.