无法在Android Studio中将项目迁移到Gradle [英] Can't migrate project to Gradle in Android Studio

查看:1674
本文介绍了无法在Android Studio中将项目迁移到Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目已经在Android Studio中运行。

I have a project that I already run in Android Studio.

在Android Studio中打开项目后,我收到了消息:

After I've opened the project in Android Studio I got the message:

将项目迁移到Gradle?
此项目不使用Gradle构建系统。我们建议您迁移到使用Gradle构建系统。
有关迁移到Gradle的更多信息
请勿再次显示此消息。

点击有关迁移到Gradle的更多信息虽然我已经在 Android Studio 我已经按照选项从IntelliJ项目迁移

Following the link of More Information about migrating to Gradle although I'm already on Android Studio I've followed the option Migrating from IntelliJ Projects .

因为我已经有 build.gradle 我的项目根目录中的文件我已修改为包含一些依赖项。

Since I've already have a build.gradle file at the root of my project I've modified to include some dependencies.

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 > Android Studio 终端窗口但是出现了一些错误。要解决这个错误,我必须使用 sdk.dir = C:\\Program Files(x86)\\\创建 local.properties \\ Android \\android-sdk 并从 / libs中删除 android-support-v4.jar 文件文件夹以及来自项目结构 Libraries-> libs

As instructed, i've ran gradle assembleDebug on the Android Studio terminal windows but was getting some errors. To solve this errors I had to create a local.properties with sdk.dir=C:\\Program Files (x86)\\Android\\android-sdk and remove the android-support-v4.jar file from the /libs folder and from the Libraries->libs from the Project Structure.

我现在又跑了 gradle assembleDebug ,这次它完成没有任何错误。

I now ran again gradle assembleDebug and this time it finishes without any errors.

我重新开始 Android Studio 但重新启动后我在上看到了该项目的外部库没有 support-v4 appcompat-v7 并且我的一个类我有 import android.support.v4.widget.CursorAdapter; 标记为错误,因为无法解析符号Cursor Adapter

I've restarted Android Studio but after restarting I've saw that on the External Libraries of the project there were no support-v4 and appcompat-v7 and in one of my classes I have the import android.support.v4.widget.CursorAdapter; marked as error since Cannot resolve symbol Cursor Adapter.

如果我按下按钮使用gradle文件同步项目我收到了消息:项目MyProject不是基于Gradle的项目

If I press the button Sync project with gradle filesi got the message: The project MyProject is not a Gradle-based project

有人可以帮我弄清楚如何解决这个问题吗?

Can someone help me figuring out how to solve this?

这是我的项目结构

推荐答案

该项目认为它仍然是一个非基于Gradle的项目;不存在使其成为基于Gradle的 build.gradle 文件,但它首先是设置项目的方式。您需要重新导入项目才能完成转换为Gradle。

The project thinks it's still a non-Gradle based project; it's not the presence of the build.gradle file that makes it Gradle-based, but it's how the project was set up in the first place. You'll need to re-import your project to finish the conversion to Gradle.

首先,看起来您没有设置。 gradle 文件;看起来你需要一个。由于您已将项目设置为单模块项目,因此可以将该文件放在项目的根目录中,紧邻 build.gradle 。它应该包含:

First, though, it looks like you don't have a settings.gradle file; it looks like you need one. Since you've set up your project as a single-module project, then you can put the file in your project's root directory, next to build.gradle. It should contain this:

import ':'

将来如果向项目添加更多模块,可能需要将其转换为多模块目录结构,但现在不必担心。无论如何,现在你需要在Android Studio中重新导入:

In the future if you add more modules to your project you may want to convert it to a multi-module directory structure, but you don't need to worry about that now. In any event, now you need to do the re-import in Android Studio:


  1. 关闭你的项目

  2. 备份项目

  3. 删除项目根目录中的 .idea 文件夹

  4. 全部删除项目中的 .iml 文件

  5. 在Android Studio中导入项目,在提示您输入文件的对话框中,选择构建。 gradle 文件。

  1. Close your project
  2. Back up your project
  3. Delete the .idea folder in the root directory of the project
  4. Delete all the .iml files in your project
  5. Import your project in Android Studio, and in the dialog that prompts you for a file, choose the build.gradle file.

在此之后你应该好好去。

After this you should be good to go.

这篇关于无法在Android Studio中将项目迁移到Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆