If I am not wrong gradle assemble does run gradle assembleDebug and gradle assembleRelease, but I believe gradle build also does the same, so what are the different between them both?
Assemble will build your artifacts, and build will assemble your artifacts with additional checks.
build depends on assemble, so build is sort of a superset of assemble
You can have a look on the tasks that will be executed by using the --dry-run flag. e.g.
gradlew build --dry-run
You will see that apart from assemble also lint and test will be executed.
From gradle tasks --all:
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
build is effectively assemble + check (and check is test + any linting tasks).
It's true that according to gradle tasks it looks like the build is a superset of assemble, including tests.
But(!) from my short experience it really looks like it's not the case.
So I ran those 2 commands in the command line using the gradle wrapper with --scan flag after running clean every time. This is the comparison:
- Desired built files:
- After running
assembleDebugI got all the built files i wanted -*.apkand*.aarfiles. - After running
buildDebugI didn't have any of those files.
- After running
- Amount of tasks ran according to the scans:
assembleDebug- 109 tasksbuildDebug- 91 tasks
- Amount of dependencies according to the scan:
assembleDebug- 172 from 20 configurationsbuildDebug- 104 from 18 configurations- It seems like the reason they differ is that in
assembleDebugin 2 of my 3 sub projects (which are java libraries, not app) there is one more configuration, calledlintClassPath. This configuration is missing inbuildDebug.
- Another point to mention is that when I searched in the tasks list, it seemed like
buildDebugdidn't callassembleDebugtask andassembleDebugdidn't callbuildDebugtasks. - And the last interesting thing to mention in this context is that when I ran build from the Android Studio (
Build -> Make Project), I see in my scan that the command that actually ran was theassembleDebug. More specifically, it ran:app:assembleDebug.
As you can see, I don't really understand the differences myself, but this is what I found out. If someone can explain it to me and the other users reading here, it could be awesome :) Thanks!
来源:https://stackoverflow.com/questions/44185165/what-are-the-differences-between-gradle-assemble-and-gradle-build-tasks