In the process of trying to get my project running on Gradle I have installed and setup Gradle for my new project.
在尝试让我的项目在Gradle上运行的过程中,我已经为我的新项目安装并设置了Gradle。
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.
我的问题是我一直收到错误“模块X没有Gradle支持”。我已经运行gradle setupBuild并且文件似乎正确,但在Android Studio中运行时它不会停止错误。
Here's a screenshot of what I'm getting:
这是我得到的截图:
So I'm wondering how to add Gradle backing to the project within Android Studio if the project is already in there.
所以我想知道如果项目已经在那里,如何在Android Studio中为项目添加Gradle支持。
2 个解决方案
#1
44
I have yet to find a good solution within Android Studio, but this has worked for me on several projects:
我还没有在Android Studio中找到一个好的解决方案,但这对我有好几个项目:
- Close the project in Android Studio (so it doesn't open the project automatically in later steps) and then close Android Studio
- 在Android Studio中关闭项目(因此它不会在后续步骤中自动打开项目),然后关闭Android Studio
- Clean the project (delete the ".idea" and "build" folders, .iml files, etc.) so you only have the source files remaining
- 清理项目(删除“.idea”和“build”文件夹,.iml文件等),这样您只剩下源文件
- Set up gradle by adding the appropriate settings.gradle and build.gradle files (test your setup using the command line)
- 通过添加适当的settings.gradle和build.gradle文件来设置gradle(使用命令行测试您的设置)
- Open Android Studio and choose "Import project" and choose to use Gradle as the external model
- 打开Android Studio并选择“导入项目”,然后选择使用Gradle作为外部模型
- Pick your settings.gradle file as the Gradle project
- 选择您的settings.gradle文件作为Gradle项目
- [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).
- [可选]设置“Gradle home”文件夹(使文本变为黑色而不是灰色)。如果我没有这样做,早期版本的Android Studio会给我带来麻烦。确保使用Gradle 0.1.10或更高版本(早期版本不适用于当前的Gradle构建工具)。
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:
另外,请记住使用最新版本的Gradle构建工具。如果需要,可以将Gradle设置为使用最新版本,如下所示:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
#2
8
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.
你需要做的就是在android studio中“导入项目”来导入eclipse项目。在那之后,尝试“Syncronize project”,如果它失败了,并弹出你的错误,它还应该伴随着“条目日志”中的条目,问题是什么,“原因:找不到目标android -10“对我来说。一旦你修复了它,你应该能够成功地同步项目并继续前进。
#1
44
I have yet to find a good solution within Android Studio, but this has worked for me on several projects:
我还没有在Android Studio中找到一个好的解决方案,但这对我有好几个项目:
- Close the project in Android Studio (so it doesn't open the project automatically in later steps) and then close Android Studio
- 在Android Studio中关闭项目(因此它不会在后续步骤中自动打开项目),然后关闭Android Studio
- Clean the project (delete the ".idea" and "build" folders, .iml files, etc.) so you only have the source files remaining
- 清理项目(删除“.idea”和“build”文件夹,.iml文件等),这样您只剩下源文件
- Set up gradle by adding the appropriate settings.gradle and build.gradle files (test your setup using the command line)
- 通过添加适当的settings.gradle和build.gradle文件来设置gradle(使用命令行测试您的设置)
- Open Android Studio and choose "Import project" and choose to use Gradle as the external model
- 打开Android Studio并选择“导入项目”,然后选择使用Gradle作为外部模型
- Pick your settings.gradle file as the Gradle project
- 选择您的settings.gradle文件作为Gradle项目
- [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).
- [可选]设置“Gradle home”文件夹(使文本变为黑色而不是灰色)。如果我没有这样做,早期版本的Android Studio会给我带来麻烦。确保使用Gradle 0.1.10或更高版本(早期版本不适用于当前的Gradle构建工具)。
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:
另外,请记住使用最新版本的Gradle构建工具。如果需要,可以将Gradle设置为使用最新版本,如下所示:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
#2
8
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.
你需要做的就是在android studio中“导入项目”来导入eclipse项目。在那之后,尝试“Syncronize project”,如果它失败了,并弹出你的错误,它还应该伴随着“条目日志”中的条目,问题是什么,“原因:找不到目标android -10“对我来说。一旦你修复了它,你应该能够成功地同步项目并继续前进。