Eclipse的Andr​​oid项目,如何引用库中的工作区? [英] Eclipse Android project, how to reference library within workspace?

查看:112
本文介绍了Eclipse的Andr​​oid项目,如何引用库中的工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟一些措施,我发现在这里(无法找到URL现在,对不起)我的Andr​​oid项目转换在Eclipse中的布局,其中99.9%的我的code是在一个库项目,然后我有在同一个工作区是大多只是在AndroidManifest.xml中的文件2等壳项目,以及一些资源文件。这样做,所以我可以支持2个建立在同一个项目中,只用2应用程序的名称也不同,所以我可以在同一时间在Android Market上发布两个。之间有一些小的文本/图标修改

I followed some steps I found here (can't find the URL right now, sorry) to convert my Android project in Eclipse to a layout where 99.9% of my code is in a library project, and then I have 2 other shell projects under the same workspace that are mostly just the AndroidManifest.xml files, and a few resource files. This was done so I can support 2 builds of the same project, with just some minor text/icon changes between the 2. The application name is also different so I can publish both on the Android Market at the same time.

自从我这样做,大约每10次我编译,也许每隔两天,我收到Dalvik的错误1和一些有关访问已经存在(访问是第一个Java单元的名称我库项目)。

Ever since I did this, about every 10 times I compile, maybe once every day or two, I get "dalvik error 1" and something about "Access already exists" (Access being the name of the first Java unit in my library project).

要解决这个问题我去到Java构建路径,我的存根的项目,我想建立,并从我的库卡主库中删除JAR文件。然后,我可以建立一个没有错误。

To "work around" the issue I go in to the Java Build path for my stub-project that I am trying to build, and remove the JAR file from my main library from the libraries tab. Then I can build without the error.

然后一段时间后(可能是1或2天),当我编译我的存根项目(不是我的库)我会错过类的错误。所以我会回去的Java构建路径,并把引用JAR文件回来,并再次一切都很好1或2天,然后我又回到了相同的错误了。

Then a while later (maybe 1 or 2 days) I'll get an error about missing classes when I compile my stub-project (not my library). So I'll go back to the Java Build path and put the reference to the JAR file back in, and all is good again for 1 or 2 days, then I'm back to the same error as before.

这仅仅是一个已知的问题,这是我需要做的,或者我可以解析我的项目/工作区一个重组?目前,我有:

Is this just a known issue and something I need to do, or can I resolve by a restructure of my projects/workspaces? Currently I have:

库项目 - 只有2库的构建路径:Android的2.1和com.android.ide.eclipse.adt.LIBRARIES

Lib Project - only has 2 libs on build path: Android 2.1 and com.android.ide.eclipse.adt.LIBRARIES

第一短的项目,使用上面LIB - 具有相同的2库作为上述项目,再加上有时我用添加JAR包括从上述项目的bin \文件夹中的JAR

First stub project that uses above lib - has the same 2 libs as above project, plus sometimes I use "Add JAR" to include the JAR from the above project's bin\ folder.

第二存根项目 - 同库的第一桩工程

2nd stub project - same libs as first stub project

我应该引用JAR从我的LIB项目使用下构建路径选择其他选项卡中的一个?也许项目选项卡,而不是,或来源选项卡?我目前没有这在任何这些领域。

Should I reference the JAR from my "lib project" using one of the other tabs under build path options? Maybe the "Project" tab instead, or the "Source" tab? I don't currently have it under any of those other areas.

当我得到的怪异状态,做一个清洁工程也于事无补,我已经试过了好几次,打开/关闭IDE清洗间,没有决心。

When I get in to the weird state, doing a "Clean project" also doesn't help, I've tried that several times and open/close the IDE between cleaning, to no resolve.

在这一点上,我们是在最后的测试阶段,所以我的日常工作​​是:

At this point we are in the final testing stages, so my normal daily task is:

  1. 请一个小更新(bug修​​复)在LIB项目

  1. Make a minor update (bug fix) in the LIB project

使用发布向导导出两个项目和更新的Andr​​oid Market和其他地方,我们保持APK文件

Use the publish wizard to export both projects and update Android Market and other places we keep the APK files

所以我想这些步骤保持简单,无需打开/关闭多个工作区,或经过大量的构建步骤如果可能的话。

So I'd like those steps to stay simple, without having to open/close multiple workspaces or go through a lot of build steps if possible.

推荐答案

  • 右键单击您要在其中插入项目。
  • 点击属性
  • 选择 Java构建路径
  • 选择标签。

The classical Eclipse/Java way

Add a (workspace) library

  • Right click the project you want to insert in.
  • Click Properties.
  • Select Java Build Path.
  • Select the Libraries tab.
  • 现在,这取决于你如何编译库。 因此,要么做一个添加JAR文件... 添加类文件夹。 选择外部变种使用外部电源。 就是这样。

    Now, it depends how you compile your library. So either do an Add JARs... or an Add Class Folder. Choose the external variant to use an external source. That's it.

    • 右键单击您要在其中插入项目。
    • 点击属性
    • 选择 Java构建路径
    • 选择项目标签。
    • Right click the project you want to insert in.
    • Click Properties.
    • Select Java Build Path.
    • Select the Projects tab.

    点击添加... 右侧和你做。

    两个步骤是必要的:

    • 标记要使用的库项目的项目
    • 参考标记的项目

    右键点击您的项目,选择属性。 选择安卓左侧并勾选复选框 IsLibrary 。完成。

    Right click your project and select Properties. Select Android on the left and tick the checkbox IsLibrary. Done.

    右键点击您的项目,选择属性。 在左边,添加... 您标记的项目选择安卓。它将被添加到列表中,并准备使用。现在,你可以从引用,标志着项目进入所有类和ressources(如可绘制字符串)。真棒,对吧? :)

    Right click your project and select Properties. Select Android on the left and Add... your marked project. It will be added to the list and is ready to use. Now you are able to access all classes and ressources (e.g. drawables, strings) from the referenced, marked project. Awesome, eh? :)

    这篇关于Eclipse的Andr​​oid项目,如何引用库中的工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆