gpt4 book ai didi

android - 引用外部项目库源码树

转载 作者:行者123 更新时间:2023-11-30 04:11:49 26 4
gpt4 key购买 nike

首先,我知道有几个问题针对这个主题,但没有一个对我有帮助。


我正在使用 Android/ADT 插件开发我的第一个 Android 项目,我想使用 this library .我在 SO 和官方文档中搜索了如何完成此操作,我找到了 how to reference a library project .

我运行了以下命令:

$ android update project --target 8 /path/to/workspace/myproject /path/to/workspace/numberpicker/lib
Resolved location of library project to: /path/to/workspace/numberpicker/lib
Updated project.properties
Updated local.properties
No project name specified, using Activity name 'SplashActivity'.
If you wish to change it, edit the first line of build.xml.
Added file /path/to/workspace/myproject/build.xml
Updated file /path/to/workspace/myproject/proguard-project.txt

显然这一步工作正常。但是,当我尝试在 xml 布局中引用 com.michaelnovakjr.numberpicker.NumberPicker 时,Eclipse 提示找不到此类。

然后我找到this answer并更改了我的 project.properties:

# Before
android.library.reference.1=/path/to/workspace/numberpicker/lib
# After
android.library.reference.1=../numberpicker/lib

但没有解决我的问题。

也许需要特别指出的是,这个库不是 Eclipse 项目,所以我无法在 Eclipse 中打开它。

最佳答案

为了让 Eclipse 正确构建依赖项目,Library Project 必须存在于同一个工作区中,参见开发指南 Managing Project - Library Projects了解更多详情:

However, a library project differs from an standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.

When you build an application that depends on a library project, the SDK tools compile the library into a temporary JAR file and uses it in the main project, then uses the result to generate the .apk. In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.

为了使用 numberpicker 库,您需要将其作为 Android 项目导入到 Eclipse 中,在向导中选择 File -> New -> Other ... -> Android -> Android project窗口,选中 Create projet from existing source 并选择位置。

关于android - 引用外部项目库源码树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10748008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com