Jenkins not recognising custom Gradle tasks - android

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.

Related

assembleRelease not found in task gradle in Jenkins

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.

Android : Not able to publish the Jacoco code coverage report on azure devops pipeline

I'm setting up android project on azure pipeline. Where I'm running the unit tests and after successful execution of test cases want to generate the code coverage report.
I have created task in azure-pipelines yml file for running the JacocoTestReport through the script and also mentioned the required path for generating the report.
// This for running the jacocoTestReport
- script:
./gradlew jacocoTestReport
// This for publishing the code coverage result
- task: PublishCodeCoverageResults#1
inputs:
codeCoverageTool: 'Jacoco'
summaryFileLocation:
'/Users/vsts/agent/2.153.2/work/1/s/app/build/reports/jacoco/jacocoTestReport/html/index.html'
I expect the report should be generated in html file and got published on code coverage tab of azure-pipeline but In my case I am able to generate he report in artifact folder but not able to see it on code coverage tab and I am getting below error after above task :
Reading code coverage summary from '/Users/vsts/agent/2.153.2/work/1/s/app/build/reports/jacoco/jacocoTestReport/html/index.html'
##[warning]No coverage data found. Check the build errors/warnings for more details.
Gradle JaCoCo Plugin able to produce report not only in HTML format, but also in XML.
Argument summaryFileLocation of Azure Pipelines PublishCodeCoverageResults task must point to this XML file instead of HTML.

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 :)

Android aar publish to Artifacotry through TeamCity

Currently we are using TeamCity for continuous integration and I have configured my Android library to build with TeamCity. I can upload my aar to Artifactory manualy by executing gradle assembleRelease artifactoryPublish command.
Is it possible to publish my library aar file to Artifactory repository from the TeamCity?
Assuming you already have builds running on TeamCity:
On TeamCity go to your Project Settings then Build Configurations, Select the build configuration that runs when ever TeamCity runs.
Inside that Build Configuration select Build Step: Gradle, then click the Add Build Step Button.
Select Gradle from the drop down menu.
Give it sensible name e.g. "Publish artifact"
Add your task names in:
Click Save
Then run your TeamCity build like you usually would.
TeamCity runs Gradle tasks. Just use the assembleRelease artifactoryPublish tasks in TeamCity.

How to trigger the minimal task on Gradle to run apt plugin

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"
}

Categories

Resources