Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

android - How to add Gradle backing to existing project?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...