将现有项目转换为 Eclipse 中的 Android 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2959820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:03:21  来源:igfitidea点击:

Convert existing project into Android project in Eclipse?

androideclipse

提问by hpique

How do you convert an existing project into an Android project in Eclipse?

在 Eclipse 中如何将现有项目转换为 Android 项目?

In particular, I want to convert a plain old Java project into an Android Library project.

特别是,我想将一个普通的旧 Java 项目转换为一个 Android 库项目。

Thanks.

谢谢。

采纳答案by Uri

What subsystem/plugin are you using for Eclipse Android development?

您在 Eclipse Android 开发中使用什么子系统/插件?

Generally speaking, the process is called "changing the project nature" e.g.,

一般来说,这个过程被称为“改变项目性质”,例如,

http://enarion.net/programming/tools/eclipse/changing-general-project-to-java-project/

http://enarion.net/programming/tools/eclipse/changed-general-project-to-java-project/

回答by hennr

You need to change the nature of the project (this has already been answered, but nobody gave the actual string you need for that.)

您需要更改项目的性质(这已经得到回答,但没有人提供您需要的实际字符串。)

  • Close eclipse
  • Open the .project file in your project
  • Make the natures section look like:

    <natures>
        <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
    
  • 关闭日食
  • 在您的项目中打开 .project 文件
  • 使性质部分看起来像:

    <natures>
        <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
    

Start eclipse again, have fun.

再次开始eclipse,玩得开心。

Note: If you are using mavenyou can configure the project's nature in your pom, see the maven eclipse plugin doc

注意:如果您使用的是maven,您可以在 pom 中配置项目的性质,请参阅maven eclipse 插件文档

回答by raider33

I had an app that was built with Eclipse 3.5 and used java projects instead of properly built Android Library projects. I'm not sure how it originally worked (the app was published and worked fined), but I couldn't get it to run when I tried setting up a dev environment on a different machine. I keep getting ClassNotFoundExceptions for references to the Java project.

我有一个使用 Eclipse 3.5 构建的应用程序,并使用 java 项目而不是正确构建的 Android 库项目。我不确定它最初是如何工作的(该应用程序已发布并正常运行),但是当我尝试在另一台机器上设置开发环境时,我无法让它运行。我不断收到 ClassNotFoundExceptions 以引用 Java 项目。

Since I had a couple years of check-in history, I really didn't want to move projects as some answers stated. For me, converting the Java project into a proper Android Library made more sense.

由于我有几年的签入历史,我真的不想像某些答案所说的那样移动项目。对我来说,将 Java 项目转换为合适的 Android 库更有意义。

Here are the steps I had to take to get it working:

以下是我必须采取的步骤才能使其正常工作:

Add AndroidNature to ".project" file

将 AndroidNature 添加到“.project”文件

<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>

Add a simple "AndroidManifest.xml"

添加一个简单的“AndroidManifest.xml”

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.convertproject.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
</manifest>

Add a "project.properties" file

添加“project.properties”文件

target=android-7
android.library=true
  • Create an empty folder off the root of the project for called: "res"
  • Refresh in Eclipse
  • Right click on project, select Android Tools, Fix Project Properties Rebuild
  • 在项目根目录下创建一个空文件夹,名为:“res”
  • 在 Eclipse 中刷新
  • 右键单击项目,选择 Android 工具,修复项目属性重建

NOTE:when you add library to your main project, import using the Android / Libray tab (under project properties) instead of Java Build Path / Projects

注意:当你将库添加到你的主项目时,使用 Android / Libray 选项卡(在项目属性下)而不是 Java Build Path / Projects 导入

回答by joeaniu

I met the same problem. Here are my steps:

我遇到了同样的问题。这是我的步骤:

  • create an new android project
  • copy .project, .classpath files into the plain old Java project
  • refresh the plain old Java project in eclipse, and then the "Android Tools" appears at context menu when you right click the plain old Java project.
  • "Android Tools" | "fix Project Properties"
  • 创建一个新的安卓项目
  • 将 .project、.classpath 文件复制到普通的旧 Java 项目中
  • 在 Eclipse 中刷新普通的旧 Java 项目,然后当您右键单击普通的旧 Java 项目时,上下文菜单中会出现“Android 工具”。
  • “安卓工具” | “修复项目属性”

In the last step, Eclipse will add "Android Resource Manager", "Android Pre Compiler" and "Android Package Builder" into "Builders" and soon compile the project, create the "gen" folder, BuildConfig.java and R.java.

在最后一步,Eclipse 会在“Builders”中添加“Android Resource Manager”、“Android Pre Compiler”和“Android Package Builder”并很快编译项目,创建“gen”文件夹、BuildConfig.java 和 R.java。

done.

完毕。

回答by peacepassion

My solution is:

我的解决办法是:

  1. Copy an AndroidManifest.xml and project.properties file to the root directory of this project.
  2. Click "File" -> "Import", choose "Android" -> "Existing Android Code Into Workspace".
  3. Configure proper source code path and Android Lib version.
  1. 将 AndroidManifest.xml 和 project.properties 文件复制到该项目的根目录。
  2. 点击“文件”->“导入”,选择“Android”->“现有Android代码到工作区”。
  3. 配置正确的源代码路径和 Android Lib 版本。

回答by JRL

Are you aware of this guide?

你知道这个指南吗?

I don't know if there's a way to convert an existing Java project, but if not I'd suggest building a new library project as described and then moving your code to it.

我不知道是否有办法转换现有的 Java 项目,但如果没有,我建议按照描述构建一个新的库项目,然后将代码移动到它。

回答by Archimedes Trajano

If I have to convert I usually just create a new project and copy the files in there.

如果我必须转换,我通常只创建一个新项目并复制其中的文件。

If I took the time to do it properly, it would've been a Mavenized project which I can just import. You can look at my app to help you get some ideas. https://github.com/trajano/GasPrices

如果我花时间正确地完成它,它将是一个我可以导入的Mavenized项目。您可以查看我的应用程序以帮助您获得一些想法。 https://github.com/trajano/GasPrices