Android Studio: Where are Gradle build tasks defined? - android-studio

I am trying to learn about how a gradle build works. When I do a build, I see a bunch of tasks executed, e.g.:
app:assembleDebug
app:preBuild
app:packageDebug
I would like to see exactly what these tasks are doing. I assume these are Gradle / Groovy scripts. I tried unzipping all the jars under Android Studio. Lots of stuff there, but I don't see anything relevant (I may have missed something in the voluminous listing). Are these tasks hidden within a class file? Am I looking in the wrong place?

All these tasks are created by the Gradle Android plugin, either the library version (com.android.library) or the application version (com.android.application). You can find the source code of these plugins in this repository.
However, it may be difficult to get insight on each task as some of them may be implemented by custom task types of the Android plugin, others may only be regular configured Gradle tasks. Also, the configuration of the tasks may be spreaded across multiple files, as many of them may be created dynamically.
But, in my opinion, it is unnecessary to know the exact functionality of each task, instead you should focus on the basic concepts of Android development and the Gradle plugin, e.g. build types and variants. The Android plugin provides a specific DSL and depending on the specified configuration, it will create the tasks automatically.

Related

What does the Android Studio delegateBuildRunToGradle do?

I'm trying to resolve some dependency issues when using an externally installed Gradle, rather than the one that come with Android Studio (AS). I then came across the particular AS setting under
File > Settings > Build,Execution,Deployment > Build Tools > Gradle > Runner.
[x] Delegate IDE build/run actions to Gradle
This is apparently also available as the Gradle config delegateBuildRunToGradle. But I can't find any sane explanation as to what it does. I thought all AS builds used Gradle...
While the Gradle doc page say it's on by default. This was not the case for my AS 3.2.2.
What does this option do?
(When should it be used?)
I was hoping to have a more precise answer, but since nothing has come forward here, I guess the only answer is that (what is written in the screenshot above) the IntelliJ IDEA has it's own way to make the builds. For many practical purposes it is probably better to have a more updated and working Gradle installation and enable the above option, to let it do its job.

Trying to make sense of Android Studio gradle build tasks between release and debug build variants

Using Android Studio 2.1.2, Gradle 2.10 and Android Gradle plugin 2.1.0, in a project and modules to build a library AAR.
I'm looking to insert my own behaviors by way of Android Studio module custom tasks. I'm in the IDE, flipping between debug and release variants and executing Build/Rebuild Project watching the Gradle console.
My questions:
I understand why "configure by convention" tasks flip between running canned "debug" versus "release" tasks, but I don't understand why the canned sequences of tasks are functionally different between the two variants. For example, when rebuilding debug, I see these core tasks executed:
...
:LibraryModule:bundleDebug
:LibraryModule:compileDebugSources
:LibraryModule:assembleDebug
...
When rebuilding release, I see these core tasks executed:
...
:LibraryModule:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:LibraryModule:compileReleaseNdk UP-TO-DATE
:LibraryModule:compileReleaseSources
...
What? Where are the bundleRelease and assembleRelease tasks? Where in the release build do I hook in my custom task (since assembleRelease or bundleRelease aren't called)?
Can I use the Android Studio "Edit Configurations..." IDE feature to setup custom build configurations to execute "Make Project (F7)" for AAR targets. And if yes, how? Specifically, what do I put in a "Gradle project:" field to target a specific module's build and what exactly, semantic and syntax wise, do I put in the "Tasks:" field?
Last question. After doing a full rebuild of a library module (to produce a .AAR file) with the build variant set to debug, I see the following task executions:
...
:LibraryModule:bundleDebug
:LibraryModule:compileDebugSources
:LibraryModule:assembleDebug
...
The order of execution doesn't seem right. I would think the order would be:
...
:LibraryModule:assembleDebug
:LibraryModule:compileDebugSources
:LibraryModule:bundleDebug
...
Am I being faked out by dependency chain output or what?

Converting android ndk build files to gradle

Is there any documentation on converting a application.mk/android.mk file to a gradle based build.gradle file?
good links, QArea. Thanks a lot!
At this moment NDK support in Gradle are very limited. If you need to assemble something that gradle not provides that function
I do like this.
I collect the old-fashioned, but to .so-patches automatically picks up the Gradle-plugin:
ndk-build -j4 NDK_LIBS_OUT=src/main/jniLibs
Otherwise, you must wait for next version of gradle 0.13. Devs promise that NDK will fix integration with NDK.
I made a script tool to convert android.mk building system to gradle building system, because I wanted to test the demo source codes in:
https://android.googlesource.com/platform/development/+/05523fb0b48280a5364908b00768ec71edb847a2/samples
But after searching whole internet, I found no one did it yet. So I created this tool by myself. But even with this tool, we couldn't ensure all projects in AndroidSamples could be built and executed successfully because of the API versions and features mismatch. So I created my own projects for https://android.googlesource.com/platform/development/+/05523fb0b48280a5364908b00768ec71edb847a2/samples
And I want to convert those demo projects one by one.
Now the whole source codes are here:
https://github.com/clockzhong/AndroidSamples
I already successfully converted some samples into gradle building system and executed them correctly on my android phones. But I still have some version mismatch issues, anyway, I'll mentioned it in the project check-in comments.

CMAKE changing Visual Studio Settings

I've been using CMAKE recently on Linux and Windows and I really like it. Its a great way of spinning up a project and organizing your builds. There are just a few things that are bugging me and I'm hoping to get help here.
Visual Studio Settings
Everytime CMAKE generates a project it will be a fresh solution and will not maintain any of the settings you applied to the Visual Studio project. I know that many things such as CMAKE_CXX_FLAGS, etc can change the properties. But what if I want to change settings such as "Suppress Startup Banner", "Environment", Enabling Microsoft Symbol Server, Enabling Native Code Debugging. How do I force CMAKE to set the options I want for fields like these?
Combining Debug/Release/Etc into one solution
It seems that with CMAKE you have to do separate generations for Debug/Release/etc. But in typical manually created Visual Studio projects you can combine the profiles and just change a project setting to get your new settings. Is it possible to generate a single solution file from CMAKE?
Okay so I scoured the CMAKE boards as well. Here are the answers I found.
Visual Studio Settings
For this one CMAKE can't modify the *.user files at all. However what was proposed was to make a user file template and then use CMAKE to supply all the paths and such that you are concerned with. This worked very well for me.
Combining Debug/Release/Etc into one solution
To change various settings on a per configuration basis. It seems like it is best to use fields like CMAKE_CXX_FLAGS_ and most importantly generator expressions. Generator expressions allow you to test for the build type and then generate whatever include, libraries, etc that you need.
Take a look at "Generator Expressions" here

Visual Studio 2012 speed big solution

Can you please advice how I can speed up a compiling, loading big solution (~50 projects).
I mean only VS 2012 studio or Windows settings, not hardware changes.
Thanks
Consider your need for 50 projects in one solution - having many projects that are referenced by each other is one of the main reasons for slowdowns.
One of the few valid reasons to have separate projects is because you need to deploy the generated assemblies separately. If this is not the case, consider combining projects - use folders for the logical separation.
The lower the number of projects, the faster your build will become.
In addition, if you change the builds to output to a specific shared directory and reference the DLLs instead of the projects, the number of unneeded re-compilations should go down drastically, though you will have to manage the build order yourself.
I use 100+ projects in a solution with Visual Studio 2012 Update 3, and it builds fast.
I agree with shared output directory comment by Oded, but I'd like to mention that project references work OK too.
Make sure that your \Users\\AppData\Local\Microsoft\WebsiteCache folder is empty. Somehow, this is a problem even with desktop-only solutions.
I have disabled Productivity Power Tools 2012, since they compile code in the background, a bit too much for my liking. Disable all plug-ins and extensions and see if it makes any difference.
Suppress excessive output messages to disk and to screen by reducing output verbosity
Use multicore with MSBuild.
As you code, try to limit dependencies between projects by using interfaces and abstract classes (C#).
Try fresh *.suo and fresh *.sdf files. (Make a backup of the user settings and DB, then remove them and try building again)
When all else fails, use ProcessMonitor or attach with another instance of Visual Studio to profile your Visual Studio while it's building.
Try excluding file system filters, such as antivirus, from your build. For example, some antiviruses have a way of skipping scanning in certain directories or by file names.

Resources