I have an android project. and it has 2 flavors whit names GooglePlay and Cafebazzar.
when using the Android Studio, I see assembleRelease and assembleCafeBazzar and assembleGooglePlay.
when I use ./gradlew -q tasks --all in jenkins, I Can't see assembleRelease in my tasks.
just I see assemble.
I use Jenkins to build the project. how can see assembleRelease in Jenkins?
+ ./gradlew -q tasks --all
------------------------------------------------------------
Tasks runnable from root project
------------------------------------------------------------
Android tasks
-------------
app:sourceSets - Prints out all the source sets defined in this project.
core:sourceSets - Prints out all the source sets defined in this project.
skeleton:sourceSets - Prints out all the source sets defined in this project.
Build tasks
-----------
app:assemble - Assembles all variants of all applications and secondary packages.
core:assemble - Assembles all variants of all applications and secondary packages.
skeleton:assemble - Assembles all variants of all applications and secondary packages.
app:assembleAndroidTest - Assembles all the Test applications.
core:assembleAndroidTest - Assembles all the Test applications.
skeleton:assembleAndroidTest - Assembles all the Test applications.
app:build - Assembles and tests this project.
core:build - Assembles and tests this project.
skeleton:build - Assembles and tests this project.
app:buildDependents - Assembles and tests this project and all projects that depend on it.
core:buildDependents - Assembles and tests this project and all projects that depend on it.
skeleton:buildDependents - Assembles and tests this project and all projects that depend on it.
app:buildNeeded - Assembles and tests this project and all projects it depends on.
core:buildNeeded - Assembles and tests this project and all projects it depends on.
skeleton:buildNeeded - Assembles and tests this project and all projects it depends on.
app:clean - Deletes the build directory.
core:clean - Deletes the build directory.
skeleton:clean - Deletes the build directory.
app:cleanBuildCache - Deletes the build cache directory.
core:cleanBuildCache - Deletes the build cache directory.
skeleton:cleanBuildCache - Deletes the build cache directory.
I have the same issue, when i check out my project "assembleRelease" is not available as a task.
When i open the project in Android Studio and select "sync with gradle" there is some activity, afterwards i can execute "gradlew assembleRelease" from the command line.
I have no idea what exactly "sync with gradle" does. It seems there was a command that did something similar once, but it seems to be no longer available.
Edit:
It seems that the file local.properties is created by running "sync with gradle files". I created a sample to reproduce the issue in googles issuetracker and it seems that this file makes the difference between assembleRelease being available or not.
Edit2:
Fastlane is now running, i copy the local.properties file into the build directory during the setup.
According to a comment on my similar question Gradle task assembleRelease not found in CI build, works with Android Studio it is because ANDROID_HOME is not set.
Related
I am trying to setup Bamboo for my Gradle build system based Android Project.
I have done the following setup on Bamboo.I'm done with rest of all setup upto project repository path.
I want to run the following tasks using gradlew for android
clean assembleDebug LintDebug
For that I have created new task called Gradle Wrapper.
Below is the Gradle Wrapper Configuration
When I am executing gradle wrapper task, I am getting the following error.
Caused by: java.lang.IllegalStateException: Cannot find executable 'D:\AndroidDemo\gradle-2.10\bin\gradlew.bat'
Note :- Standalone Gradle is working fine on local machine with all the tasks(clean assembleDebug LintDebug)
Gradle_Home = D:\AndroidDemo\gradle-2.10\bin(Local machine)
Can anyone suggest a solution for the same?
I also had some initial difficulties to set up Bamboo to build an Android project using Gradle.
First of all, make sure that you have the Gradle wrapper (gradlew) in your repo. (Seemingly that's the situation in your case). It seems to me, however the Gradle wrapper ignores the system default Gradle distribution (set by the GRADLE_HOME env var), and always downloads a Gradle version mandated by the Android Build tools.
Also make sure, that the Android SDK root environment variable (ANDROID_HOME or ANDROID_SDK_ROOT) is pointing to the SDK's root directory (e.g. $ export ANDROID_HOME="/opt/android-sdk/")[1].
Restart Bamboo after applying the environment variable changes.
In Bamboo, in the build tasks lists, add a new Script task. The interpreter should be '/bin/sh or cmd.exe', the script location should be 'inline', and the script body should contain the call for the parametrized Gradle wrapper, e.g.
gradlew clean build
Point the working subdirectory to the Gradle wrapper's relative location (to the repo root), if necessary.
[Sample Bamboo Android Gradle build script]
After these steps, Bamboo should execute the Gradle wrapper, which in fact should perform the actual build steps.
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 :)
I have been trying to run unit tests from my build.gradle file with Jenkins. If i use the command ./gradlew tasks in the terminal in android studio I am able to see the custom tasks which I have set up. However if i try to run the same command via jenkins I am not able to see them in the tasks output.
Code snippet from my build.gradle
task runDataUnitTests(dependsOn: [':data:test']) {
description 'Run unit tests for data layer.'
}
task runBusinessUnitTests(dependsOn: [':business:test']) {
description 'Run unit tests for business layer.'
}
task runPresenterUnitTests(dependsOn: [':presenter:test']) {
description 'Run unit tests for presenter layer.'
}
task runAllUnitTests(dependsOn: [runDataUnitTests, runBusinessUnitTests, runPresenterUnitTests]) << {
group = 'My tasks'
description 'Run unit tests for all layers.'
}
task testingTaskmma{
group = 'My tasks'
println 'is this task seen'
}
Android Studio Ouput
Other tasks
-----------
assembleArtifacts - Builds the project artifacts
assembleDefault
crashlyticsUploadDistributionLiveDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionLiveRelease - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingRelease - Uploads an APK to Crashlytics for distribution.
hello
jarLiveDebugClasses
jarLiveReleaseClasses
jarStagingDebugClasses
jarStagingReleaseClasses
lintVitalLiveRelease - Runs lint on just the fatal issues in the LiveRelease build.
lintVitalStagingRelease - Runs lint on just the fatal issues in the StagingRelease build.
runAllUnitTests **<<< THIS DUDE HERE**
sonarqube - Analyzes project ':msmandroidapp' and its subprojects with SonarQube.
sonarRunner - Analyzes project ':msmandroidapp' and its subprojects with Sonar Runner.
testingTaskmsma
Jenkins Output
Other tasks
-----------
assembleArtifacts - Builds the project artifacts
assembleDefault
connectedInstrumentTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedLiveTest - Installs and runs the tests for LiveDebug flavor on connected devices.
connectedStagingTest - Installs and runs the tests for StagingDebug flavor on connected devices.
crashlyticsUploadDistributionLiveDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionLiveDebugAndroidTest - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionLiveRelease - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingDebugAndroidTest - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingRelease - Uploads an APK to Crashlytics for distribution.
jarLiveDebugClasses
jarLiveReleaseClasses
jarStagingDebugClasses
jarStagingReleaseClasses
publishLive - Uploads a live-flavor specific APK to MobileAppStore
publishStaging - Uploads a staging-flavor specific APK to MobileAppStore
sonarRunner - Analyzes project ':msmandroidapp' and its subprojects with Sonar Runner.
uploadArtifacts - Builds the project artifacts and uploads them the to local maven repository.
As you can see there are other custom tasks which I have created which are also missing from the jenkins output(e.g. testingTaskmsma, hello etc. )
I have tried my Jenkins setup with using the gradle wrapper and invoke grade options (using the grade plugin for jenkins) and neither works.
The problem was an incorrect path from the Jenkins server. After I renamed a job I didn't realise that a brand new workspace was created so I was pointing to the previous workspace. Also I have found it is better to use shell commands instead of the grade plugin for Jenkins since that is how I was able to track down my problem.
I'm creating a compile-time annotation processor to generate some code on Android.
To trigger the annotation processor I'm using the android-apt plugin from hvisser https://bitbucket.org/hvisser/android-apt/overview
At the moment, on every change I do on my Processor extends AbstractProcessor I have to run a full /.gradlew clean build to see the results, and that is kinda of a slow process, even for a tiny sample project.
So my question, is there any of the gradlew tasks I could use to trigger the annotation processor?
The output from my current ./gradlew tasks is:
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Android tasks
-------------
androidDependencies - Displays the Android dependencies of the project.
signingReport - Displays the signing info for each variant.
Build tasks
-----------
assemble - Assembles the outputs of this project.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleDebugAndroidTest - Assembles the android (on device) tests for the Debug build.
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 classes 'main'.
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 classes 'test'.
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
----------
components - Displays the components produced by root project 'Decorator'. [incubating]
dependencies - Displays all dependencies declared in root project 'Decorator'.
dependencyInsight - Displays the insight into a specific dependency in root project 'Decorator'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'Decorator'.
properties - Displays the properties of root project 'Decorator'.
tasks - Displays the tasks runnable from root project 'Decorator' (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.
connectedAndroidTestDebug - Installs and runs the tests for Debug build on connected devices.
connectedCheck - Runs all device checks on currently 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 - Runs the unit tests.
testDebug - Run unit tests for the debug build.
testRelease - Run unit tests for the release build.
Other tasks
-----------
jarDebugClasses
jarReleaseClasses
Source generation happens when you compile. So running gradlew cleanCompileDebugSources compileDebugSources is what you need. This is the same was what Android Studio is running when you make your project from the build menu.
If you are developing your annotation processor as part of your project, you can use the processor option in android-apt without needing to package your processor project. This is assuming you have your processor module as a apt project(':myprocessor') dependency (compile will also work).
apt {
processor "my.class.name"
}
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>