gradle – Java source directories for Android Studio project flavors not rendered in blue-ThrowExceptions

Exception or error:

I have an Android Gradle project and I want to create two flavor branches. I’m use the default sourceSets with this structure:

src
  - main
    - java
      - package   
    - res
    - manifest.xml

  - flavor1
    - java
      - package

  - flavor2
    - java
      - package

“main/java”, “flavor1/java” is rendered/annotated as Java source in the IDE (i.e., “java” is in blue, and the directories are shown as packages), but “flavor2” is not rendered the same way.

I tried to clear the caches and restart Android Studio but this did not help. How can I fix this?

How to solve:

Your main directory (content root) sources will always be blue colored by default, but others depend on the activeness.

The blue color directory shows that the build variant or content root is active and if you will use the Run button of IDE, it will take these sources to compile and build you app. Only one content root can be active at a time for building the app.

You can change and make any directory/flavor active for your content root to compile and build your app when run option is used. It can be done from Build Variants tab available in left panel of your Android Studio.

Like shown in picture below :

Production is active here:

prodmark

uat is active here:

uatmark

###

Based on user pyus13 ‘s answer I found that by going to build variants and simply selecting flavor2release in your case, the folder becomes blue.

So by clicking the release version of the flavor you want to make active the folder becomes blue.

Hope this helps. Thanks pyus13!

Leave a Reply

Your email address will not be published. Required fields are marked *