简体   繁体   English

如何在Eclipse中导入Android Studio项目?

[英]How to import Android Studio project in Eclipse?

我已经在Android Studio中创建了一个项目,现在我想将该项目导入Eclipse,有将eclipse转换为Android Studio的选项,但是如何将Android studio转换为Eclipse?

As the others say, a full import is not possible, but just try a manual 'import'. 正如其他人所说,完全导入是不​​可能的,但只需尝试手动“导入”。 The key files for an Android project are the Java sourcecode (src directory), the resource XML files and the Manifest. Android项目的关键文件是Java源代码(src目录),资源XML文件和Manifest。 Just create a new Android project in Eclipse and simply copy these files over. 只需在Eclipse中创建一个新的Android项目,然后只需复制这些文件即可。 You may have to create a new package structure, so construct the necessary packages and copy each sourcefile over and refactor the package name if necessary. 您可能必须创建一个新的包结构,因此构造必要的包并复制每个源文件,并在必要时重构包名。 If you use any additional libraries, you may have to manually import them as well. 如果您使用任何其他库,则可能还必须手动导入它们。

IMPORTING FROM ANDROID STUDIO INTO ECLIPSE 从ANDROID STUDIO进入ECLIPSE

http://www.nodeclipse.org/projects/gradle/android/Importing-from-Android-Studio-into-Eclipse describes steps needed http://www.nodeclipse.org/projects/gradle/android/Importing-from-Android-Studio-into-Eclipse描述了所需的步骤

http://www.nodeclipse.org/projects/gradle/MyApplicationName.PNG http://www.nodeclipse.org/projects/gradle/MyApplicationName.PNG

http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile-symlink-done.PNG http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile-symlink-done.PNG

Copy-paste here as of September 2014 复制粘贴到2014年9月


welcome to raise issue on GitHub . 欢迎在GitHub上提出问题。

First, it is easier to create project with Eclipse-ADT, add build.gradle and import into Android Studio by selecting that build.gradle , then other way around. 首先,使用Eclipse-ADT创建项目更容易,添加build.gradle并通过选择build.gradle导入到Android Studio,然后以其他方式。

Single-project 单项目

see step 2 below 见下面的第2步

Multi-project 多项目
  1. Add .project file into root .project文件添加到root中

<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>MyApplicationName</name> <comment></comment> <projects> </projects> <buildSpec> </buildSpec> <natures> </natures> </projectDescription>

(you can also use Nodeclipse CLI ) eg from froject root C:\\Users\\username\\AndroidStudioProjects\\MyApplicationName run nodeclipse -g (你也可以使用Nodeclipse CLI )例如来自froject root C:\\Users\\username\\AndroidStudioProjects\\MyApplicationName运行nodeclipse -g

Copy that path (eg in Android Studio "Copy Path" Ctrl+Shift+C ), 复制该路径(例如在Android Studio“复制路径”中按Ctrl + Shift + C ),
in Eclipse File -> Import -> General / Existing Project into workspace 在Eclipse File - > Import - > General / Existing Project into workspace中

http://www.nodeclipse.org/projects/gradle/MyApplicationName.PNG http://www.nodeclipse.org/projects/gradle/MyApplicationName.PNG

At this point, you don't really need to have ADT. 此时,您实际上并不需要ADT。 Eclipse is like Viewer, but you already can launch Gradle build , installDebug or run on Device (when you have defined run task) Eclipse就像Viewer,但您已经可以启动Gradle buildinstallDebug或在Device上运行(当您定义了run任务时)

Further operation you can do within Eclipse 您可以在Eclipse中进行进一步操作

  1. For every module (as mobile or wear ) do 对于每个模块(如mobilewear

2.1 Add 2 standard .files for Android project as below (you can get them by creating new project with Eclipse-ADT, only need to change "src" path="src/main/java" ): 2.1为Android项目添加2个标准.files如下(您可以通过使用Eclipse-ADT创建新项目来获取它们,只需要更改"src" path="src/main/java" ):

  • .project : .project

<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>MyApplicationName-mobile</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>com.android.ide.eclipse.adt.ApkBuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription>

  • .classpath : .classpath

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" path="gen"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> <classpathentry kind="output" path="bin/classes"/> </classpath>

http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile.PNG http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile.PNG

2.2 create OS symbolic links 2.2创建OS符号链接

On Lunix 在伦尼克斯

 ln -s src/main/res res ln -s src/main/AndroidManifest.xml AndroidManifest.xml 

On Windows I don't yet know grace way that would work always: 在Windows上,我还不知道总是会有效的优雅方式:

symbolic links on Windows Windows上的符号链接

 mklink /D res src/main/res mklink AndroidManifest.xml src/main/AndroidManifest.xml 

Windows 7 has mklink util , but it just did not work on my PC. Windows 7有mklink util ,但它在我的电脑上无法正常工作。

I found a great Junction util and could do junction res src/main/res , but for link to file is created .lnk file (aka Windows shortcut). 我找到了一个很棒的Junction util ,可以做junction res src/main/res ,但是为了链接到文件创建了.lnk文件(又名Windows快捷方式)。

I discovered that Git Bash can execute ln -s src/main/AndroidManifest.xml AndroidManifest.xml but it creates copy, not link. 我发现Git Bash可以执行ln -s src/main/AndroidManifest.xml AndroidManifest.xml但它创建副本,而不是链接。

http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile-symlink.PNG http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile-symlink.PNG

2.3 Add gen folder 2.3添加gen文件夹

2.4 add project.properties 2.4添加project.properties

target=android-15

2.5 Import as existing project 2.5作为现有项目导入

click on mobile , Ctrl+Alt+C 点击mobile按Ctrl + Alt + C.
File -> Import -> General / Existing Project into workspace 文件 - >导入 - >常规/现有项目进入工作区

http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile-symlink-done.PNG http://www.nodeclipse.org/projects/gradle/MyApplicationName-mobile-symlink-done.PNG

DONE. DONE。

Of course limitations are: 当然限制是:

  • Eclipse is still using ADT to build Eclipse仍然使用ADT来构建
  • dependencies added via gradle are not visible to ADT (but jars in libs folder are shared of course) 通过gradle添加的依赖项对ADT不可见(但libs文件夹中的jar当然是共享的)

Good things are: 好东西是:

  • you can use more stable Eclipse ADT for developing and debugging 您可以使用更稳定的Eclipse ADT进行开发和调试
  • at the same time you can use and/or experiment with new build system in the same IDE as second one. 同时,您可以在与第二个IDE相同的IDE中使用和/或试验新的构建系统

http://www.nodeclipse.org/projects/gradle http://www.nodeclipse.org/projects/gradle

try install the gradle plugin in the eclipse. 尝试在eclipse中安装gradle插件。 THis will work for some apps. 这适用于某些应用。

The following update sites are available: 以下更新站点可用:

http://dist.springsource.com/milestone/TOOLS/gradle (latest milestone build) http://dist.springsource.com/release/TOOLS/gradle (latest release) Pasting the above URLs into a web browser will not work. http://dist.springsource.com/milestone/TOOLS/gradle (最新里程碑版本) http://dist.springsource.com/release/TOOLS/gradle (最新版本)将上述URL粘贴到Web浏览器中将无法正常工作。 You need to follow the instructions given below to use an Eclipse update site. 您需要按照下面给出的说明使用Eclipse更新站点。

In Eclipse Open Help >> Install New Software Paste a Gradle update site link into the "Work with" text box. 在Eclipse中打开帮助>>安装新软件将Gradle更新站点链接粘贴到“使用”文本框中。 Click the Add button at the top of the screen. 单击屏幕顶部的“添加”按钮。 Ensure that the option "Group Items by Category" is enabled. 确保启用“按类别分组项目”选项。 Select the top-level node 'Extensions / Gradle Integration'. 选择顶级节点“Extensions / Gradle Integration”。 Click "Next". 点击下一步”。 This may take a while. 可能还要等一下。 Review the list of software that will be installed. 查看将要安装的软件列表。 Click "Next" again. 再次单击“下一步”。 Review and accept licence agreements and Click "Finish". 查看并接受许可协议,然后单击“完成”。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM