10

I have mutiple modules in my android project. if i make a release apk with :app:assembleRelease it works but when i make a release apk with assembleRelease it keep showing error. I know there's error in my code but this is not what i am questioning about. I just want to know what is the difference between assembleRelease and :app:assembleRelease

zihadrizkyef
  • 1,849
  • 3
  • 23
  • 46

2 Answers2

11

In Multi module Gradle project, if you don't refer to your module explicitly then Gradle by default try to find that task from root project's Tasks graph.

For example: If you're having multiple modules named as module1 & module2, then on evaluation phase Gradle distributes each module's tasks in their own extensions. Meaning you must now refer it as :module1:task1 & :module2:task2

This is the reason why assembleRelease doesn't work & :app:assembleRelease works.


You can check tasks graph by opening 'Gradle' window in Android Studio/IntelliJ IDEA.

If you look at the image below you can see Tasks node which have common tasks available at root project.

While there are other module related tasks can be found inside expanding it's own node.

Gradle Task Graph

Note that: In android you can have multiple modules but your default module is always abbreviated as app module while others are considered as library module which are abbreviated by name of that individual module like base, db, domain etc. from image above (You can't have multiple app module in same project I guess).

Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58
5

The difference between :app:assembleRelease and assembleRelease is that assembleRelease executes the assembleRelease task of each module while :app:assembleRelease executes the assembleRelease task in the app module.

Obviously the task graph is populated correctly for both, it means that :app:assembleRelease for Android depends on the assembleRelease of the other modules used as dependencies in :app.

Giorgio Antonioli
  • 15,771
  • 10
  • 45
  • 70
  • is it okay if i make an android apk for playstore with `:app:assembleRelease` instead of `assembleRelease`? – zihadrizkyef Apr 03 '20 at 06:24
  • 1
    @zihadrizkyef If the APK you are upload on Play Store is the APK of the module `app` and you aren't manually manipulating the task graph, yes. – Giorgio Antonioli Apr 03 '20 at 07:41