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

时间:2023-01-22 12:36:44

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.

谢谢。

7 个解决方案

#1


14  

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/changing-general-project-to-java-project/

#2


75  

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
  • 关闭eclipse
  • Open the .project file in your project
  • 在项目中打开.project文件。
  • Make the natures section look like:

    让自然部分看起来像:

    <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 maven you can configure the project's nature in your pom, see the maven eclipse plugin doc

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

#3


21  

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”。项目”文件

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

Add a simple "AndroidManfest.xml"

添加一个简单的“AndroidManfest.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

添加一个”项目。属性”文件

target=android-7
android.library=true
  • Create an empty folder off the root of the project for called: "res"
  • 在项目的根目录下创建一个空文件夹,称为“res”
  • Refresh in Eclipse
  • 在Eclipse中刷新
  • Right click on project, select Android Tools, Fix Project Properties Rebuild
  • 右键单击项目,选择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构建路径/项目

#4


1  

I met the same problem. Here are my steps:

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

  • create an new android project
  • 创建一个新的android项目。
  • copy .project, .classpath files into the plain old Java project
  • 将.project、.classpath文件复制到普通的旧Java项目中
  • 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.
  • 在eclipse中刷新纯旧Java项目,然后右键单击纯旧Java项目时,“Android工具”将出现在上下文菜单中。
  • "Android Tools" | "fix Project Properties"
  • "Android Tools" | "fix Project Properties"

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将把“Android资源管理器”、“Android预编译器”和“Android包构建器”添加到“构建器”中,并很快编译项目,创建“gen”文件夹BuildConfig。java和参数。

done.

完成了。

#5


1  

My solution is:

我的解决方案是:

  1. Copy an AndroidManifest.xml and project.properties file to the root directory of this project.
  2. 复制一个AndroidManifest。xml和项目。属性文件到此项目的根目录。
  3. Click "File" -> "Import", choose "Android" -> "Existing Android Code Into Workspace".
  4. 点击“File”->“Import”,选择“Android”->“现有Android代码进入工作空间”。
  5. Configure proper source code path and Android Lib version.
  6. 配置适当的源代码路径和Android Lib版本。

#6


0  

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项目,但如果不是,我建议按照描述构建一个新的库项目,然后将您的代码移动到它。

#7


0  

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

#1


14  

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/changing-general-project-to-java-project/

#2


75  

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
  • 关闭eclipse
  • Open the .project file in your project
  • 在项目中打开.project文件。
  • Make the natures section look like:

    让自然部分看起来像:

    <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 maven you can configure the project's nature in your pom, see the maven eclipse plugin doc

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

#3


21  

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”。项目”文件

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

Add a simple "AndroidManfest.xml"

添加一个简单的“AndroidManfest.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

添加一个”项目。属性”文件

target=android-7
android.library=true
  • Create an empty folder off the root of the project for called: "res"
  • 在项目的根目录下创建一个空文件夹,称为“res”
  • Refresh in Eclipse
  • 在Eclipse中刷新
  • Right click on project, select Android Tools, Fix Project Properties Rebuild
  • 右键单击项目,选择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构建路径/项目

#4


1  

I met the same problem. Here are my steps:

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

  • create an new android project
  • 创建一个新的android项目。
  • copy .project, .classpath files into the plain old Java project
  • 将.project、.classpath文件复制到普通的旧Java项目中
  • 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.
  • 在eclipse中刷新纯旧Java项目,然后右键单击纯旧Java项目时,“Android工具”将出现在上下文菜单中。
  • "Android Tools" | "fix Project Properties"
  • "Android Tools" | "fix Project Properties"

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将把“Android资源管理器”、“Android预编译器”和“Android包构建器”添加到“构建器”中,并很快编译项目,创建“gen”文件夹BuildConfig。java和参数。

done.

完成了。

#5


1  

My solution is:

我的解决方案是:

  1. Copy an AndroidManifest.xml and project.properties file to the root directory of this project.
  2. 复制一个AndroidManifest。xml和项目。属性文件到此项目的根目录。
  3. Click "File" -> "Import", choose "Android" -> "Existing Android Code Into Workspace".
  4. 点击“File”->“Import”,选择“Android”->“现有Android代码进入工作空间”。
  5. Configure proper source code path and Android Lib version.
  6. 配置适当的源代码路径和Android Lib版本。

#6


0  

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项目,但如果不是,我建议按照描述构建一个新的库项目,然后将您的代码移动到它。

#7


0  

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