skip to Main Content

I have a simple multi-module Gradle project with Java code. When I import it in IntelliJ Community, it asks me to select the build tool from among Maven and Gradle, and will properly recognize the Gradle modules and show me a Gradle tool window.

When I do the same in Android Studio, I don’t get the build tool question, and it won’t recognize the projects or show me the Gradle tool window.

How do I get this to work in Android Studio?

5

Answers


  1. Chosen as BEST ANSWER

    The answer, as far as I've been able to find out, is: Don't even try. Use IntelliJ instead. Installing it is most certainly quicker than trying to get Android Studio to do this.


  2. I suspect that you will have to manually move some code from the successful build files in intellij to the android build files.

    Login or Signup to reply.
  3. Simply Try This,

    Go to File -> Project Structure -> Sdk Location

    This You will get a option menu like this (the given image)

    there you can update your gradle settings.

    enter image description here

    Login or Signup to reply.
  4. How do you open the project in Intellij? Do you open the folder? Or do you open the build.gradle?

    Just like a maven project (where you should open the pom.xml, not the folder) you should open the project using the build.gradle, not the folder.

    Intellij will then do what you expect and import your gradle project

    Login or Signup to reply.
  5. The least required to make it recognize the project is to add AGP, the Android Gradle Plugin:

    buildscript {
        repositories {
            google()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:7.0.2"
        }
    }
    

    Then one can define Android modules with:

    • apply plugin: "com.android.application"
    • apply plugin: "com.android.library"
    • apply plugin: "com.android.dynamic-feature"

    Then it will recognize the android {} configuration block (without this Gradle DSL configuration block it would not know what or how to build for Android – as it isn’t a sane Android project). Just see the documentation linked, this has little to do with the default Java tooling.

    Gradle 7.2 is currently required to build. Even if one cannot mix the plugins per module, one can have different plugins per module – or use different IDE, depending on the tooling of the module. How compatible this really is, is being determined by the dependencies used in the Java module. The fact that one can only use either tooling per single module dictates the layout to be applied.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search