如何将现有的Java源项目添加到Android Studio

如何将现有的Java源项目添加到Android Studio

问题描述:

我有一个现有的纯Java代码git存储库,我想将其添加到我的Android项目中.

I have an existing git repository of pure Java code that I would like to add to my Android project.

我不想更改任何现有文件.我想保留现有的程序包名称,以简化对旧代码的维护.

I don't want to change any of the existing files. I want to keep my existing package names to simplify the maintenance of my legacy code.

在Eclipse中,您只需将现有项目的根目录添加到Java Build Path中即可.

In Eclipse, you can simply add the root of the existing project to your Java Build Path.

如何在Android Studio中执行相同的操作?

How to do the same in Android Studio?

我的解决方案是将Java项目导出到JAR.

My solution to this was to Export my Java project to a JAR.

然后,我将JAR添加到Android Studio项目中.文件">项目结构"将显示以下窗口:

And then, I added the JAR to the Android Studio project. File > Project Structure leads to this window:

那样,我可以原样使用我的文件.

That way, I could use my files untouched as such.

我对这种解决方案不太满意,因为它破坏了我的版本控制系统.

I am not so happy with this solution because it breaks my revision control system.