我有一个项目已经在 Android Studio 中运行。
在 Android Studio 中打开项目后,我收到消息:
将项目迁移到 Gradle?
该项目不使用 Gradle 构建系统。我们建议您迁移到使用 Gradle 构建系统。
有关迁移到 Gradle 的更多信息
不要再显示此消息。
按照以下链接有关迁移到 Gradle 的更多信息 http://tools.android.com/tech-docs/new-build-system/intellij_to_gradle虽然我已经在Android Studio
我已经遵循了该选项从 IntelliJ 项目迁移 http://tools.android.com/tech-docs/new-build-system/migrating-from-intellij-projects .
既然我已经有一个build.gradle
我已修改项目根目录下的文件以包含一些依赖项。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile "com.android.support:support-v4:18.0.+"
compile "com.android.support:appcompat-v7:18.0.+"
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
按照指示,我跑了gradle assembleDebug
on the Android Studio
终端窗口但出现一些错误。为了解决这个错误,我必须创建一个local.properties
with sdk.dir=C:\\Program Files (x86)\\Android\\android-sdk
并删除android-support-v4.jar
文件来自/libs
文件夹并从Libraries->libs
来自Project Structure
.
我现在又跑了gradle assembleDebug
这次它完成了,没有任何错误。
我已经重新启动了Android Studio
但重新启动后我在External Libraries
该项目没有support-v4
and appcompat-v7
在我的一堂课上,我有import android.support.v4.widget.CursorAdapter;
标记为错误,因为Cannot resolve symbol Cursor Adapter
.
如果我按下按钮Sync project with gradle files
我收到消息:The project MyProject is not a Gradle-based project
有人可以帮我弄清楚如何解决这个问题吗?
这是我的项目结构