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"
}
Related
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.
Just updated to Android gradle plugin version 3.3.0
We have the following setup (not sure which are important):
Application project (app) with 3 library modules (data, domain, utils)
Databinding enabled (databinding.enabled true)
Proguard enabled(proguardFiles 'proguard-rules.pro')
When I build the app using:
./gradlew assembleDevRelease
I get the following error:
can't find referenced class my.package.data.R$raw
When I build the app using:
./gradlew :app:assembleDevRelease
The app builds fine, generates an obfuscated *.apk which I can install
Question:
What's the difference between assembleRelease and :app:assembleRelease
- Why does switching to android gradle plugin 3.3.0 affect which task I have to call to build my apk? We use assembleRelease everywhere in our CI pipelines to build our apks.
What changed in android gradle plugin 3.3.0 that caused the task assembleRelease to break? We use assembleRelease everywhere in our CI pipelines to build our apks.
Any suggestions how we can make 'assembleRelease' working again? (update Proguard config?, enabling R8?)
What's the difference between assembleRelease and :app:assembleRelease
The former runs the assembleRelease task on all modules relative to current level. The latter runs it on the app module only (and its dependencies).
Why does switching to android gradle plugin 3.3.0 affect which task I have to call to build my apk? We use assembleRelease everywhere in our CI pipelines to build our apks.
The question does not have enough info to say for sure, but there are a number of changes listed in the release notes. For example, this issue might be related to:
Faster R class generation for library projects: Previously, the Android Gradle plugin would generate an R.java file for each of your project's dependencies and then compile those R classes alongside your app's other classes. The plugin now generates a JAR containing your app's compiled R class directly, without first building intermediate R.java classes. This optimization may significantly improve build performance for projects that include many library subprojects and dependencies, and improve the indexing speed in Android Studio.
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 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.