简体   繁体   English

如何在Eclipse中打开Android Studio项目?

[英]How do you open an Android Studio project in Eclipse?

The new Android Studio allows for better Android development with better tools. 新的Android Studio使用更好的工具可以更好地进行Android开发。 I see a bunch of questions on how to transfer an eclipse project to android studio but what about the other way? 我看到了关于如何将Eclipse项目转移到android studio的一堆问题,但是其他方法又如何呢?

If you make an Android app in Android Studio, can you bring it back to Eclipse? 如果您在Android Studio中制作一个Android应用程序,您可以将其重新带回Eclipse吗? If so, how? 如果是这样,怎么办?

This would be needed for specific eclipse plugins, such as the Blackberry Android plugin. 特定的eclipse插件(例如Blackberry Android插件)将需要此功能。

Thank you. 谢谢。

You cannot import the project directly but it's not to hard to achieve it: 您不能直接导入项目,但要实现它并不难:

  • Create a new Android empty project in eclipse 在Eclipse中创建一个新的Android空项目
  • Overwrite the fresh res/ folder and the AndroidManifest.xml file, with the ones from the Android Studio project 使用Android Studio项目中的内容覆盖新的res /文件夹和AndroidManifest.xml文件
  • Copy the content of the java/ folder from the Android Studio project (it should contain your package name folder structure, like com/example/app/, and the java files of course) in the Eclipse src folder 从Eclipse src文件夹中复制Android Studio项目中java /文件夹的内容(它应该包含您的包名称文件夹结构,例如com / example / app /,以及Java文件)
  • Link your needed libraries if it's the case 如果是这种情况,链接所需的库

Basically the Android application fundamental elements are the java files, the manifest file and the resources. 基本上,Android应用程序的基本元素是java文件,清单文件和资源。 From there you can build back a project in your favorite IDE 从那里您可以在自己喜欢的IDE中重新构建项目

It's not possible. 这是不可能的。 We intend to add support for Gradle-based project in ADT but it's not currently possible. 我们打算在ADT中添加对基于Gradle的项目的支持,但目前尚无法实现。

Step-by-Step process to import Android Studio Project into Eclipse ... 将Android Studio项目导入Eclipse的分步过程 ...

  1. Start new Android Project in eclipse using wizard and fill following details from app/build.gradle 使用向导在eclipse中启动新的Android项目,并从app / build.gradle中填写以下详细信息

    ApplicationName and ProjectName : - You can find project name from .iml file in / folder PackageName : MinSDK, TargetSDK and CompileSDK ApplicationName和ProjectName:-您可以从/ im文件夹中的.iml文件中找到项目名称。PackageName:MinSDK,TargetSDK和CompileSDK

  2. Click Next in the wizard and make sure that you have "unchecked" ' Create Activity ' and " Create Custom Icon" . 在向导中单击“下一步”,并确保您已“取消选中”“ 创建活动 ”和“ 创建自定义图标” Click Finish. 单击完成。

  3. Open AndroidManifest.xml file in new created project. 在新创建的项目中打开AndroidManifest.xml文件。 Copy "application", "uses-permission" etc tags as is from app/src/main/AndroidManifest.xml 从app / src / main / AndroidManifest.xml复制“ application”,“ uses-permission” 标签

  4. Source Files : Replace all contents in AndroidStudio/app/src/main/java to Eclipse//src folder. 源文件:将AndroidStudio / app / src / main / java中的所有内容替换为Eclipse // src文件夹。

  5. Resource Files : Replace all contents in AndroidStudio/app/src/main/res to Eclipse//res folder. 资源文件:将AndroidStudio / app / src / main / res中的所有内容替换为Eclipse // res文件夹。

  6. Library files : Copy all libs from AndroidStudio/app/libs to Eclipse//libs folder. 库文件:将所有库从AndroidStudio / app / libs复制到Eclipse // libs文件夹。

  7. Dependency Library : Import and Add AppCompact as a dependent library using Properties->Android->Library->Add 依赖库:使用Properties-> Android-> Library-> Add将AppCompact导入并添加为依赖库

  8. Resolve any errors to build. 解决任何要构建的错误。 Clean and Build again as a last step. 最后清洁并重新构建。

  9. You may not be able to deploy it directly onto a phone but you can find .apk file generated in bin folder. 您可能无法将其直接部署到手机上,但可以在bin文件夹中找到生成的.apk文件。

UPDATE: see One Android project for Eclipse and Android Studio 更新:请参阅针对Eclipse和Android Studio的一个Android项目

Currently if you create Android project in Android Studio you will have hard times opening it in Eclipse. 当前,如果您在Android Studio中创建Android项目,则很难在Eclipse中打开它。 (However opening classic Android with added build.gradle in Android Studio should be easier) (但是在Android Studio中打开带有添加build.gradle经典Android会更容易)

So you can open (as general project) and then convert some modules into Eclipse project, but still it will not be fully functional (but for a quick view inside may suffice) 因此,您可以打开(作为常规项目),然后将一些模块转换为Eclipse项目,但仍然不能完全正常工作(但对于内部的快速浏览可能就足够了)

from How to use Gradle to generate Eclipse and Intellij project files for Android projects 来自如何使用Gradle为Android项目生成Eclipse和Intellij项目文件

As answered in Issue 57668 by Android team (raised by @arcone) 如Android团队在问题57668中所回答(由@arcone提出)

Project Member #2 x...@android.com 项目成员#2 x ... @ android.com

The eclipse plugin is not compatible with the android plugin. eclipse插件与android插件不兼容。

You will not be able to import an Android gradle project into Eclipse using the default Gradle support in Eclipse. 您将无法使用Eclipse中的默认Gradle支持将Android gradle项目导入Eclipse。

To make it work in Eclipse we will have to change the Gradle plugin for Eclipse, the same way we are modifying the Gradle support in IntelliJ 为了使其在Eclipse中工作,我们必须更改Eclipse的Gradle插件,就像我们在IntelliJ中修改Gradle支持一样

That is Android team is working on gradle plugin for IntelliJ and gradle plugin for Eclipse needs to be updated too. 也就是说,Android团队正在开发IntelliJ的gradle插件,而Eclipse的gradle插件也需要更新。

What is possible with Eclipse now is 现在,Eclipse可以实现的是

THIS IS OUTDATED, see How to import Android Studio project in Eclipse? 这已过时,请参阅如何在Eclipse中导入Android Studio项目?

.1. .1。 import the project as general project 将项目导入为普通项目

.project

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

导入android-gradle-general-project

.2. .2。 Put 2 Eclipse . 放入2个Eclipse。 "dot" files into modules into /OpenSpritz-Android/app/src/main and /OpenSpritz-Android/lib/src/main 将“点”文件放入/OpenSpritz-Android/app/src/main/OpenSpritz-Android/lib/src/main

蚀文件

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>OpenSpritz-Android-app</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

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="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>

.3. .3。 Import as Existing Android Code into Workspace 作为现有的Android代码导入到工作区

结果

you can then browse code in familiar way, but even after that you won't be able to run with Eclipse ADT. 您可以用熟悉的方式浏览代码,但是即使那样,您也将无法使用Eclipse ADT运行。

.4. .4。

Now you can run build and tasks with gradle CLI or Nodeclipse/Enide Gradle for Eclipse ( marketplace ) 现在,您可以使用gradle CLI或Nodeclipse / Enide Gradle for Eclipse市场 )运行构建和任务

开始

discuss at https://github.com/Nodeclipse/nodeclipse-1/issues/148 https://github.com/Nodeclipse/nodeclipse-1/issues/148上讨论

Also answered in Can't run imported gradle android project in Eclipse 无法在Eclipse中运行导入的Gradle Android项目中也得到了解答

Import project then Properties > java build path > source tab....remove path to src....add path to java folder in the source code using add folde rbutton... then build your project as usual 导入项目,然后导入属性> Java构建路径>源选项卡。...删除src的路径。...使用add folde rbutton在源代码中添加Java文件夹的路径...然后照常构建项目

配置源代码所在的Java文件夹的路径

我认为,如果没有太多的手工工作,就不可能导入Eclipse的android studio项目。

I really miss the automatic build feature in Eclipse but also hate the speed and bugs in Eclipse for Mac. 我真的很想念Eclipse中的自动构建功能,但也讨厌Eclipse for Mac中的速度和错误。 It would be nice to have the best of both worlds. 最好两全其美。 The project layout in Eclipse and Android Studio has a lot in difference and I guess it would be very difficult if not impossible to change the default layout. Eclipse和Android Studio中的项目布局有很多不同,我想即使不是不可能更改默认布局也将非常困难。 Therefore, I tried to create an empty Android project in Eclipse. 因此,我试图在Eclipse中创建一个空的Android项目。 Then I deleted the physical folders and files and created linked resources to reference those in the Android Studio project and voila! 然后,我删除了物理文件夹和文件,并创建了链接资源以引用Android Studio项目中的内容,瞧! It works. 有用。

Here is my resource mapping: 这是我的资源映射:

AS-Project/app/src/main/AndroidManifest.xml -> Eclipse-Project/AndroidManifest.xml  
AS-Project/app/src/main/res                 -> Eclipse-Project/res  
AS-Project/app/src/main/assets              -> Eclipse-Project/assets  
AS-Project/app/src/main/java                -> Eclipse-Project/src    
AS-Project/app/libs                         -> Eclipse-Project/libs-as  

Linked folder doesn't quite work for the "libs" folder. 链接文件夹不适用于“ libs”文件夹。 So I mapped it to a folder called "libs-as" and manually added the JARs to project build path. 因此,我将其映射到名为“ libs-as”的文件夹,并手动将JAR添加到项目构建路径。 In the worst case I guess you could maintain two separate libs folders. 在最坏的情况下,我想您可以维护两个单独的libs文件夹。

Eclipse项目布局

PS It would be a good idea to put two projects side by side and use location variables to reference relative paths (eg ${PARENT-1-PROJECT_LOC}) PS最好将两个项目并排放置,并使用位置变量来引用相对路径(例如$ {PARENT-1-PROJECT_LOC})

I just published a project that requires to work for Android Studio or Eclipse users. 我刚刚发布了一个项目,该项目要求适用于Android Studio或Eclipse用户。 It's basically an Android Studio project, but I provided a gradle build file that developers can use to convert it to Eclipse. 这基本上是一个Android Studio项目,但我提供了gradle构建文件 ,开发人员可以使用该文件将其转换为Eclipse。

Basically developers would have to run the following command to convert the project to Eclipse: 基本上,开发人员必须运行以下命令才能将项目转换为Eclipse:

gradle -b eclipse.gradle eclipse

Here are the contents of eclipse.gradle: 以下是eclipse.gradle的内容:

 apply plugin: 'java' apply plugin: 'eclipse' buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' } } allprojects { repositories { jcenter() mavenCentral() } } // Add the natures and build commands to the project eclipse.project { natures 'com.android.ide.eclipse.adt.AndroidNature' natures 'org.eclipse.jdt.core.javanature' buildCommands.clear(); buildCommand 'com.android.ide.eclipse.adt.ResourceManagerBuilder' buildCommand 'com.android.ide.eclipse.adt.PreCompilerBuilder' buildCommand 'org.eclipse.jdt.core.javabuilder' buildCommand 'com.android.ide.eclipse.adt.ApkBuilder' } // The source code is in the java folder sourceSets.main.java.srcDirs 'java' dependencies { // declare your dependencies here } 

Hope this helps 希望这可以帮助

Adding step-by-step procedure. 添加分步过程。 1. Install gradle . 1.安装gradle Note that if you have Android Studio you already have gradle. 请注意,如果您拥有Android Studio,那么您已经有了gradle。 2. Create an eclipse.gradle file in the root folder of your Android Studio project and copy the contents of the eclipse.gradle mentioned above. 2.在您的Android Studio项目的根文件夹中创建eclipse.gradle文件,然后复制上述eclipse.gradle的内容。 3. Open a command prompt or terminal and run gradle -b eclipse.gradle 4. Try to open in Eclipse 3.打开命令提示符或终端,然后运行gradle -b eclipse.gradle。4.尝试在Eclipse中打开

The published answer worked for me, but only after some mis-steps due to my inexperience with these IDEs. 已发布的答案对我有用,但是仅由于我对这些IDE的经验不足,才出现一些错误。 For any other beginner be careful with these ... 对于任何其他初学者,请谨慎使用这些...

  1. use the same minimum, target and build SDKs 使用相同的最低,目标和构建SDK
  2. use the exact same project name, and watch the sequence of project directories based on the package name, for the correct location of the .java file[s] 使用完全相同的项目名称,并根据包名称监视项目目录的顺序,以获取.java文件的正确位置
  3. for the /res folder copy over missing directories / res文件夹复制到丢失的目录中
  4. edit [i used NotePad] all matching xml files, carefully choosing the correct mix of entries, some from each 编辑[我使用NotePad]所有匹配的xml文件,仔细选择条目的正确组合,每个条目中的一些

After this there may still be some errors to contend with, but with some persistence you should be able to correct them. 在此之后,仍然可能有一些错误需要解决,但是通过一些持久性,您应该能够纠正它们。

It's quite simple if you know the trick. 如果知道诀窍,这很简单。

  • Replace the eclipse project Res folder with Android studio project's res folder. 将eclipse项目Res文件夹替换为Android Studio项目的res文件夹。

  • Go inside java folder and copy all folders and paste inside src folder of eclipse project. 进入java文件夹并复制所有文件夹,然后粘贴到eclipse项目的src文件夹中。

  • Open Android manifest of android studio project, copy all of the content and paste it in eclipse projects manifest. 打开android studio项目的Android清单,复制所有内容并将其粘贴到eclipse项目清单中。

  • clean and run the project. 清理并运行项目。

Simple way to move project from android studio to eclipse. 将项目从android studio移动到Eclipse的简单方法。

1) Import project in eclipse .There is no file in src folder in these project. 1)在eclipse中导入项目。这些项目的src文件夹中没有文件。

2) Go to the java folder that is available in folder stucture which you imported in eclipse. 2)转到在eclipse中导入的文件夹结构中可用的java文件夹。 Copy the folder which is inside java it would be most of the time started from 'com' and paste in source 'src' folder . 复制Java里面的文件夹,通常大部分时间是从'com'开始的,然后粘贴到源'src'文件夹中。

Now you can compile your projrct it would work. 现在您可以编译您的项目了。 if your project require third party libs then add the required file also. 如果您的项目需要第三方库,则还添加所需的文件。

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

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