简体   繁体   English

在Android项目中导入源java项目

[英]Import source java project in Android project

Is it possible to import an existing Java project which is in my workspace, in an Android project which is also in my workspace? 是否可以导入我工作区中的现有Java项目,也在我的工作区中的Android项目中? The Java project doesn't use stuff that is incompatible with Android. Java项目不使用与Android不兼容的东西。 I could do it using a .JAR, but since I'm modifying the Java project a lot, I would like to import the whole source code and change it once in a while. 我可以使用.JAR来做,但由于我正在修改Java项目,我想导入整个源代码并偶尔更改一次。 Is it possible? 可能吗? Thanks 谢谢

This is somewhat of a hack, but worked for my project: 这有点像黑客,但对我的项目有用:

  1. Add both Android project and plain Java project to workspace 将Android项目和普通Java项目添加到工作区
  2. Go to properties for Android project -> Java Build Path -> Source 转到Android项目的属性 - > Java Build Path - > Source
  3. Click Link Source, in "Folder name", make sure to select the root directory of the plain Java project's src tree 单击“链接源”,在“文件夹名称”中,确保选择普通Java项目的src树的根目录
  4. Use a descriptive name for "Linked folder location", like "java_project_src". 使用“链接文件夹位置”的描述性名称,如“java_project_src”。
  5. Press Finish and compile 按Finish并编译

This setup will compile the plain-java code as Dalvik bytecode. 此设置将plain-java代码编译为Dalvik字节码。 In my case, I had pure java code with very limited dependencies, but wanted to share the pure java code with non-Android projects, instead of separately maintaining these files in every project. 在我的例子中,我有纯粹的java代码,依赖性非常有限,但是想要与非Android项目共享纯Java代码,而不是在每个项目中单独维护这些文件。

我认为您正在谈论将其他项目引用到当前项目中,如果是这种情况,那么您可以通过右键单击项目,属性 - >项目参考来完成此操作

You can link another projects to your current project. 您可以将其他项目链接到当前项目。 Right click on your main project, choose Build Path -> Configure Build Path... In the dialog choose the Projects tab, then click Add.. button. 右键单击主项目,选择Build Path -> Configure Build Path...在对话框中选择Projects选项卡,然后单击Add..按钮。 Now choose the project you want to link and click OK . 现在选择要链接的项目,然后单击“ OK You'll now be able to use this project's sources inside your main project. 您现在可以在主项目中使用此项目的源代码。 Hope this helps. 希望这可以帮助。

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

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