java - 从 Eclipse 迁移到 Android Studio 问题

标签 java android eclipse android-studio android-gradle-plugin

我正在尝试将我的项目从 Eclipse 转移到 Android studio。 我尝试了两种方法:

  • 使用 Android Studio IDE 中的“导入”导入当前项目。

  • 将当前项目导出为成绩项目

(虽然我没有成绩 在我的 eclipse 项目中设置),然后将其导入到 Android Studio 中。

使用第一种方法时,我遇到了 gradle 和 API 错误,例如:

没有适用于 com.android.support:support-v4:jar 的版本 (我安装了22和23 sdk,都没有解决这个问题)。

Error:(15, 0) Gradle DSL method not found: 'android()' Possible causes: The project may be using a version of Gradle that does not contain the method. Gradle settings.The build file may be missing a Gradle plugin. Apply Gradle plugin

使用项目资源管理器中的第二种方法,我只能看到 Java src 文件,而没有 res 文件夹。

这是 Gradle 代码:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}
apply plugin: 'com.android.application'

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.0'

    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')
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

正确的做法是什么? 我这样做主要是为了将 Gradle 添加到我的项目中。

谢谢!

最佳答案

您采用第一种方法并更改 Android 支持版本。

步骤: 您转到“打开模块设置”,然后删除旧的依赖项。 并选择以下支持文件,然后同步项目。

版本 23: 支持-v4 (com.android.support:support-v4:23.0.1)

关于java - 从 Eclipse 迁移到 Android Studio 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32864534/

相关文章:

java - 我做了什么使 "weak refs processing"需要 30 秒而不是 1.5 秒?

java - 将图像存储为数组或枚举 : which is better?

java - 如何使用 wamp 服务器发送 Spinner 在数据库中选择的值

android - eclipse 机器人 : edittext input will be the output of other edittext

java - 参数传递到方法中的顺序 (Java)

Android HTTP 调用未设置接受语言 header ?

android - 为什么 Android Studio 无法识别 Android Q Beta 2 符号?

android - 如何停止新线程(new Runnable())

java - 将控制台 Java 应用程序传输到 Maven

Android android.view.InflateException 二进制 XML 文件行 #16 : Error inflating class fragment