How to build multiple APKs at once using Gradle? - android

I got a big project with several flavors in it. How can I generate all the APKS at once from all my flavors?

./gradlew assemble will compile all flavors in different build types (debug, release)
./gradlew assembleDebug
./gradlew assembleRelease
these guys above will compile either debug or release versions of all flavors

Related

Build All productFlavors Automatically in same time

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

How to build all product flavors from Android Studio?

I have many flavors in gradle file :
def _versionName = "1.19"
def _applicationId = "com.site.app"
productFlavors {
CafebazarPro {
applicationId "${_applicationId}"
versionName "${_versionName}" +"-Cafebazar-Pro"
}
CafebazarInPurchase {
applicationId "${_applicationId}.inpurchase"
versionName "${_versionName}" +"-Cafebazar-InPurchase"
}
//-------------------------------------------
Cando {
applicationId ${_applicationId}"
versionName "${_versionName}" +"-Cando-Pro"
}
//-------------------------------------------
Myket {
applicationId "${_applicationId}"
versionName "${_versionName}" +"-Myket-Pro"
}
//-----------------------------------------
IranApps {
applicationId "${_applicationId}"
versionName "${_versionName}" +"-IranApps-Pro"
}
}
How to build automatically all flavors ? not select and build one by one .
Open Cmd and run this command :
gradlew tasks
Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleRelease - Assembles all Release builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
compileDebugAndroidTestSources
compileDebugSources
compileDebugUnitTestSources
compileReleaseSources
compileReleaseUnitTestSources
jar - Assembles a jar archive containing the main classes.
mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.
testClasses - Assembles test classes.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'src'.
components - Displays the components produced by root project 'src'. [incubating]
dependencies - Displays all dependencies declared in root project 'src'.
dependencyInsight - Displays the insight into a specific dependency in root project 'src'.
help - Displays a help message.
model - Displays the configuration model of root project 'src'. [incubating]
projects - Displays the sub-projects of root project 'src'.
properties - Displays the properties of root project 'src'.
tasks - Displays the tasks runnable from root project 'src' (some of the displayed tasks may belong to subprojects).
Install tasks
-------------
installDebug - Installs the Debug build.
installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build.
uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
uninstallRelease - Uninstalls the Release build.
Verification tasks
------------------
check - Runs all checks.
connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
lint - Runs lint on all variants.
lintDebug - Runs lint on the Debug build.
lintRelease - Runs lint on the Release build.
test - Run unit tests for all variants.
testDebugUnitTest - Run unit tests for the debug build.
testReleaseUnitTest - Run unit tests for the release build.
Other tasks
-----------
clean
jarDebugClasses
jarReleaseClasses
transformResourcesWithMergeJavaResForDebugUnitTest
transformResourcesWithMergeJavaResForReleaseUnitTest
gradlew assemble - Assembles all variants of all applications and
secondary packages.
The question states that if it is possible to build all flavors using android studio. So this might help someone in the future.
Use the Gradle option either from the right side toolbar or from
View -> Tool Windows -> Gradle (if gradle is not visible on the toolbar)
Then navigate to Your Project -> Tasks ->build click on the desired option as mentioned below to initiate there respective builds
assemble: assemble both the debug and release versions of all flavors (Takes a lot of time)
assembleAndroidTest: assemble all android unit test
assembleChocolate: assemble both debug and release version of Chocolate flavor
assembleDebug: assemble only the debug version of all flavors (I use this when I do changes which affects all flavors, to make sure all of them build)
assembleRelease: assemble only the release version of all flavors.
assembleStrawberry: assemble both debug and release version of Strawberry flavor
assembleVanila: assemble both debug and release version of Vanilla flavor
kudos :)

Gradle assemble specific flavor and build

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

Android build variants on travis.ci

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>

Gradle: How to Build different flavours of different built types?

Could someone tell me if it's possible to build only one of my different flavors through the command-line?
At the moment I haven't seen the way to execute, for example:
gradle buildDev
when Dev is one of my different flavors. Indeed, I have to execute:
gradle build
And all flavors are build.
I'd like to skip some flavors.
is it possible?
Thanks
While there is no flavor-specific version of the build task, there are flavor-specific versions of the assemble and install tasks. assemble will create the APK; install will install it on devices/emulators.
For example, in this sample project, I define two product flavors (chocolate and vanilla) and three total build types (debug, release, and mezzanine).
Running gradle tasks shows, among others:
Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleChocolate - Assembles all builds for flavor Chocolate
assembleChocolateDebug - Assembles the Debug build for flavor Chocolate
assembleChocolateDebugTest - Assembles the Test build for the ChocolateDebug build
assembleChocolateMezzanine - Assembles the Mezzanine build for flavor Chocolate
assembleChocolateRelease - Assembles the Release build for flavor Chocolate
assembleDebug - Assembles all Debug builds
assembleMezzanine - Assembles all Mezzanine builds
assembleRelease - Assembles all Release builds
assembleTest - Assembles all the Test applications
assembleVanilla - Assembles all builds for flavor Vanilla
assembleVanillaDebug - Assembles the Debug build for flavor Vanilla
assembleVanillaDebugTest - Assembles the Test build for the VanillaDebug build
assembleVanillaMezzanine - Assembles the Mezzanine build for flavor Vanilla
assembleVanillaRelease - Assembles the Release build for flavor Vanilla
Install tasks
-------------
installChocolateDebug - Installs the Debug build for flavor Chocolate
installChocolateDebugTest - Installs the Test build for the ChocolateDebug build
installChocolateMezzanine - Installs the Mezzanine build for flavor Chocolate
installChocolateRelease - Installs the Release build for flavor Chocolate
installVanillaDebug - Installs the Debug build for flavor Vanilla
installVanillaDebugTest - Installs the Test build for the VanillaDebug build
installVanillaMezzanine - Installs the Mezzanine build for flavor Vanilla
installVanillaRelease - Installs the Release build for flavor Vanilla
uninstallAll - Uninstall all applications.
uninstallChocolateDebug - Uninstalls the Debug build for flavor Chocolate
uninstallChocolateDebugTest - Uninstalls the Test build for the ChocolateDebug build
uninstallChocolateMezzanine - Uninstalls the Mezzanine build for flavor Chocolate
uninstallChocolateRelease - Uninstalls the Release build for flavor Chocolate
uninstallVanillaDebug - Uninstalls the Debug build for flavor Vanilla
uninstallVanillaDebugTest - Uninstalls the Test build for the VanillaDebug build
uninstallVanillaMezzanine - Uninstalls the Mezzanine build for flavor Vanilla
uninstallVanillaRelease - Uninstalls the Release build for flavor Vanilla
I would simplify the answer given by #CommonsWare because going through the answer i was litte confused.
Consider these are the product flavours
Dev
Preprod
Prod
Run
gradlew task
This will list out all Product flavours along with there build types
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleDEV - Assembles all DEV builds.
assemblePREPROD - Assembles all PREPROD builds.
assemblePROD - Assembles all PROD builds.
assembleRelease - Assembles all Release builds.
From this you can easily choose the flavours and will generate a build based on that
gradlew assemblePREPROD
If your productFlavor is chocolate you can do
./gradlew assembleChocolateRelease
or
./gradlew assembleChocolateDebug
To add to the above answers, if you want to build an Android Bundle (AAB) then you can use this
# build flavor 'flavorName' only
./gradlew bundleFlavorName

Categories

Resources