现在如何将Eclipse项目导入Android Studio ?

时间:2023-01-13 22:20:03

Using "Import Project" in Android Studio for an Eclipse project used to change the project structure and generate Gradle files, but right now (I'm using AS 0.5.3) it's only generating IDEA files (.iml, .idea) but not Gradle and it's not touching the file structure either.

在Android Studio中为一个Eclipse项目使用“导入项目”来更改项目结构并生成渐变文件,但是现在(我使用的是0.5.3)它只生成想法文件()。但不是Gradle,也不涉及文件结构。

How do you import an Eclipse project into Android Studio now?

现在如何将Eclipse项目导入Android Studio ?

Update: Trying to export gradle files in Eclipse won't export them for the app, it doesn't show up as a module in Android Studio either.

更新:尝试在Eclipse中导出等级文件不会导出应用程序,它也不会显示为Android Studio中的模块。

11 个解决方案

#1


65  

In newer versions of Android Studio, the best way to bring in an Eclipse/ADT project is to import it directly into Android Studio; we used to recommend you export it from Eclipse to Gradle first, but we haven't been updating ADT often enough to keep pace with Android Studio.

在新版本的Android Studio中,引入Eclipse/ADT项目的最佳方式是将其直接导入Android Studio;我们曾经建议您首先将它从Eclipse导出到Gradle,但是我们并没有经常更新ADT以跟上Android Studio的步伐。

In any event, if you choose "Import Project" from the File menu or from the Welcome screen when you launch Android Studio, it should take you through a specialized wizard that will prompt you that it intends to copy the files into a new directory structure instead of importing them in-place, and it will offer to fix up some common things like converting dependencies into Maven-style includes and such.

在任何情况下,如果你选择从文件菜单或“进口项目”的欢迎屏幕在启动Android工作室时,应该带你通过专业向导将提示您,它打算将文件复制到一个新目录结构而不是进口他们就地,它将提供解决一些常见的诸如将依赖关系转化为Maven-style包括等。

It doesn't seem like you're getting this specialized flow. I think it may not be recognizing your imported project as an ADT project, and it's defaulting to the old built-into-IntelliJ behavior which doesn't know about Gradle. To get the specialized import working, the following must be true:

看起来你并没有得到专门的流程。我认为它可能没有将导入的项目识别为ADT项目,它默认为不了解Gradle的内置智能j行为。要使专业的进口工作,以下必须是真实的:

  • The root directory of the project you import must have an AndroidManifest.xml file.
  • 您导入的项目的根目录必须具有AndroidManifest。xml文件。
  • Either:
    • The root directory must contain the .project and .classpath files from Eclipse
    • 根目录必须包含来自Eclipse的.project和.classpath文件
  • 要么:根目录必须包含来自Eclipse的.project和.classpath文件
  • or
    • The root directory must contain res and src directories.
    • 根目录必须包含res和src目录。
  • 或者根目录必须包含res和src目录。

If your project is complex, perhaps you're not pointing it as the root directory it wants to see for the import to succeed.

如果您的项目很复杂,那么您可能没有将其作为导入成功所需的根目录。

#2


24  

Export from Eclipse

  1. Update your Eclipse ADT Plugin to 22.0 or higher, then go to File | Export

    将您的Eclipse ADT插件更新到22.0或更高版本,然后执行文件|导出。

  2. Go to Android now then click on Generate Gradle build files, then it would generate gradle file for you.

    现在转到Android,然后点击生成渐变构建文件,然后它会为你生成渐变文件。

    现在如何将Eclipse项目导入Android Studio ?

  3. Select your project you want to export

    选择要导出的项目

    现在如何将Eclipse项目导入Android Studio ?

  4. Click on finish now

    单击finish现在

    现在如何将Eclipse项目导入Android Studio ?

Import into Android Studio

  1. In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.

    在Android Studio中,关闭当前打开的任何项目。您应该看到欢迎来到Android Studio窗口。

  2. Click Import Project.

    单击导入项目。

  3. Locate the project you exported from Eclipse, expand it, select it and click OK.

    定位从Eclipse导出的项目,展开它,选择它并单击OK。

#3


7  

Its Got simpler with Android Studio All you need is to first choose

Android Studio更简单,你只需要先选一个

  1. import project(eclipse.....) 现在如何将Eclipse项目导入Android Studio ?
  2. 导入项目(eclipse .....)
  3. then choose your folder eclipse based project.like this one below 现在如何将Eclipse项目导入Android Studio ?
  4. 然后选择您的文件夹eclipse项目。像这样的下面

3.based on the type of project and library you used like (ActionBarSherlock) you may prompted special import wizard so go ahead and click next then finish. in this case it was simple one

3所示。根据您使用的项目和库的类型(比如ActionBarSherlock),您可能会提示“特殊导入向导”,因此请单击“下一步”,然后单击“完成”。在这种情况下,这很简单

现在如何将Eclipse项目导入Android Studio ?

4.And you are done. 现在如何将Eclipse项目导入Android Studio ?

4所示。和你做。

but sometimes the debug or Run options do not work and a error msg shows like

但有时调试或运行选项不起作用,一个错误msg显示如下

"this project structure is not gradle based or migrate it to gradle"

"这个项目结构不是基于等级或迁移到等级"

something to solve this close the opened eclipse project and reopen same project through the same process as we did before with import project (eclipse adt,gradle,etc)) this time android studio gonna add all necessary gradle files and green debug option will work too. i have did this somehow accidentally but it worked, i just hope it works for you too.

解决此问题的方法是关闭已打开的eclipse项目,并通过与之前导入项目(eclipse adt、gradle等)相同的过程重新打开相同的项目,这次android studio将添加所有必需的gradle文件和green debug选项。我不小心做了这件事,但它成功了,我只是希望它对你也有效。

#4


7  

Try these steps: 1- click on Import project (Eclipse, ADT, ...)

尝试以下步骤:1-单击导入项目(Eclipse, ADT,…)

现在如何将Eclipse项目导入Android Studio ?

2- Choose main directory of your Eclipse project

2-选择Eclipse项目的主目录

现在如何将Eclipse项目导入Android Studio ?

3- Keep the defaults. The first two options is for changing jar files into remote libraries (dependencies). It mean while building Android studio try to find library in local system or remote repositories. The last option is for showing only one folder as app after importing.

3 -保留默认值。前两个选项用于将jar文件更改为远程库(依赖项)。这意味着在构建Android studio时,尝试在本地系统或远程存储库中找到库。最后一个选项是在导入后只显示一个文件夹作为app。

现在如何将Eclipse项目导入Android Studio ?

4- Then, you will see the summary of changes

4-然后,您将看到变更的摘要

现在如何将Eclipse项目导入Android Studio ?

5- Then, if you see Gradle project sync failed, you should go to project view (top left corner). Then, you should go to your project-> app and open build.gradle.

5-然后,如果您看到Gradle项目同步失败,您应该去项目视图(左上角)。然后,你应该去你的项目>应用和开放建设。

现在如何将Eclipse项目导入Android Studio ?

6- Then, you should change your compilesdkVersion and targetsdkVersion to your current version that you see in buildToolsVersion (mine is 23). For example, in my project I should change 17 to 23 in two places

6-然后,您应该将编译后的dkversion和targetsdkVersion更改为您在buildToolsVersion中看到的当前版本(我的版本是23)。例如,在我的项目中,我应该在两个地方将17改为23

7- If you see an error in your dependencies, you should change the version of it. For example, in my project I need to check which version of android support library I am using. So, I open the SDK manager and go to bottom to see the version. Then, I should replace my Android studio version with my current version and click try again from top right corner

7-如果您在依赖项中看到错误,您应该更改它的版本。例如,在我的项目中,我需要检查我正在使用哪个版本的android支持库。因此,我打开SDK管理器,到底部查看版本。然后,我应该用当前版本替换我的Android studio版本,然后从右上角再次单击try

现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ?

I hope it helps.

我希望它有帮助。

#5


6  

Android Studio has been improved since this question was posted, and the latest versions of Android Studio (as of this writing, we are at 2.1.1) have fairly good Eclipse importing capabilities, so importing Eclipse projects directly into Android Studio is now the best approach for migrating projects from Eclipse into Android Studio.

Android工作室发布以来一直在改善这个问题,和最新版本的Android工作室(在撰写本文时,我们在2.1.1)有相当好的Eclipse导入功能,所以导入Eclipse项目直接进入Android工作室现在最好的方法迁移项目从Eclipse到Android工作室。

I will describe how to do this below, including a few of the pitfalls that one might encounter. I will deal in particular with importing an Eclipse workspace that contains multiple apps sharing one or more project libraries (the approaches posted thus far seem limited to importing just one Eclipse app project and its project libraries). While I don't deal with every possible issue, I do go into a lot of detail regarding some of them, which I hope will be helpful to those going through this process for the first time themselves.

下面我将介绍如何实现这一点,包括可能遇到的一些陷阱。我将特别介绍如何导入包含多个应用程序的Eclipse工作区,这些应用程序共享一个或多个项目库(到目前为止发布的方法似乎仅限于导入一个Eclipse应用程序项目及其项目库)。虽然我没有处理每一个可能的问题,但我确实对其中的一些问题进行了大量的细节讨论,我希望这将有助于那些第一次经历这个过程的人。

I recently imported the projects from an Eclipse workspace. This workspace included four library projects that were shared between up to nine projects each.

我最近从Eclipse工作区导入了项目。这个工作区包括四个库项目,每个项目最多共享9个项目。

Some background:

背景知识:

An Eclipse workspace contains multiple projects, which may be library projects or apps.

Eclipse工作区包含多个项目,这些项目可能是库项目或应用程序。

An Android Studio project is analogous to an Eclipse workspace, in that it can contain both library projects and apps. However, a library project or an app is represented by a "module" in Android Studio, whereas it is represented by a "project" in Eclipse.

Android Studio项目类似于Eclipse工作区,因为它可以包含库项目和应用程序。然而,库项目或应用程序在Android Studio中由“模块”表示,而在Eclipse中由“项目”表示。

So, to summarize: Eclipse workspaces will end up as Android Studio projects, and Eclipse projects inside a workspace will end up as Android Studio modules inside a project.

综上所述:Eclipse工作区将以Android Studio项目结束,而工作空间中的Eclipse项目将以项目中的Android Studio模块结束。

You should start the import process by creating an Android Studio project (File / New / New Project). You might give this project the same (or similar) name as you gave your Eclipse workspace. This project will eventually hold all of your modules, one each for each Eclipse project (including project libraries) that you will import.

您应该通过创建一个Android Studio项目(文件/新项目/新项目)来启动导入过程。您可以为这个项目提供与Eclipse工作区相同(或类似)的名称。这个项目最终将包含所有模块,每个模块对应您将要导入的每个Eclipse项目(包括项目库)。

The import process does not change your original Eclipse files, so long as you place the imported files in a different folder hierarchy, so you should choose a folder for this project that is not in your original Eclipse hierarchy. For example, if your Eclipse projects are all in a folder called Android, you might create a sibling folder called AStudio.

导入过程不会更改原始Eclipse文件,只要将导入的文件放在不同的文件夹层次结构中,因此应该为这个项目选择一个不在原始Eclipse层次结构中的文件夹。例如,如果您的Eclipse项目都在一个名为Android的文件夹中,那么您可以创建一个名为AStudio的兄弟文件夹。

Your Android Studio project can then be created as a sub-folder of this new folder. The New Project wizard will prompt you to enter this top-level project folder, into which it will create your project.

然后可以将Android Studio项目创建为这个新文件夹的子文件夹。新的项目向导将提示您输入这个*的项目文件夹,它将在其中创建您的项目。

Android Studio's new project wizard will then ask you to configure a single module at the time you create the project. This can be a little confusing at first, because they never actually tell you that you are creating a module, but you are; you are creating a project with a single module in it. Apparently, every project is required to have at least one module, so, since you are relying on Eclipse to provide your modules, your initial module will be a placeholder to vacuously satisfy that formal requirement.

Android Studio的新项目向导会要求您在创建项目时配置一个模块。这一开始可能有点让人困惑,因为他们从来没有告诉你你正在创建一个模块,但是你是;您正在创建一个项目,其中只有一个模块。显然,每个项目都需要至少有一个模块,因此,由于您需要依赖Eclipse来提供模块,所以您的初始模块将是一个占位符,以空虚地满足正式的需求。

Thus, you probably will want to create an initial module for your project that does as little as possible. Therefore, select Phone and Tablet as the type of your module, accept the default minimum SDK (API level 8), and select Add No Activity for your module.

因此,您可能希望为您的项目创建一个尽可能少的初始模块。因此,选择Phone和Tablet作为模块的类型,接受默认的最小SDK (API级别8),选择不为模块添加活动。

Next, select one of the Eclipse app projects in your workspace that requires the largest number of libraries as your first project to import. The advantage of doing this is that when you import that project, all the library projects that it uses (directly, or indirectly, if some of your library projects themselves require other library projects) will get imported along with it as part of the importing process.

接下来,在您的工作区中选择一个Eclipse应用程序项目,这需要最大数量的库作为您的第一个导入项目。这样做的好处是,当您导入该项目时,它所使用的所有库项目(直接或间接地,如果您的一些库项目本身需要其他库项目)都将作为导入过程的一部分一并导入。

Each of these imported projects will get its own module within your Android Studio project. All of these modules will be siblings of one another (both in your project hierarchy, and in the folder hierarchy where their files are placed), just as if you had imported the modules separately. However, the dependencies between the modules will be created for you (in your app's build.gradle files) as part of the importing process.

每个导入的项目都将在Android Studio项目中获得自己的模块。所有这些模块都是彼此的兄弟(在您的项目层次结构中,以及它们的文件所在的文件夹层次结构中),就像您分别导入了这些模块一样。但是,模块之间的依赖关系将为您创建(在应用程序的构建中)。作为导入过程的一部分。

Note that after you finish importing, testing and debugging this "most dependent" Eclipse project and its supporting library projects, you will go on to import a second Eclipse app project (if you have a second one in your workspace) and its library project modules (with those imported earlier getting found by the import wizard as existing modules and re-used for this new module, rather than being duplicated).

注意,导入完成后,测试和调试这个“最依赖”Eclipse项目及其支持库项目,您将继续进口第二个Eclipse应用程序项目(如果你有一个工作空间中的第二个)和它的库项目模块(与进口早些时候被导入向导发现现有模块和重用这个新的模块,而不是复制)。

So, you should never have to import even a single library project from Eclipse directly; they will all be brought in indirectly, based on their dependencies upon app projects that you import. This is assuming that all of your library projects in the workspace are created to serve the needs of one or more app projects in that same workspace.

因此,您不必直接从Eclipse导入一个库项目;它们都将被间接地引入,基于它们依赖于您导入的应用程序项目。假设工作区中的所有库项目都是为了满足同一个工作区中的一个或多个应用程序项目的需求而创建的。

To perform the import of this first app project, back in Android Studio, while you are in the project that you just created, select File / New / New Module. You might think that you should be using File / New / Import Module, but no, you should not, because if you do that, Android Studio will create a new project to hold your imported module, and it will import your module to that project. You actually could create your first module that way, but then the second through Nth modules would still require that you use this other method (for importing a module into an existing project), and so I think that just starting with an "empty" project (or rather, one with its own vacuous, do-nothing placeholder module), and then importing each of your Eclipse projects as a new module into that project (i.e., the approach we are taking here), may be less confusing.

要执行第一个应用程序项目的导入,回到Android Studio,在您刚刚创建的项目中,选择File / New / New模块。您可能认为应该使用File / New / Import模块,但不应该使用,因为如果这样做,Android Studio将创建一个新项目来保存导入的模块,它将把模块导入到该项目中。您可以创建您的第一个模块,然后第二个通过n模块仍然会要求你使用其他方法(导入一个模块到现有项目),所以我认为,从一个“空”的项目(或者更确切地说,一个拥有自己的空洞,游手好闲的占位符模块),然后输入您的每个Eclipse项目(即作为一个新的模块项目。我们在这里采用的方法可能不会那么令人困惑。

So, you are going to take your practically-empty new project, and perform a File / New / New Module in it. The wizard that this invokes will give you a choice of what kind of module you want to create. You must select "Import Eclipse ADT Project." That is what accesses the wizard that knows how to convert an Eclipse project into an Android Studio module (along with the library modules on which it depends) within your current Android Studio project.

因此,您将使用实际为空的新项目,并在其中执行一个文件/新/新模块。该调用的向导将为您提供要创建的模块类型的选择。您必须选择“导入Eclipse ADT项目”。这就是访问向导的原因,该向导知道如何在当前的Android Studio项目中将Eclipse项目转换为Android Studio模块(以及它所依赖的库模块)。

When prompted for a source folder, you should enter the folder for your Eclipse project (this is the folder that contains that project's AndroidManifest.xml file).

当提示输入源文件夹时,您应该为您的Eclipse项目输入文件夹(这是包含该项目的AndroidManifest的文件夹)。xml文件)。

The import wizard will then display the module name that it intends to create (similar to your original Eclipse project's name, but with a lower-case first letter because that is a convention that distinguishes module names from project names (which start with an upper-case letter). It usually works pretty well to accept this default.

然后,导入向导将显示它打算创建的模块名称(与您最初的Eclipse项目名称类似,但是使用小写的第一个字母,因为这是一个将模块名称与项目名称区分开来的约定(从一个大写字母开始)。接受这个默认值通常很有效。

Below the module name is a section titled "Additional required modules." This will list every library required by the module you are importing (or by any of its libraries, etc.). Since this is the first module you are importing, none of these will already be in your project, so each of them will have its Import box checked by default. You should leave these checked because you need these modules. (Note that when you import later Eclipse app projects, if a library that they need has already been imported, those libraries will still appear here, but there will be a note that "Project already contains module with this name," and the Import box will be un-checked by default. In that case, you should leave the box unchecked, so that the importer will hook up your newly-imported module(s) to the libraries that have already been imported. It may be that accepting the default names that Android Studio creates for your modules will be important for allowing the IDE to find and re-use these library modules.

在模块名称下面是一个标题为“附加必需的模块”的部分。这将列出您正在导入的模块(或其任何库等)所需的每个库。由于这是您要导入的第一个模块,所以这些模块中没有一个已经在您的项目中,因此每个模块的导入框都会被默认选中。您应该保留这些检查,因为您需要这些模块。(请注意,当您导入以后的Eclipse应用程序项目时,如果需要的库已经被导入,那么这些库仍然会出现在这里,但是会注意到“项目已经包含了这个名称的模块”,并且默认情况下导入框将被取消选中。在这种情况下,应该不检查框,以便导入器将新导入的模块连接到已经导入的库。可能接受Android Studio为模块创建的默认名称对于IDE查找和重用这些库模块很重要。

Next, the importer will offer to replace any jars and library sources with Gradle dependencies, and to create camelCase module names for any dependent modules, checking all those options by default. You should generally leave these options checked and continue. Read the warning, though, about possible problems. Remember that you can always delete an imported module or modules (via the Project Structure dialog) and start the import process over again.

接下来,导入器将提供用Gradle依赖项替换任何jar和库源代码,并为任何依赖模块创建camelCase模块名称,默认检查所有这些选项。通常,您应该检查并继续这些选项。不过,请阅读有关可能出现问题的警告。请记住,您始终可以删除导入的模块或模块(通过Project Structure对话框),并再次启动导入过程。

The next display that I got (YMMV) claims that the Android Support Repository is not installed in my SDK installation. It provides a button to open the Android SDK Manager for purposes of installing it. However, that button did not work for me. I manually opened the SDK manager as a separate app, and found that the Android Support Repository was already installed. There was an update, however. I installed that, and tapped the Refresh button in the import dialog, but that did nothing. So, I proceeded, and the perceived lack of this Repository did not seem to hurt the importing process (although I did get messages regarding it being missing from time to time later on, while working with the imported code, which I was able to appease by clicking a supplied link that corrected the problem - at least temporarily). Eventually this problem went away when I installed an update to the repository, so you may not experience it at all.

我得到的下一个显示(YMMV)声明Android支持存储库没有安装在我的SDK安装中。它提供一个按钮来打开Android SDK管理器,以便安装它。但是,那个按钮对我不起作用。我手工将SDK管理器作为一个单独的应用程序打开,发现已经安装了Android Support Repository。然而,有一个更新。我安装了它,并在导入对话框中点击了Refresh按钮,但是没有任何效果。所以,我接着,缺乏这个库似乎没有伤害导入过程(虽然我得到消息关于它不时被失踪后,在导入的代码,我能够安抚通过点击一个链接,纠正问题——至少暂时提供)。最终,当我向存储库安装更新时,这个问题消失了,因此您可能根本没有体验到它。

At this point, you will click Finish, and after a bit it should create your modules and build them. If all goes well, you should get a BUILD SUCCESSFUL message in your Gradle Console.

此时,您将单击Finish,稍后它将创建您的模块并构建它们。如果一切顺利,您应该在您的Gradle控制台获得构建成功的消息。

One quirk is that if the build fails, you may not see your imported modules in the Project hierarchy. It seems that you need to get to the first valid build before the new modules will appear there (my experience, anyway). You may still be able to see the new modules in the File / Project Structure dialog (e.g., if you want to delete them and start your import over).

一个问题是,如果构建失败,您可能在项目层次结构中看不到导入的模块。似乎您需要在新模块出现之前获得第一个有效的构建(无论如何,我的经验)。您仍然可以在文件/项目结构对话框中看到新的模块(例如,如果您想删除它们并重新开始导入)。

Remember that since you are not changing your original Eclipse projects, you can always delete the modules that you have just imported (if importing goes badly), and start all over again. You can even make changes to the Eclipse side after deleting your Android Studio modules, if that will make importing go better the second time (so long as you preserve your fallback ability to build your existing source under Eclipse). As you'll see when we discuss version control below, it may be necessary for you to retain your ability to build under Eclipse, because the project structure is changed under Android Studio, so if you need to go back to a commit that precedes your move to Android Studio (e.g., to make a bug fix), you will want to have the ability to build that earlier commit in Eclipse.

请记住,由于您没有更改原始的Eclipse项目,所以您总是可以删除刚刚导入的模块(如果导入失败),然后重新开始。您甚至可以在删除Android Studio模块后对Eclipse端进行更改,如果这将使第二次导入变得更好(只要您保留在Eclipse下构建现有源代码的回退能力)。如您所见,当我们讨论下面的版本控制,它可能是必要的为你保留你的能力构建在Eclipse,因为项目结构改变在Android工作室,所以如果你需要回到提交之前你搬到Android工作室(例如,错误修正),你会想要在Eclipse中构建之前承诺的能力。

To delete a module, you must select File / Project Structure, then select the module from the left side of the dialog, and then hit the delete key. For some reason, I was not able to delete a module directly in the Project hierarchy; it had to be done using this Project Structure dialog.

要删除模块,必须选择File / Project结构,然后从对话框的左侧选择模块,然后单击delete键。由于某种原因,我无法直接删除项目层次结构中的模块;必须使用这个项目结构对话框来完成。

The import wizard generates an import-summary.txt file containing a detailed list of any issues it may have encountered, along with actions taken to resolve them. You should read it carefully, as it may provide clues as to what is happening if you have trouble building or running the imported code. It will also help you to find things that the importer moves around to accommodate the different structure of Android Studio projects.

导入向导生成导入摘要。txt文件包含可能遇到的任何问题的详细列表,以及为解决这些问题而采取的行动。您应该仔细阅读它,因为如果您在构建或运行导入的代码时遇到问题,它可能提供有关正在发生什么的线索。它还将帮助您发现导入器移动的东西,以适应Android Studio项目的不同结构。

If all does not go well, then have at look at these possible problems that you may encounter, along with solutions for those problems:

如果一切都不顺利,那么看看你可能遇到的这些问题,以及解决这些问题的办法:

Generally speaking, there are two main kinds of problems that I encountered:

总的来说,我遇到的主要有两种问题:

  1. Proguard problems
  2. 混淆器问题
  3. Manifest problems
  4. 明显的问题

When Proguard is messed up, the (obfuscated) names of methods in your libraries may not match the names being used to invoke them from your app, and you will get compiler errors like "error: cannot find symbol class ..."

当Proguard出错时,库中的(模糊的)方法名称可能与用于从应用程序调用它们的名称不匹配,您将得到编译器错误,如“error:找不到符号类…”

In Eclipse, Proguard stuff is pretty much ignored for library projects, with the Proguard stuff for any app project that you are building determining the obfuscation, etc. for not just itself, but for processing all of the libraries on which it depends. And that is generally what you want.

在Eclipse中,对库项目来说,Proguard的内容几乎被忽略了,对于您正在构建的任何应用程序项目来说,Proguard的内容决定了混淆,等等。这就是你想要的。

In Android Studio, however, you need to make some changes to attain this same effect. Basically, in the build.gradle files for each of your library project modules, you will want something like this:

然而,在Android Studio中,您需要做一些更改以获得相同的效果。基本上,在构建。每个库项目模块的等级文件,您将需要如下内容:

buildTypes {
    release {
        minifyEnabled false
        consumerProguardFiles 'proguard.cfg'
    }
}

Where proguard.cfg is your library module's own proguard configuration file.

混淆器的地方。cfg是库模块自己的proguard配置文件。

The term "consumer" in "consumerProguardFiles" apparently refers to the app module that is using this library module. So the proguard commands from that app are used in preference to those of the library module itself, and apparently this results in obfuscations that are coordinated and compatible, so that all calls from the app module to its library modules are made with matching symbols.

“consumerProguardFiles”中的术语“consumer”显然指的是正在使用这个库模块的应用程序模块。因此,该应用程序的proguard命令优先于库模块本身的命令,显然,这导致了协调和兼容的混淆,因此,从应用程序模块到库模块的所有调用都使用了匹配的符号。

These "consumerProguardFiles" entries are not created automatically during the import process (at least that was my own experience) so you will want to make sure to edit that into your library modules' build.gradle files if they are not created for you during importing.

这些“consumerProguardFiles”条目不会在导入过程中自动创建(至少这是我自己的经验),因此您需要确保将其编辑到库模块的构建中。如果在导入过程中没有为您创建渐变文件的话。

If you wanted to distribute your library projects separately, with obfuscation, then you would need an individual proguard file for them; I have not done this myself, and so that is beyond the scope of this answer.

如果您想要单独分发您的库项目,与混淆,那么您将需要一个单独的proguard文件;我自己没有这样做过,所以这超出了这个答案的范围。

In the app module, you will want something like this:

在app模块中,你会想要这样的东西:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles 'proguard.cfg'
    }
}

(BTW, as of this writing, while my apps are running just fine, I have not yet directly confirmed that things are actually getting obfuscated using this approach, so do check this yourself - e.g., by using a decompiler like apktool. I will be checking this later on, and will edit this answer when I get that info).

(顺便说一句,在撰写本文时,虽然我的应用程序运行良好,但我还没有直接确认使用这种方法会让事情变得混乱,所以请自己检查一下——例如,使用apktool这样的反编译器。稍后我会检查这个,当我得到那个信息时我会编辑这个答案)。

The second kind of problem is due to the fact that Eclipse pretty much ignores the manifest files for library projects when compiling an app project that uses those library projects, while in Android Studio, there is an interleaving of the two that apparently does not consistently prioritize the app's manifest over those of its libraries.

第二种问题是由于Eclipse为库项目几乎忽略了manifest文件编译应用程序时使用这些库项目的项目,而在Android工作室,有一个交叉的两个显然不一致优先考虑应用程序的清单的库。

I encountered this because I had a library manifest that listed (just for documentation purposes) an abstract Activity class as the main activity. There was a class derived from this abstract class in my app that was declared in the manifest of each app that used the library.

我遇到这种情况是因为我有一个库清单,它列出了一个抽象的活动类作为主要活动。在我的应用程序中有一个来自这个抽象类的类,它是在使用库的每个应用程序的清单中声明的。

In Eclipse, this never caused any problems, because the library manifests were ignored. But in Android Studio, I ended up with that abstract class as my activity class for the app, which caused a run-time error when the code made an attempt to instantiate that abstract class.

在Eclipse中,这不会导致任何问题,因为库清单被忽略了。但是在Android Studio中,我最终得到了抽象类作为应用程序的活动类,当代码试图实例化抽象类时,这会导致运行时错误。

You have two choices in this case:

在这种情况下你有两个选择:

  1. Use tools syntax to override specific library manifest stuff in your app manifest - for example:
  2. 使用工具语法覆盖应用程序清单中的特定库清单内容——例如:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.goalstate.WordGames.FullBoard.trialsuite"
       xmlns:tools="http://schemas.android.com/tools"
       .
       .
        <application
           tools:replace="android:name"

or,

或者,

  1. Strip out practically everything from your library modules' manifests, and rely upon the app module's manifest to provide every value. Note that you do need to have a manifest for each library module, but not much more is required than the header and a bare manifest element with just a package attribute in it.
  2. 实际上,从库模块的清单中删除所有内容,并依赖于应用程序模块的清单来提供每个值。注意,您确实需要为每个库模块提供一个manifest,但是只需要一个header和一个仅包含包属性的裸manifest元素。

I tried both and ended up with approach 2., above, as the simpler method. However, if you wanted to distribute your library modules separately, you would need to create a more meaningful manifest file that reflects each library module's own individual requirements.

我两种都试过了,结果是接近2。,作为更简单的方法。但是,如果想要单独发布库模块,则需要创建一个更有意义的清单文件,该文件反映每个库模块各自的需求。

There is probably a more "correct" way to do this which puts requirements (e.g., permissions) for each library in the library manifest itself, and allows the automatic interleaving process to combine these with those declared for the app. However, given that Eclipse ignores the manifests for libraries, it seems safer at least initially to rely entirely on the app manifests and just strip the library manifests down to the bare bones.

可能是一个有“正确”的方法将需求(例如,权限)为每个库库中的体现,并允许自动交叉过程将这些与那些宣称应用。然而,鉴于Eclipse为库,忽略了体现似乎更安全的至少一开始完全依赖应用程序清单,只带图书馆体现梗概。

Be aware that some of the project properties, and also the manifest attributes, from your Eclipse project will have been used to construct portions of your build.gradle files. Specifically, your compileSdkVersion in build.gradle is set to the project build version from the Eclipse project properties, applicationId is the package name from your app's manifest, and minSdkVersion and targetSdkVersion are also copied from the app's manifest file. The dependencies section of build.gradle comes from the library project dependencies in your project's properties.

请注意,来自Eclipse项目的一些项目属性以及manifest属性将被用于构建构建的部分。gradle文件。具体地说,就是在build中编译dkversion。gradle从Eclipse项目属性设置为项目构建版本,applicationId是应用程序清单中的包名称,minSdkVersion和targetSdkVersion也从应用程序的清单文件中复制。构建的依赖项部分。gradle来自于项目属性中的库项目依赖项。

Note that this may make some of your AndroidManifest.xml values redundant and quite possibly residual (i.e., unused). This could create confusion. My understanding is that the build.gradle values are the ones that actually have an effect, and that the manifest values like targetSdkVersion are not used any more for purposes of building. However, they may still be used by app stores such as Google Play; I don't know for certain one way or the other, so at this point I am just maintaining them in tandem.

请注意,这可能会使你的一些android显化。xml值是冗余的,而且很可能是剩余的(例如。未使用的)。这可能会造成混乱。我的理解是建造。gradle值是具有实际效果的值,并且不会再将targetSdkVersion这样的清单值用于构建目的。但是,谷歌Play等应用商店仍然可以使用;我不知道是这样还是那样,所以现在我只是把它们串联起来。

Besides the above two kinds of issue, there are more routine things like importing a project that has a project build level of 22 when you have only installed SDK level 23 in Android Studio. In that situation, it is probably better to edit your app module's build.gradle file to move compileSdkVersion from 22 (the imported value) to 23, than it would be to install the SDK for level 22, but either approach should work.

除了上述两种问题之外,还有更多的常规问题,比如当您在Android Studio中只安装了SDK 23级时,导入项目构建级别为22的项目。在这种情况下,最好编辑应用程序模块的构建。将编译后的dkversion从22(导入值)移动到23的gradle文件,要比将SDK安装到22级的文件多,但是这两种方法都应该有效。

Throughout this entire process, when something does not build properly and you make a change to try to address it, you might want to try Build / Rebuild Project and/or Tools / Android / Sync Project with Gradle Files, and/or File / Invalidate Caches/Restart, to make sure that your changes have been fully incorporated. I don't know exactly when these are truly necessary, because I don't know how much is done incrementally when you haven't yet had a successful build, but I performed them all fairly regularly as a kind of superstitious ritual, and I'm fairly certain that it helped. For example, when I got a Resources$NotFound runtime error that appeared to be from an inability to find the launch icon resource, I tried all three, and the problem was fixed.

在这整个过程中,当一些没有建立适当的和你做出改变来解决它,你可能会想尝试构建/重建项目和/或工具/ Android /同步项目Gradle文件,和/或文件/缓存失效/重启,以确保您的更改已经完全整合。我不知道确切的时间是什么时候,因为我不知道,当你还没有成功的构建时,增量是多少,但是我经常把它们作为一种迷信的仪式来进行,我相当肯定它是有帮助的。例如,当我获得一个资源$NotFound运行时错误,似乎是由于无法找到启动图标资源时,我尝试了所有三个,问题是固定的。

When you have performed the above for your first Eclipse project and have attained a successful build, then with luck, you can select your app module from the dropdown at the top of the Android Studio display to the left of the play button, then click the play button itself, then select a device or Android Virtual Device, and the app should be loaded for running.

当你已经完成了以上第一个Eclipse项目,成功构建,然后运气好的话,你可以选择你的应用模块的下拉顶部的Android工作室显示左边的播放按钮,然后单击播放按钮本身,然后选择一个设备或Android虚拟设备,应用程序应该加载运行。

Likewise, you should be able to create a signed copy of your app using the Build / Generate Signed APK feature. Note that some import-related errors may appear when running your signed copy that do not appear when using the play button, so you need to confirm that both are working before deciding that your import is complete.

同样,您应该能够使用Build / Generate signed APK特性创建应用程序的签名副本。请注意,在运行签名副本时可能会出现一些与输入相关的错误,而使用play按钮时不会出现这些错误,因此在决定导入是否完成之前,您需要确认这两个错误都在工作。

Following this, you will probably want to turn on version control. I am using git myself, but there are a number of other options available.

接下来,您可能想要打开版本控制。我自己也在使用git,但是还有其他一些选项。

Version control is mostly beyond the scope of this answer, but there are a few things that are affected by the importing process. First, in Eclipse you might have your various projects in various folders stuck all over the place, but when you import into Android Studio, all modules will be created as direct child folders of your main project folder. So if you had a separate git folder for each project in Eclipse, or for related groups of projects organized under a parent folder for each group (as I did), that is not going to translate very well to Android Studio.

版本控制主要超出了这个答案的范围,但是有一些事情会受到导入过程的影响。首先,在Eclipse中,您可能会将各种项目放在各种文件夹中,但是当您导入到Android Studio时,所有模块将被创建为主项目文件夹的直接子文件夹。因此,如果您有一个单独的git文件夹,用于Eclipse中的每个项目,或者为每个组在父文件夹下组织的相关项目组(就像我所做的那样),这将不能很好地转化为Android Studio。

My knowledge of this is limited as I have not worked with version control yet in Android Studio, so maybe there is a way around this, but it appears that all version control in Android Studio is unified at the project level, and so all of your modules will be under a single git archive.

我的知识是有限的,我还没有与版本控制Android工作室,所以也许有办法解决这个问题,但现在看来,所有版本控制Android工作室统一在项目层面,所以你所有的模块将会在一个git存档。

This means that you may need to abandon your old git archive and start fresh with a new archive for your imported source code. And that means that you will want to keep your old git archive around, so that it can be used with Eclipse to perform any needed bug fixes, etc., at least for a while. And you also will want it to preserve a history of your project.

这意味着您可能需要放弃旧的git归档文件,重新开始导入源代码的新归档文件。这意味着您将希望保留旧的git归档文件,以便至少在一段时间内将其与Eclipse一起用于执行任何所需的bug修复等等。你也会希望它能保存你项目的历史。

If you are fortunate enough to have had all of your projects organized under a single Eclipse workspace, and if you were using a single git archive for those projects, then it is possible that you might just copy your old git archive from in and under your Eclipse workspace folder to in and under your Android Studio project folder. Then, you could edit any still-relevant .gitignore items from you Eclipse project into the auto-generated .gitignore file for your Android Studio project, and let git figure out what has been changed during the importing process (and some things will have been moved around - for example, the manifest file is no longer at the top level of your module). Others have reported that git is pretty good at figuring out what has changed; I have not tried this myself.

如果你足够幸运有你所有的项目组织在一个Eclipse工作区中,如果你使用一个git归档的项目,那么很可能你会复制你的旧git存档的,在您的Eclipse工作区文件夹,在你的Android工作室项目文件夹。然后,您可以编辑任何相关.gitignore物品从你Eclipse项目自动生成.gitignore申请你的Android工作室项目,并让git在导入过程中找出改变了(和一些事情会一直移动——例如,清单文件不再是在顶层的模块)。其他人则报告说,git非常善于找出发生了什么变化;我自己还没试过。

But even if you did this, going back to a commit that precedes your move from Eclipse to Android Studio would be going back to a set of files that would only make sense from inside Eclipse. So it sounds, well, "difficult" to work with. Especially since Eclipse will still be pointing to its original set of project folders.

但是,即使您这样做了,返回到从Eclipse到Android Studio之前的提交,将返回到一组只在Eclipse中有意义的文件。听起来,嗯,很难共事。特别是由于Eclipse仍将指向其原始的项目文件夹集。

I personally had multiple git archives for my various sets of related projects, and so I decided to just make a clean break and start git over again in Android Studio. If you had to do this, it could affect your planning, because you would want to be at a very stable point in your code development before making the move in that case, since you will lose some accessibility to that older code within your version control system (e.g., ability to merge with post-import code) once you have made the move to Android Studio.

我个人拥有多个git档案,用于我的各种相关项目,所以我决定在Android Studio中重新开始git。如果你不得不这样做,它可以影响你的计划,因为你会想要在一个非常稳定的点在你的代码开发之前在这种情况下,因为你将失去一些可访问性,老的代码在您的版本控制系统(例如,能力与post-import合并代码)一旦你已经搬到Android工作室。

The part of this answer that pertains to git is partly speculative, since I have not actually worked with version control yet on my imported project files, but I wanted to include it to give some idea of the challenges, and I plan to update my answer after I have worked more with version control inside Android Studio.

这个答案的一部分属于git是部分投机,因为我还没有真正与版本控制进口项目文件,但是我想把它给一些想法的挑战,和我计划更新我的回答后我与版本控制工作在Android工作室。

#6


3  

According to http://tools.android.com/tech-docs/new-build-system/migrating-from-eclipse-projects, You have a couple of choices
- simply importing
- pre-exporting first from Eclipse.

根据http://tools.android.com/tech-docs/new-build-system/ migrating-fromeclipse -projects,您有两个选择——简单地导入——从Eclipse先导出。

Pre-exporting from eclipse may be the better choice if your project contains a lot of relationships that are Eclipse-specific. A.S. cannot 'translate' everything Eclipse can produce. If you want to continue using Eclipse as well as A.S. on this project code, this is the better choice. If you choose this method, please read the above link, there are some important pre-requisites.

Simply importing into AS will let AS 'translate' and rearrange the project, and is the recommended method, especially if you have no intention of returning to Eclipse. In this case, you let the A.S. wizard do everything and you dont need to manually generate gradle files.

如果您的项目包含许多特定于eclipse的关系,那么从eclipse预导出可能是更好的选择。A.S.不能“翻译”Eclipse能够产生的一切。如果您想在这个项目代码上继续使用Eclipse和A.S.,这是更好的选择。如果您选择这个方法,请阅读上面的链接,有一些重要的先决条件。简单地导入AS可以让AS“翻译”并重新安排项目,这是推荐的方法,尤其是当您无意返回Eclipse时。在这种情况下,您可以让A.S.向导完成所有工作,而不需要手工生成渐变文件。

#7


1  

In addition to the answer by Scott Barta above, you may still have import problems if there are references to Eclipse workspace library files, with e.g.

除了上面Scott Barta给出的答案之外,如果有对Eclipse工作区库文件的引用,例如

/workspace/android-support-v7-appcompat

being a common one.

是常见的一种。

In this case the import will halt until you provide a reference (and if you've cloned from a git repo, it probably won't be there) and even pointing to your own install (e.g. something like /android-sdk-macosx/extras/android/m2repository/com/android/support/appcompat-v7) won't be recognised and will halt the import, leaving you in no-man's land.

在这种情况下,导入将停止,直到您提供一个引用(如果您已经从一个git repo克隆,它可能不会在那里),甚至指向您自己的安装(例如/android-sdk-macosx/extras/android/m2repository/ support/appcompat-v7)将不会被识别,并将停止导入,将您留在无人的地方。

To get around this, look for refs in the project.properties or .classpath files that came in from the Eclipse project and remove/comment them out, e.g.

要解决这个问题,请在项目中查找参考文献。来自Eclipse项目的属性或.classpath文件,并将它们删除/注释掉。

<classpathentry combineaccessrules="false" kind="src" path="/android-support-v7-appcompat"/>

That will get you past the import stage and you can then add these refs in your build.gradle (Module:app) as indicated in the Android tutorial, like below:

这将使您通过导入阶段,然后您可以在构建中添加这些refs。如Android教程中所示的gradle(模块:app),如下图所示:

dependencies {
    compile 'com.android.support:appcompat-v7:22.2.0'
}

#8


1  

Here is a simpler way to migrate:

这里有一种更简单的迁移方式:

Start off with a sample Android Studio project. Open android studio and create a new project (or) just download a ‘sample’ studio project here: https://github.com/AppLozic/eclipse-to-android-studio-migration. Now, open the downloaded project in Android Studio by following the below instructions.

从一个示例Android Studio项目开始。打开android studio并创建一个新项目(或者),在这里下载一个“示例”studio项目:https://github.com/applozic/eclipse/android-studio -migration。现在,按照下面的说明在Android Studio中打开下载的项目。

Import eclipse project modules into Android Studio. Select File -> New -> Import Module Image title

将eclipse项目模块导入Android Studio。选择File ->新建->导入模块图像标题

Next, select the path of the eclipse project and import the modules. In case, if you see the message “Failed to sync Gradle project,” then click on “Install Build Tools and sync project…”

接下来,选择eclipse项目的路径并导入模块。如果您看到“未能同步Gradle项目”的消息,请单击“安装构建工具和同步项目……”

Now, remove the sample project modules by following the below simple steps:

现在,通过以下简单步骤删除示例项目模块:

Open settings.gradle and remove “include ‘:app’” Right click on “app” module and “Delete” it. Now, what we have is the Eclipse project open in Android studio with the Gradle build.

打开设置。逐步删除“include:app”右键点击“app”模块,“Delete”。现在,我们拥有的是在Android studio中开放的带有渐变构建的Eclipse项目。

Here are few other links which might help you:

这里有一些其他的链接可以帮助你:

http://developer.android.com/sdk/installing/migrate.html Source: http://www.applozic.com/blog/migrating-project-from-eclipse-to-studio/

http://developer.android.com/sdk/installing/migrate.html来源:http://www.applozic.com/blog/migrating-project-from-eclipse-to-studio/

#9


0  

Simple steps: 1.Go to Android Studio. 2.Close all open projects if any. 3.There will be an option which says import non Android Studio Projects(Eclipse ect). 4.Click on it and choose ur project Thats't it enjoy!!!

简单的步骤:1。去Android Studio。关闭所有开放项目(如果有的话)。3所示。将有一个选项说导入非Android Studio项目(Eclipse ect)。4所示。点击它,选择你的项目那不是它享受!!

#10


0  

The best way to bring in an Eclipse/ADT project is to import it directly into Android Studio. At first GO to Eclipse project & delete the *project.properties** file.After that, open the Android studio Tool & import Eclipse project(Eclipse ADT, Gradle etc).

引入Eclipse/ADT项目的最佳方法是直接将其导入Android Studio。首先进入Eclipse项目并删除*项目。* *文件属性。然后,打开Android studio工具并导入Eclipse项目(Eclipse ADT、Gradle等)。

-- Thanks and Regards

——感谢和问候

Rakesh Kumar Jha Android Developer

Rakesh Kumar Jha Android开发者

#11


0  

Stop installing android studio 3.0.1 and go back 2.3.3 ( Stable version) . Check for the stable version and you can find them a lot

停止安装android studio 3.0.1,回到2.3.3(稳定版本)。检查稳定版本,你可以找到很多

All you have to do uninstall and go back to the other version. Yes it asks to create gradle file seperately which is completely new to me!

您所需要做的就是卸载并返回到另一个版本。是的,它要求分别创建一个对我来说是全新的等级文件!

Failure is the stepping stone for success..

失败是成功的垫脚石。

#1


65  

In newer versions of Android Studio, the best way to bring in an Eclipse/ADT project is to import it directly into Android Studio; we used to recommend you export it from Eclipse to Gradle first, but we haven't been updating ADT often enough to keep pace with Android Studio.

在新版本的Android Studio中,引入Eclipse/ADT项目的最佳方式是将其直接导入Android Studio;我们曾经建议您首先将它从Eclipse导出到Gradle,但是我们并没有经常更新ADT以跟上Android Studio的步伐。

In any event, if you choose "Import Project" from the File menu or from the Welcome screen when you launch Android Studio, it should take you through a specialized wizard that will prompt you that it intends to copy the files into a new directory structure instead of importing them in-place, and it will offer to fix up some common things like converting dependencies into Maven-style includes and such.

在任何情况下,如果你选择从文件菜单或“进口项目”的欢迎屏幕在启动Android工作室时,应该带你通过专业向导将提示您,它打算将文件复制到一个新目录结构而不是进口他们就地,它将提供解决一些常见的诸如将依赖关系转化为Maven-style包括等。

It doesn't seem like you're getting this specialized flow. I think it may not be recognizing your imported project as an ADT project, and it's defaulting to the old built-into-IntelliJ behavior which doesn't know about Gradle. To get the specialized import working, the following must be true:

看起来你并没有得到专门的流程。我认为它可能没有将导入的项目识别为ADT项目,它默认为不了解Gradle的内置智能j行为。要使专业的进口工作,以下必须是真实的:

  • The root directory of the project you import must have an AndroidManifest.xml file.
  • 您导入的项目的根目录必须具有AndroidManifest。xml文件。
  • Either:
    • The root directory must contain the .project and .classpath files from Eclipse
    • 根目录必须包含来自Eclipse的.project和.classpath文件
  • 要么:根目录必须包含来自Eclipse的.project和.classpath文件
  • or
    • The root directory must contain res and src directories.
    • 根目录必须包含res和src目录。
  • 或者根目录必须包含res和src目录。

If your project is complex, perhaps you're not pointing it as the root directory it wants to see for the import to succeed.

如果您的项目很复杂,那么您可能没有将其作为导入成功所需的根目录。

#2


24  

Export from Eclipse

  1. Update your Eclipse ADT Plugin to 22.0 or higher, then go to File | Export

    将您的Eclipse ADT插件更新到22.0或更高版本,然后执行文件|导出。

  2. Go to Android now then click on Generate Gradle build files, then it would generate gradle file for you.

    现在转到Android,然后点击生成渐变构建文件,然后它会为你生成渐变文件。

    现在如何将Eclipse项目导入Android Studio ?

  3. Select your project you want to export

    选择要导出的项目

    现在如何将Eclipse项目导入Android Studio ?

  4. Click on finish now

    单击finish现在

    现在如何将Eclipse项目导入Android Studio ?

Import into Android Studio

  1. In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.

    在Android Studio中,关闭当前打开的任何项目。您应该看到欢迎来到Android Studio窗口。

  2. Click Import Project.

    单击导入项目。

  3. Locate the project you exported from Eclipse, expand it, select it and click OK.

    定位从Eclipse导出的项目,展开它,选择它并单击OK。

#3


7  

Its Got simpler with Android Studio All you need is to first choose

Android Studio更简单,你只需要先选一个

  1. import project(eclipse.....) 现在如何将Eclipse项目导入Android Studio ?
  2. 导入项目(eclipse .....)
  3. then choose your folder eclipse based project.like this one below 现在如何将Eclipse项目导入Android Studio ?
  4. 然后选择您的文件夹eclipse项目。像这样的下面

3.based on the type of project and library you used like (ActionBarSherlock) you may prompted special import wizard so go ahead and click next then finish. in this case it was simple one

3所示。根据您使用的项目和库的类型(比如ActionBarSherlock),您可能会提示“特殊导入向导”,因此请单击“下一步”,然后单击“完成”。在这种情况下,这很简单

现在如何将Eclipse项目导入Android Studio ?

4.And you are done. 现在如何将Eclipse项目导入Android Studio ?

4所示。和你做。

but sometimes the debug or Run options do not work and a error msg shows like

但有时调试或运行选项不起作用,一个错误msg显示如下

"this project structure is not gradle based or migrate it to gradle"

"这个项目结构不是基于等级或迁移到等级"

something to solve this close the opened eclipse project and reopen same project through the same process as we did before with import project (eclipse adt,gradle,etc)) this time android studio gonna add all necessary gradle files and green debug option will work too. i have did this somehow accidentally but it worked, i just hope it works for you too.

解决此问题的方法是关闭已打开的eclipse项目,并通过与之前导入项目(eclipse adt、gradle等)相同的过程重新打开相同的项目,这次android studio将添加所有必需的gradle文件和green debug选项。我不小心做了这件事,但它成功了,我只是希望它对你也有效。

#4


7  

Try these steps: 1- click on Import project (Eclipse, ADT, ...)

尝试以下步骤:1-单击导入项目(Eclipse, ADT,…)

现在如何将Eclipse项目导入Android Studio ?

2- Choose main directory of your Eclipse project

2-选择Eclipse项目的主目录

现在如何将Eclipse项目导入Android Studio ?

3- Keep the defaults. The first two options is for changing jar files into remote libraries (dependencies). It mean while building Android studio try to find library in local system or remote repositories. The last option is for showing only one folder as app after importing.

3 -保留默认值。前两个选项用于将jar文件更改为远程库(依赖项)。这意味着在构建Android studio时,尝试在本地系统或远程存储库中找到库。最后一个选项是在导入后只显示一个文件夹作为app。

现在如何将Eclipse项目导入Android Studio ?

4- Then, you will see the summary of changes

4-然后,您将看到变更的摘要

现在如何将Eclipse项目导入Android Studio ?

5- Then, if you see Gradle project sync failed, you should go to project view (top left corner). Then, you should go to your project-> app and open build.gradle.

5-然后,如果您看到Gradle项目同步失败,您应该去项目视图(左上角)。然后,你应该去你的项目>应用和开放建设。

现在如何将Eclipse项目导入Android Studio ?

6- Then, you should change your compilesdkVersion and targetsdkVersion to your current version that you see in buildToolsVersion (mine is 23). For example, in my project I should change 17 to 23 in two places

6-然后,您应该将编译后的dkversion和targetsdkVersion更改为您在buildToolsVersion中看到的当前版本(我的版本是23)。例如,在我的项目中,我应该在两个地方将17改为23

7- If you see an error in your dependencies, you should change the version of it. For example, in my project I need to check which version of android support library I am using. So, I open the SDK manager and go to bottom to see the version. Then, I should replace my Android studio version with my current version and click try again from top right corner

7-如果您在依赖项中看到错误,您应该更改它的版本。例如,在我的项目中,我需要检查我正在使用哪个版本的android支持库。因此,我打开SDK管理器,到底部查看版本。然后,我应该用当前版本替换我的Android studio版本,然后从右上角再次单击try

现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ? 现在如何将Eclipse项目导入Android Studio ?

I hope it helps.

我希望它有帮助。

#5


6  

Android Studio has been improved since this question was posted, and the latest versions of Android Studio (as of this writing, we are at 2.1.1) have fairly good Eclipse importing capabilities, so importing Eclipse projects directly into Android Studio is now the best approach for migrating projects from Eclipse into Android Studio.

Android工作室发布以来一直在改善这个问题,和最新版本的Android工作室(在撰写本文时,我们在2.1.1)有相当好的Eclipse导入功能,所以导入Eclipse项目直接进入Android工作室现在最好的方法迁移项目从Eclipse到Android工作室。

I will describe how to do this below, including a few of the pitfalls that one might encounter. I will deal in particular with importing an Eclipse workspace that contains multiple apps sharing one or more project libraries (the approaches posted thus far seem limited to importing just one Eclipse app project and its project libraries). While I don't deal with every possible issue, I do go into a lot of detail regarding some of them, which I hope will be helpful to those going through this process for the first time themselves.

下面我将介绍如何实现这一点,包括可能遇到的一些陷阱。我将特别介绍如何导入包含多个应用程序的Eclipse工作区,这些应用程序共享一个或多个项目库(到目前为止发布的方法似乎仅限于导入一个Eclipse应用程序项目及其项目库)。虽然我没有处理每一个可能的问题,但我确实对其中的一些问题进行了大量的细节讨论,我希望这将有助于那些第一次经历这个过程的人。

I recently imported the projects from an Eclipse workspace. This workspace included four library projects that were shared between up to nine projects each.

我最近从Eclipse工作区导入了项目。这个工作区包括四个库项目,每个项目最多共享9个项目。

Some background:

背景知识:

An Eclipse workspace contains multiple projects, which may be library projects or apps.

Eclipse工作区包含多个项目,这些项目可能是库项目或应用程序。

An Android Studio project is analogous to an Eclipse workspace, in that it can contain both library projects and apps. However, a library project or an app is represented by a "module" in Android Studio, whereas it is represented by a "project" in Eclipse.

Android Studio项目类似于Eclipse工作区,因为它可以包含库项目和应用程序。然而,库项目或应用程序在Android Studio中由“模块”表示,而在Eclipse中由“项目”表示。

So, to summarize: Eclipse workspaces will end up as Android Studio projects, and Eclipse projects inside a workspace will end up as Android Studio modules inside a project.

综上所述:Eclipse工作区将以Android Studio项目结束,而工作空间中的Eclipse项目将以项目中的Android Studio模块结束。

You should start the import process by creating an Android Studio project (File / New / New Project). You might give this project the same (or similar) name as you gave your Eclipse workspace. This project will eventually hold all of your modules, one each for each Eclipse project (including project libraries) that you will import.

您应该通过创建一个Android Studio项目(文件/新项目/新项目)来启动导入过程。您可以为这个项目提供与Eclipse工作区相同(或类似)的名称。这个项目最终将包含所有模块,每个模块对应您将要导入的每个Eclipse项目(包括项目库)。

The import process does not change your original Eclipse files, so long as you place the imported files in a different folder hierarchy, so you should choose a folder for this project that is not in your original Eclipse hierarchy. For example, if your Eclipse projects are all in a folder called Android, you might create a sibling folder called AStudio.

导入过程不会更改原始Eclipse文件,只要将导入的文件放在不同的文件夹层次结构中,因此应该为这个项目选择一个不在原始Eclipse层次结构中的文件夹。例如,如果您的Eclipse项目都在一个名为Android的文件夹中,那么您可以创建一个名为AStudio的兄弟文件夹。

Your Android Studio project can then be created as a sub-folder of this new folder. The New Project wizard will prompt you to enter this top-level project folder, into which it will create your project.

然后可以将Android Studio项目创建为这个新文件夹的子文件夹。新的项目向导将提示您输入这个*的项目文件夹,它将在其中创建您的项目。

Android Studio's new project wizard will then ask you to configure a single module at the time you create the project. This can be a little confusing at first, because they never actually tell you that you are creating a module, but you are; you are creating a project with a single module in it. Apparently, every project is required to have at least one module, so, since you are relying on Eclipse to provide your modules, your initial module will be a placeholder to vacuously satisfy that formal requirement.

Android Studio的新项目向导会要求您在创建项目时配置一个模块。这一开始可能有点让人困惑,因为他们从来没有告诉你你正在创建一个模块,但是你是;您正在创建一个项目,其中只有一个模块。显然,每个项目都需要至少有一个模块,因此,由于您需要依赖Eclipse来提供模块,所以您的初始模块将是一个占位符,以空虚地满足正式的需求。

Thus, you probably will want to create an initial module for your project that does as little as possible. Therefore, select Phone and Tablet as the type of your module, accept the default minimum SDK (API level 8), and select Add No Activity for your module.

因此,您可能希望为您的项目创建一个尽可能少的初始模块。因此,选择Phone和Tablet作为模块的类型,接受默认的最小SDK (API级别8),选择不为模块添加活动。

Next, select one of the Eclipse app projects in your workspace that requires the largest number of libraries as your first project to import. The advantage of doing this is that when you import that project, all the library projects that it uses (directly, or indirectly, if some of your library projects themselves require other library projects) will get imported along with it as part of the importing process.

接下来,在您的工作区中选择一个Eclipse应用程序项目,这需要最大数量的库作为您的第一个导入项目。这样做的好处是,当您导入该项目时,它所使用的所有库项目(直接或间接地,如果您的一些库项目本身需要其他库项目)都将作为导入过程的一部分一并导入。

Each of these imported projects will get its own module within your Android Studio project. All of these modules will be siblings of one another (both in your project hierarchy, and in the folder hierarchy where their files are placed), just as if you had imported the modules separately. However, the dependencies between the modules will be created for you (in your app's build.gradle files) as part of the importing process.

每个导入的项目都将在Android Studio项目中获得自己的模块。所有这些模块都是彼此的兄弟(在您的项目层次结构中,以及它们的文件所在的文件夹层次结构中),就像您分别导入了这些模块一样。但是,模块之间的依赖关系将为您创建(在应用程序的构建中)。作为导入过程的一部分。

Note that after you finish importing, testing and debugging this "most dependent" Eclipse project and its supporting library projects, you will go on to import a second Eclipse app project (if you have a second one in your workspace) and its library project modules (with those imported earlier getting found by the import wizard as existing modules and re-used for this new module, rather than being duplicated).

注意,导入完成后,测试和调试这个“最依赖”Eclipse项目及其支持库项目,您将继续进口第二个Eclipse应用程序项目(如果你有一个工作空间中的第二个)和它的库项目模块(与进口早些时候被导入向导发现现有模块和重用这个新的模块,而不是复制)。

So, you should never have to import even a single library project from Eclipse directly; they will all be brought in indirectly, based on their dependencies upon app projects that you import. This is assuming that all of your library projects in the workspace are created to serve the needs of one or more app projects in that same workspace.

因此,您不必直接从Eclipse导入一个库项目;它们都将被间接地引入,基于它们依赖于您导入的应用程序项目。假设工作区中的所有库项目都是为了满足同一个工作区中的一个或多个应用程序项目的需求而创建的。

To perform the import of this first app project, back in Android Studio, while you are in the project that you just created, select File / New / New Module. You might think that you should be using File / New / Import Module, but no, you should not, because if you do that, Android Studio will create a new project to hold your imported module, and it will import your module to that project. You actually could create your first module that way, but then the second through Nth modules would still require that you use this other method (for importing a module into an existing project), and so I think that just starting with an "empty" project (or rather, one with its own vacuous, do-nothing placeholder module), and then importing each of your Eclipse projects as a new module into that project (i.e., the approach we are taking here), may be less confusing.

要执行第一个应用程序项目的导入,回到Android Studio,在您刚刚创建的项目中,选择File / New / New模块。您可能认为应该使用File / New / Import模块,但不应该使用,因为如果这样做,Android Studio将创建一个新项目来保存导入的模块,它将把模块导入到该项目中。您可以创建您的第一个模块,然后第二个通过n模块仍然会要求你使用其他方法(导入一个模块到现有项目),所以我认为,从一个“空”的项目(或者更确切地说,一个拥有自己的空洞,游手好闲的占位符模块),然后输入您的每个Eclipse项目(即作为一个新的模块项目。我们在这里采用的方法可能不会那么令人困惑。

So, you are going to take your practically-empty new project, and perform a File / New / New Module in it. The wizard that this invokes will give you a choice of what kind of module you want to create. You must select "Import Eclipse ADT Project." That is what accesses the wizard that knows how to convert an Eclipse project into an Android Studio module (along with the library modules on which it depends) within your current Android Studio project.

因此,您将使用实际为空的新项目,并在其中执行一个文件/新/新模块。该调用的向导将为您提供要创建的模块类型的选择。您必须选择“导入Eclipse ADT项目”。这就是访问向导的原因,该向导知道如何在当前的Android Studio项目中将Eclipse项目转换为Android Studio模块(以及它所依赖的库模块)。

When prompted for a source folder, you should enter the folder for your Eclipse project (this is the folder that contains that project's AndroidManifest.xml file).

当提示输入源文件夹时,您应该为您的Eclipse项目输入文件夹(这是包含该项目的AndroidManifest的文件夹)。xml文件)。

The import wizard will then display the module name that it intends to create (similar to your original Eclipse project's name, but with a lower-case first letter because that is a convention that distinguishes module names from project names (which start with an upper-case letter). It usually works pretty well to accept this default.

然后,导入向导将显示它打算创建的模块名称(与您最初的Eclipse项目名称类似,但是使用小写的第一个字母,因为这是一个将模块名称与项目名称区分开来的约定(从一个大写字母开始)。接受这个默认值通常很有效。

Below the module name is a section titled "Additional required modules." This will list every library required by the module you are importing (or by any of its libraries, etc.). Since this is the first module you are importing, none of these will already be in your project, so each of them will have its Import box checked by default. You should leave these checked because you need these modules. (Note that when you import later Eclipse app projects, if a library that they need has already been imported, those libraries will still appear here, but there will be a note that "Project already contains module with this name," and the Import box will be un-checked by default. In that case, you should leave the box unchecked, so that the importer will hook up your newly-imported module(s) to the libraries that have already been imported. It may be that accepting the default names that Android Studio creates for your modules will be important for allowing the IDE to find and re-use these library modules.

在模块名称下面是一个标题为“附加必需的模块”的部分。这将列出您正在导入的模块(或其任何库等)所需的每个库。由于这是您要导入的第一个模块,所以这些模块中没有一个已经在您的项目中,因此每个模块的导入框都会被默认选中。您应该保留这些检查,因为您需要这些模块。(请注意,当您导入以后的Eclipse应用程序项目时,如果需要的库已经被导入,那么这些库仍然会出现在这里,但是会注意到“项目已经包含了这个名称的模块”,并且默认情况下导入框将被取消选中。在这种情况下,应该不检查框,以便导入器将新导入的模块连接到已经导入的库。可能接受Android Studio为模块创建的默认名称对于IDE查找和重用这些库模块很重要。

Next, the importer will offer to replace any jars and library sources with Gradle dependencies, and to create camelCase module names for any dependent modules, checking all those options by default. You should generally leave these options checked and continue. Read the warning, though, about possible problems. Remember that you can always delete an imported module or modules (via the Project Structure dialog) and start the import process over again.

接下来,导入器将提供用Gradle依赖项替换任何jar和库源代码,并为任何依赖模块创建camelCase模块名称,默认检查所有这些选项。通常,您应该检查并继续这些选项。不过,请阅读有关可能出现问题的警告。请记住,您始终可以删除导入的模块或模块(通过Project Structure对话框),并再次启动导入过程。

The next display that I got (YMMV) claims that the Android Support Repository is not installed in my SDK installation. It provides a button to open the Android SDK Manager for purposes of installing it. However, that button did not work for me. I manually opened the SDK manager as a separate app, and found that the Android Support Repository was already installed. There was an update, however. I installed that, and tapped the Refresh button in the import dialog, but that did nothing. So, I proceeded, and the perceived lack of this Repository did not seem to hurt the importing process (although I did get messages regarding it being missing from time to time later on, while working with the imported code, which I was able to appease by clicking a supplied link that corrected the problem - at least temporarily). Eventually this problem went away when I installed an update to the repository, so you may not experience it at all.

我得到的下一个显示(YMMV)声明Android支持存储库没有安装在我的SDK安装中。它提供一个按钮来打开Android SDK管理器,以便安装它。但是,那个按钮对我不起作用。我手工将SDK管理器作为一个单独的应用程序打开,发现已经安装了Android Support Repository。然而,有一个更新。我安装了它,并在导入对话框中点击了Refresh按钮,但是没有任何效果。所以,我接着,缺乏这个库似乎没有伤害导入过程(虽然我得到消息关于它不时被失踪后,在导入的代码,我能够安抚通过点击一个链接,纠正问题——至少暂时提供)。最终,当我向存储库安装更新时,这个问题消失了,因此您可能根本没有体验到它。

At this point, you will click Finish, and after a bit it should create your modules and build them. If all goes well, you should get a BUILD SUCCESSFUL message in your Gradle Console.

此时,您将单击Finish,稍后它将创建您的模块并构建它们。如果一切顺利,您应该在您的Gradle控制台获得构建成功的消息。

One quirk is that if the build fails, you may not see your imported modules in the Project hierarchy. It seems that you need to get to the first valid build before the new modules will appear there (my experience, anyway). You may still be able to see the new modules in the File / Project Structure dialog (e.g., if you want to delete them and start your import over).

一个问题是,如果构建失败,您可能在项目层次结构中看不到导入的模块。似乎您需要在新模块出现之前获得第一个有效的构建(无论如何,我的经验)。您仍然可以在文件/项目结构对话框中看到新的模块(例如,如果您想删除它们并重新开始导入)。

Remember that since you are not changing your original Eclipse projects, you can always delete the modules that you have just imported (if importing goes badly), and start all over again. You can even make changes to the Eclipse side after deleting your Android Studio modules, if that will make importing go better the second time (so long as you preserve your fallback ability to build your existing source under Eclipse). As you'll see when we discuss version control below, it may be necessary for you to retain your ability to build under Eclipse, because the project structure is changed under Android Studio, so if you need to go back to a commit that precedes your move to Android Studio (e.g., to make a bug fix), you will want to have the ability to build that earlier commit in Eclipse.

请记住,由于您没有更改原始的Eclipse项目,所以您总是可以删除刚刚导入的模块(如果导入失败),然后重新开始。您甚至可以在删除Android Studio模块后对Eclipse端进行更改,如果这将使第二次导入变得更好(只要您保留在Eclipse下构建现有源代码的回退能力)。如您所见,当我们讨论下面的版本控制,它可能是必要的为你保留你的能力构建在Eclipse,因为项目结构改变在Android工作室,所以如果你需要回到提交之前你搬到Android工作室(例如,错误修正),你会想要在Eclipse中构建之前承诺的能力。

To delete a module, you must select File / Project Structure, then select the module from the left side of the dialog, and then hit the delete key. For some reason, I was not able to delete a module directly in the Project hierarchy; it had to be done using this Project Structure dialog.

要删除模块,必须选择File / Project结构,然后从对话框的左侧选择模块,然后单击delete键。由于某种原因,我无法直接删除项目层次结构中的模块;必须使用这个项目结构对话框来完成。

The import wizard generates an import-summary.txt file containing a detailed list of any issues it may have encountered, along with actions taken to resolve them. You should read it carefully, as it may provide clues as to what is happening if you have trouble building or running the imported code. It will also help you to find things that the importer moves around to accommodate the different structure of Android Studio projects.

导入向导生成导入摘要。txt文件包含可能遇到的任何问题的详细列表,以及为解决这些问题而采取的行动。您应该仔细阅读它,因为如果您在构建或运行导入的代码时遇到问题,它可能提供有关正在发生什么的线索。它还将帮助您发现导入器移动的东西,以适应Android Studio项目的不同结构。

If all does not go well, then have at look at these possible problems that you may encounter, along with solutions for those problems:

如果一切都不顺利,那么看看你可能遇到的这些问题,以及解决这些问题的办法:

Generally speaking, there are two main kinds of problems that I encountered:

总的来说,我遇到的主要有两种问题:

  1. Proguard problems
  2. 混淆器问题
  3. Manifest problems
  4. 明显的问题

When Proguard is messed up, the (obfuscated) names of methods in your libraries may not match the names being used to invoke them from your app, and you will get compiler errors like "error: cannot find symbol class ..."

当Proguard出错时,库中的(模糊的)方法名称可能与用于从应用程序调用它们的名称不匹配,您将得到编译器错误,如“error:找不到符号类…”

In Eclipse, Proguard stuff is pretty much ignored for library projects, with the Proguard stuff for any app project that you are building determining the obfuscation, etc. for not just itself, but for processing all of the libraries on which it depends. And that is generally what you want.

在Eclipse中,对库项目来说,Proguard的内容几乎被忽略了,对于您正在构建的任何应用程序项目来说,Proguard的内容决定了混淆,等等。这就是你想要的。

In Android Studio, however, you need to make some changes to attain this same effect. Basically, in the build.gradle files for each of your library project modules, you will want something like this:

然而,在Android Studio中,您需要做一些更改以获得相同的效果。基本上,在构建。每个库项目模块的等级文件,您将需要如下内容:

buildTypes {
    release {
        minifyEnabled false
        consumerProguardFiles 'proguard.cfg'
    }
}

Where proguard.cfg is your library module's own proguard configuration file.

混淆器的地方。cfg是库模块自己的proguard配置文件。

The term "consumer" in "consumerProguardFiles" apparently refers to the app module that is using this library module. So the proguard commands from that app are used in preference to those of the library module itself, and apparently this results in obfuscations that are coordinated and compatible, so that all calls from the app module to its library modules are made with matching symbols.

“consumerProguardFiles”中的术语“consumer”显然指的是正在使用这个库模块的应用程序模块。因此,该应用程序的proguard命令优先于库模块本身的命令,显然,这导致了协调和兼容的混淆,因此,从应用程序模块到库模块的所有调用都使用了匹配的符号。

These "consumerProguardFiles" entries are not created automatically during the import process (at least that was my own experience) so you will want to make sure to edit that into your library modules' build.gradle files if they are not created for you during importing.

这些“consumerProguardFiles”条目不会在导入过程中自动创建(至少这是我自己的经验),因此您需要确保将其编辑到库模块的构建中。如果在导入过程中没有为您创建渐变文件的话。

If you wanted to distribute your library projects separately, with obfuscation, then you would need an individual proguard file for them; I have not done this myself, and so that is beyond the scope of this answer.

如果您想要单独分发您的库项目,与混淆,那么您将需要一个单独的proguard文件;我自己没有这样做过,所以这超出了这个答案的范围。

In the app module, you will want something like this:

在app模块中,你会想要这样的东西:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles 'proguard.cfg'
    }
}

(BTW, as of this writing, while my apps are running just fine, I have not yet directly confirmed that things are actually getting obfuscated using this approach, so do check this yourself - e.g., by using a decompiler like apktool. I will be checking this later on, and will edit this answer when I get that info).

(顺便说一句,在撰写本文时,虽然我的应用程序运行良好,但我还没有直接确认使用这种方法会让事情变得混乱,所以请自己检查一下——例如,使用apktool这样的反编译器。稍后我会检查这个,当我得到那个信息时我会编辑这个答案)。

The second kind of problem is due to the fact that Eclipse pretty much ignores the manifest files for library projects when compiling an app project that uses those library projects, while in Android Studio, there is an interleaving of the two that apparently does not consistently prioritize the app's manifest over those of its libraries.

第二种问题是由于Eclipse为库项目几乎忽略了manifest文件编译应用程序时使用这些库项目的项目,而在Android工作室,有一个交叉的两个显然不一致优先考虑应用程序的清单的库。

I encountered this because I had a library manifest that listed (just for documentation purposes) an abstract Activity class as the main activity. There was a class derived from this abstract class in my app that was declared in the manifest of each app that used the library.

我遇到这种情况是因为我有一个库清单,它列出了一个抽象的活动类作为主要活动。在我的应用程序中有一个来自这个抽象类的类,它是在使用库的每个应用程序的清单中声明的。

In Eclipse, this never caused any problems, because the library manifests were ignored. But in Android Studio, I ended up with that abstract class as my activity class for the app, which caused a run-time error when the code made an attempt to instantiate that abstract class.

在Eclipse中,这不会导致任何问题,因为库清单被忽略了。但是在Android Studio中,我最终得到了抽象类作为应用程序的活动类,当代码试图实例化抽象类时,这会导致运行时错误。

You have two choices in this case:

在这种情况下你有两个选择:

  1. Use tools syntax to override specific library manifest stuff in your app manifest - for example:
  2. 使用工具语法覆盖应用程序清单中的特定库清单内容——例如:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.goalstate.WordGames.FullBoard.trialsuite"
       xmlns:tools="http://schemas.android.com/tools"
       .
       .
        <application
           tools:replace="android:name"

or,

或者,

  1. Strip out practically everything from your library modules' manifests, and rely upon the app module's manifest to provide every value. Note that you do need to have a manifest for each library module, but not much more is required than the header and a bare manifest element with just a package attribute in it.
  2. 实际上,从库模块的清单中删除所有内容,并依赖于应用程序模块的清单来提供每个值。注意,您确实需要为每个库模块提供一个manifest,但是只需要一个header和一个仅包含包属性的裸manifest元素。

I tried both and ended up with approach 2., above, as the simpler method. However, if you wanted to distribute your library modules separately, you would need to create a more meaningful manifest file that reflects each library module's own individual requirements.

我两种都试过了,结果是接近2。,作为更简单的方法。但是,如果想要单独发布库模块,则需要创建一个更有意义的清单文件,该文件反映每个库模块各自的需求。

There is probably a more "correct" way to do this which puts requirements (e.g., permissions) for each library in the library manifest itself, and allows the automatic interleaving process to combine these with those declared for the app. However, given that Eclipse ignores the manifests for libraries, it seems safer at least initially to rely entirely on the app manifests and just strip the library manifests down to the bare bones.

可能是一个有“正确”的方法将需求(例如,权限)为每个库库中的体现,并允许自动交叉过程将这些与那些宣称应用。然而,鉴于Eclipse为库,忽略了体现似乎更安全的至少一开始完全依赖应用程序清单,只带图书馆体现梗概。

Be aware that some of the project properties, and also the manifest attributes, from your Eclipse project will have been used to construct portions of your build.gradle files. Specifically, your compileSdkVersion in build.gradle is set to the project build version from the Eclipse project properties, applicationId is the package name from your app's manifest, and minSdkVersion and targetSdkVersion are also copied from the app's manifest file. The dependencies section of build.gradle comes from the library project dependencies in your project's properties.

请注意,来自Eclipse项目的一些项目属性以及manifest属性将被用于构建构建的部分。gradle文件。具体地说,就是在build中编译dkversion。gradle从Eclipse项目属性设置为项目构建版本,applicationId是应用程序清单中的包名称,minSdkVersion和targetSdkVersion也从应用程序的清单文件中复制。构建的依赖项部分。gradle来自于项目属性中的库项目依赖项。

Note that this may make some of your AndroidManifest.xml values redundant and quite possibly residual (i.e., unused). This could create confusion. My understanding is that the build.gradle values are the ones that actually have an effect, and that the manifest values like targetSdkVersion are not used any more for purposes of building. However, they may still be used by app stores such as Google Play; I don't know for certain one way or the other, so at this point I am just maintaining them in tandem.

请注意,这可能会使你的一些android显化。xml值是冗余的,而且很可能是剩余的(例如。未使用的)。这可能会造成混乱。我的理解是建造。gradle值是具有实际效果的值,并且不会再将targetSdkVersion这样的清单值用于构建目的。但是,谷歌Play等应用商店仍然可以使用;我不知道是这样还是那样,所以现在我只是把它们串联起来。

Besides the above two kinds of issue, there are more routine things like importing a project that has a project build level of 22 when you have only installed SDK level 23 in Android Studio. In that situation, it is probably better to edit your app module's build.gradle file to move compileSdkVersion from 22 (the imported value) to 23, than it would be to install the SDK for level 22, but either approach should work.

除了上述两种问题之外,还有更多的常规问题,比如当您在Android Studio中只安装了SDK 23级时,导入项目构建级别为22的项目。在这种情况下,最好编辑应用程序模块的构建。将编译后的dkversion从22(导入值)移动到23的gradle文件,要比将SDK安装到22级的文件多,但是这两种方法都应该有效。

Throughout this entire process, when something does not build properly and you make a change to try to address it, you might want to try Build / Rebuild Project and/or Tools / Android / Sync Project with Gradle Files, and/or File / Invalidate Caches/Restart, to make sure that your changes have been fully incorporated. I don't know exactly when these are truly necessary, because I don't know how much is done incrementally when you haven't yet had a successful build, but I performed them all fairly regularly as a kind of superstitious ritual, and I'm fairly certain that it helped. For example, when I got a Resources$NotFound runtime error that appeared to be from an inability to find the launch icon resource, I tried all three, and the problem was fixed.

在这整个过程中,当一些没有建立适当的和你做出改变来解决它,你可能会想尝试构建/重建项目和/或工具/ Android /同步项目Gradle文件,和/或文件/缓存失效/重启,以确保您的更改已经完全整合。我不知道确切的时间是什么时候,因为我不知道,当你还没有成功的构建时,增量是多少,但是我经常把它们作为一种迷信的仪式来进行,我相当肯定它是有帮助的。例如,当我获得一个资源$NotFound运行时错误,似乎是由于无法找到启动图标资源时,我尝试了所有三个,问题是固定的。

When you have performed the above for your first Eclipse project and have attained a successful build, then with luck, you can select your app module from the dropdown at the top of the Android Studio display to the left of the play button, then click the play button itself, then select a device or Android Virtual Device, and the app should be loaded for running.

当你已经完成了以上第一个Eclipse项目,成功构建,然后运气好的话,你可以选择你的应用模块的下拉顶部的Android工作室显示左边的播放按钮,然后单击播放按钮本身,然后选择一个设备或Android虚拟设备,应用程序应该加载运行。

Likewise, you should be able to create a signed copy of your app using the Build / Generate Signed APK feature. Note that some import-related errors may appear when running your signed copy that do not appear when using the play button, so you need to confirm that both are working before deciding that your import is complete.

同样,您应该能够使用Build / Generate signed APK特性创建应用程序的签名副本。请注意,在运行签名副本时可能会出现一些与输入相关的错误,而使用play按钮时不会出现这些错误,因此在决定导入是否完成之前,您需要确认这两个错误都在工作。

Following this, you will probably want to turn on version control. I am using git myself, but there are a number of other options available.

接下来,您可能想要打开版本控制。我自己也在使用git,但是还有其他一些选项。

Version control is mostly beyond the scope of this answer, but there are a few things that are affected by the importing process. First, in Eclipse you might have your various projects in various folders stuck all over the place, but when you import into Android Studio, all modules will be created as direct child folders of your main project folder. So if you had a separate git folder for each project in Eclipse, or for related groups of projects organized under a parent folder for each group (as I did), that is not going to translate very well to Android Studio.

版本控制主要超出了这个答案的范围,但是有一些事情会受到导入过程的影响。首先,在Eclipse中,您可能会将各种项目放在各种文件夹中,但是当您导入到Android Studio时,所有模块将被创建为主项目文件夹的直接子文件夹。因此,如果您有一个单独的git文件夹,用于Eclipse中的每个项目,或者为每个组在父文件夹下组织的相关项目组(就像我所做的那样),这将不能很好地转化为Android Studio。

My knowledge of this is limited as I have not worked with version control yet in Android Studio, so maybe there is a way around this, but it appears that all version control in Android Studio is unified at the project level, and so all of your modules will be under a single git archive.

我的知识是有限的,我还没有与版本控制Android工作室,所以也许有办法解决这个问题,但现在看来,所有版本控制Android工作室统一在项目层面,所以你所有的模块将会在一个git存档。

This means that you may need to abandon your old git archive and start fresh with a new archive for your imported source code. And that means that you will want to keep your old git archive around, so that it can be used with Eclipse to perform any needed bug fixes, etc., at least for a while. And you also will want it to preserve a history of your project.

这意味着您可能需要放弃旧的git归档文件,重新开始导入源代码的新归档文件。这意味着您将希望保留旧的git归档文件,以便至少在一段时间内将其与Eclipse一起用于执行任何所需的bug修复等等。你也会希望它能保存你项目的历史。

If you are fortunate enough to have had all of your projects organized under a single Eclipse workspace, and if you were using a single git archive for those projects, then it is possible that you might just copy your old git archive from in and under your Eclipse workspace folder to in and under your Android Studio project folder. Then, you could edit any still-relevant .gitignore items from you Eclipse project into the auto-generated .gitignore file for your Android Studio project, and let git figure out what has been changed during the importing process (and some things will have been moved around - for example, the manifest file is no longer at the top level of your module). Others have reported that git is pretty good at figuring out what has changed; I have not tried this myself.

如果你足够幸运有你所有的项目组织在一个Eclipse工作区中,如果你使用一个git归档的项目,那么很可能你会复制你的旧git存档的,在您的Eclipse工作区文件夹,在你的Android工作室项目文件夹。然后,您可以编辑任何相关.gitignore物品从你Eclipse项目自动生成.gitignore申请你的Android工作室项目,并让git在导入过程中找出改变了(和一些事情会一直移动——例如,清单文件不再是在顶层的模块)。其他人则报告说,git非常善于找出发生了什么变化;我自己还没试过。

But even if you did this, going back to a commit that precedes your move from Eclipse to Android Studio would be going back to a set of files that would only make sense from inside Eclipse. So it sounds, well, "difficult" to work with. Especially since Eclipse will still be pointing to its original set of project folders.

但是,即使您这样做了,返回到从Eclipse到Android Studio之前的提交,将返回到一组只在Eclipse中有意义的文件。听起来,嗯,很难共事。特别是由于Eclipse仍将指向其原始的项目文件夹集。

I personally had multiple git archives for my various sets of related projects, and so I decided to just make a clean break and start git over again in Android Studio. If you had to do this, it could affect your planning, because you would want to be at a very stable point in your code development before making the move in that case, since you will lose some accessibility to that older code within your version control system (e.g., ability to merge with post-import code) once you have made the move to Android Studio.

我个人拥有多个git档案,用于我的各种相关项目,所以我决定在Android Studio中重新开始git。如果你不得不这样做,它可以影响你的计划,因为你会想要在一个非常稳定的点在你的代码开发之前在这种情况下,因为你将失去一些可访问性,老的代码在您的版本控制系统(例如,能力与post-import合并代码)一旦你已经搬到Android工作室。

The part of this answer that pertains to git is partly speculative, since I have not actually worked with version control yet on my imported project files, but I wanted to include it to give some idea of the challenges, and I plan to update my answer after I have worked more with version control inside Android Studio.

这个答案的一部分属于git是部分投机,因为我还没有真正与版本控制进口项目文件,但是我想把它给一些想法的挑战,和我计划更新我的回答后我与版本控制工作在Android工作室。

#6


3  

According to http://tools.android.com/tech-docs/new-build-system/migrating-from-eclipse-projects, You have a couple of choices
- simply importing
- pre-exporting first from Eclipse.

根据http://tools.android.com/tech-docs/new-build-system/ migrating-fromeclipse -projects,您有两个选择——简单地导入——从Eclipse先导出。

Pre-exporting from eclipse may be the better choice if your project contains a lot of relationships that are Eclipse-specific. A.S. cannot 'translate' everything Eclipse can produce. If you want to continue using Eclipse as well as A.S. on this project code, this is the better choice. If you choose this method, please read the above link, there are some important pre-requisites.

Simply importing into AS will let AS 'translate' and rearrange the project, and is the recommended method, especially if you have no intention of returning to Eclipse. In this case, you let the A.S. wizard do everything and you dont need to manually generate gradle files.

如果您的项目包含许多特定于eclipse的关系,那么从eclipse预导出可能是更好的选择。A.S.不能“翻译”Eclipse能够产生的一切。如果您想在这个项目代码上继续使用Eclipse和A.S.,这是更好的选择。如果您选择这个方法,请阅读上面的链接,有一些重要的先决条件。简单地导入AS可以让AS“翻译”并重新安排项目,这是推荐的方法,尤其是当您无意返回Eclipse时。在这种情况下,您可以让A.S.向导完成所有工作,而不需要手工生成渐变文件。

#7


1  

In addition to the answer by Scott Barta above, you may still have import problems if there are references to Eclipse workspace library files, with e.g.

除了上面Scott Barta给出的答案之外,如果有对Eclipse工作区库文件的引用,例如

/workspace/android-support-v7-appcompat

being a common one.

是常见的一种。

In this case the import will halt until you provide a reference (and if you've cloned from a git repo, it probably won't be there) and even pointing to your own install (e.g. something like /android-sdk-macosx/extras/android/m2repository/com/android/support/appcompat-v7) won't be recognised and will halt the import, leaving you in no-man's land.

在这种情况下,导入将停止,直到您提供一个引用(如果您已经从一个git repo克隆,它可能不会在那里),甚至指向您自己的安装(例如/android-sdk-macosx/extras/android/m2repository/ support/appcompat-v7)将不会被识别,并将停止导入,将您留在无人的地方。

To get around this, look for refs in the project.properties or .classpath files that came in from the Eclipse project and remove/comment them out, e.g.

要解决这个问题,请在项目中查找参考文献。来自Eclipse项目的属性或.classpath文件,并将它们删除/注释掉。

<classpathentry combineaccessrules="false" kind="src" path="/android-support-v7-appcompat"/>

That will get you past the import stage and you can then add these refs in your build.gradle (Module:app) as indicated in the Android tutorial, like below:

这将使您通过导入阶段,然后您可以在构建中添加这些refs。如Android教程中所示的gradle(模块:app),如下图所示:

dependencies {
    compile 'com.android.support:appcompat-v7:22.2.0'
}

#8


1  

Here is a simpler way to migrate:

这里有一种更简单的迁移方式:

Start off with a sample Android Studio project. Open android studio and create a new project (or) just download a ‘sample’ studio project here: https://github.com/AppLozic/eclipse-to-android-studio-migration. Now, open the downloaded project in Android Studio by following the below instructions.

从一个示例Android Studio项目开始。打开android studio并创建一个新项目(或者),在这里下载一个“示例”studio项目:https://github.com/applozic/eclipse/android-studio -migration。现在,按照下面的说明在Android Studio中打开下载的项目。

Import eclipse project modules into Android Studio. Select File -> New -> Import Module Image title

将eclipse项目模块导入Android Studio。选择File ->新建->导入模块图像标题

Next, select the path of the eclipse project and import the modules. In case, if you see the message “Failed to sync Gradle project,” then click on “Install Build Tools and sync project…”

接下来,选择eclipse项目的路径并导入模块。如果您看到“未能同步Gradle项目”的消息,请单击“安装构建工具和同步项目……”

Now, remove the sample project modules by following the below simple steps:

现在,通过以下简单步骤删除示例项目模块:

Open settings.gradle and remove “include ‘:app’” Right click on “app” module and “Delete” it. Now, what we have is the Eclipse project open in Android studio with the Gradle build.

打开设置。逐步删除“include:app”右键点击“app”模块,“Delete”。现在,我们拥有的是在Android studio中开放的带有渐变构建的Eclipse项目。

Here are few other links which might help you:

这里有一些其他的链接可以帮助你:

http://developer.android.com/sdk/installing/migrate.html Source: http://www.applozic.com/blog/migrating-project-from-eclipse-to-studio/

http://developer.android.com/sdk/installing/migrate.html来源:http://www.applozic.com/blog/migrating-project-from-eclipse-to-studio/

#9


0  

Simple steps: 1.Go to Android Studio. 2.Close all open projects if any. 3.There will be an option which says import non Android Studio Projects(Eclipse ect). 4.Click on it and choose ur project Thats't it enjoy!!!

简单的步骤:1。去Android Studio。关闭所有开放项目(如果有的话)。3所示。将有一个选项说导入非Android Studio项目(Eclipse ect)。4所示。点击它,选择你的项目那不是它享受!!

#10


0  

The best way to bring in an Eclipse/ADT project is to import it directly into Android Studio. At first GO to Eclipse project & delete the *project.properties** file.After that, open the Android studio Tool & import Eclipse project(Eclipse ADT, Gradle etc).

引入Eclipse/ADT项目的最佳方法是直接将其导入Android Studio。首先进入Eclipse项目并删除*项目。* *文件属性。然后,打开Android studio工具并导入Eclipse项目(Eclipse ADT、Gradle等)。

-- Thanks and Regards

——感谢和问候

Rakesh Kumar Jha Android Developer

Rakesh Kumar Jha Android开发者

#11


0  

Stop installing android studio 3.0.1 and go back 2.3.3 ( Stable version) . Check for the stable version and you can find them a lot

停止安装android studio 3.0.1,回到2.3.3(稳定版本)。检查稳定版本,你可以找到很多

All you have to do uninstall and go back to the other version. Yes it asks to create gradle file seperately which is completely new to me!

您所需要做的就是卸载并返回到另一个版本。是的,它要求分别创建一个对我来说是全新的等级文件!

Failure is the stepping stone for success..

失败是成功的垫脚石。