53

In the process of trying to get my project running on Gradle I have installed and setup Gradle for my new project.

My problem is that I keep getting an error "Module X is not backed by Gradle". I've run gradle setupBuild and the files seem correct, but when running in Android Studio it won't stop the error.

Here's a screenshot of what I'm getting:

prob

So I'm wondering how to add Gradle backing to the project within Android Studio if the project is already in there.

Paul Thompson
  • 3,290
  • 2
  • 31
  • 39

2 Answers2

47

I have yet to find a good solution within Android Studio, but this has worked for me on several projects:

  1. Close the project in Android Studio (so it doesn't open the project automatically in later steps) and then close Android Studio
  2. Clean the project (delete the ".idea" and "build" folders, .iml files, etc.) so you only have the source files remaining
  3. Set up gradle by adding the appropriate settings.gradle and build.gradle files (test your setup using the command line)
  4. Open Android Studio and choose "Import project" and choose to use Gradle as the external model
  5. Pick your settings.gradle file as the Gradle project
  6. [Optional] Set your "Gradle home" folder (so the text turns black instead of gray). Earlier versions of Android Studio caused problems for me if I didn't do this. Make sure you use Gradle 0.1.10 or newer (earlier versions do not work with the current Gradle build tools).

Also, remember to use the latest version of the Gradle build tools. If you want, you can setup Gradle to use the most recent version like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}
Paul Thompson
  • 3,290
  • 2
  • 31
  • 39
sorenhk
  • 1,597
  • 15
  • 9
  • 3
    Thanks Soren. How do I accomplish #3 (Set up gradle by adding the appropriate settings.gradle and build.gradle files)? Sorry, newbie to gradle ... – Karim Varela Jul 02 '13 at 18:13
  • 3
    Karim, check out the answers to this question: http://stackoverflow.com/questions/17323858/using-gradle-with-an-existing-android-project . Also, I'd very much recommend reading the Gradle build tools user guide at http://tools.android.com/tech-docs/new-build-system/user-guide . Basically, these gradle files define the location of your source code, assets, etc. as well as the version to use of the build tools, Android SDK, and so on. "settings.gradle" is used to define your workspace (location of projects) whereas "build.gradle" defines information about each sub-project (including libraries) – sorenhk Jul 11 '13 at 16:26
  • Using android studio 2021.1.1, I had to go to File/Project Structure/Project and set the gradle version. If I didn't do that my project did not contain the gradle and gradlew.bat files. In this version, if your imported project contains a build.gradle file, you don't get the import project window, it just automatically imports the project using gradle. The ".gradle" folder will be made, but the gradle and gradlew.bat files will be missing and the easiest way to get them is via the Project Structure. – Tom Rutchik Feb 02 '22 at 22:51
9

Importing Eclipse Projects

Simpler Solution nowadays

All you need to do is "Import Project" in android studio to import eclipse projects. After that, try to "Syncronize project" and if it fails, and pops up that error u had, it should also be accompanied with an entry in "Entry log" as to what is the problem, "Cause: failed to find target android-10" for me. Once you fix that you should be able to successfully sync project and keep on going.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
Karthik T
  • 31,456
  • 5
  • 68
  • 87
  • The original question was not for eclipse project but rather for ones that were originally IntelliJ, though this does answer what i'm sure some people come to this question looking for :D – Paul Thompson Apr 11 '14 at 04:56
  • @PaulThompson Yup, I came here looking for the answer so figured others might too. I expect this process should work for intellij as well though? – Karthik T Apr 11 '14 at 05:00