gpt4 book ai didi

android - 如何为非 Maven 项目创建 apklib

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:17:37 25 4
gpt4 key购买 nike

我的 android 应用程序依赖于来自第 3 方的 android 库项目。我正在将我的构建环境切换到 Maven 并且遵循示例进行得相当顺利,但最后一步是这样。我不明白我实际上需要做什么。我已经阅读了 apklib 页面 here .我从未见过比本文档更好地围绕您实际做得更好的文档。它包含 1 个您如何引用 apklib 的 fragment ,但根本没有关于您如何实际生成它的信息?

另外,我的项目结构是这样的

/projectroot/app   (main application android project source code)
/projectroot/shared/lib1
/projectroot/shared/lib2 (3rd party lib i don't want to create pom.xml for)

我的 projectroot/pom.xml 有一个像这样的模块部分:

<modules>
<module>shared/lib1</module>
<module>shared/lib2</module>
<module>app</module>
</modules>

这是正确的吗?在所有模块示例中,我看到它们引用文件夹直接子项,而我的则嵌套得更远。

我正在寻找的主要内容是如何使 lib2 成为 apklib 以从 app/pom.xml 中引用。

最佳答案

提到in the link you referenced :

Compatible with non-Maven Android Library Projects!

The generated .apklib file will have the layout of a standard Android/Eclipse library project. This means that regardless of your Maven layout, the layout inside the .apklib file will be that source code is in "src/" instead of "src/main/java/", but still interpreted correctly when used in an Android/Maven application project. This is to be compatible with non-Maven developers' library projects, which is important to grow the Android developer community.

Use other non-Maven developers' libraries

It also means we can take any external Android library project zip file (from non-Maven developers) and do mvn install:install-file ... on it and simply start using it as a dependency.

Share your .apklib with non-Maven developers

To share your .apklib file with a non-Maven developer, they will probably feel more comfortable if you rename it to .zip. They can then simply unpack it in a directory and use it from there.

如果它是一个 mavenized Android 库项目,只需运行 mvn clean install 即可创建 apklib 并将其安装到本地 Maven 存储库中。

如果是常规的Android库项目,只需压缩项目文件夹(最好去掉所有不必要的IDE生成文件),将my-lib.zip重命名为my-lib.apklib,然后运行mvn install:install-file。将 my-lib.apklib 安装到本地 Maven 存储库中。

注意,在你的多模块maven项目中,如果子模块lib2没有mavenized,运行maven build时可能会出现一些配置错误,毕竟叫多模块Maven项目所以没有太大意义包括一个非 mavenized 子项目。如果 lib2 尚未 mavenized,要么将其作为 mutli-module maven 项目的一部分进行 mavenize,要么将其从 mutli-module maven 项目中删除并单独维护(从通过 apklib 的命令行构建和通过源代码的 IDE 开发)。

另请注意,在 Maven 和 Eclipse 中构建项目是完全不同的故事,如果您正在创建项目/将项目导入到 IDE 中,则无论如何都需要库项目源。如果 lib2 作为多模块项目的一部分进行了 mavenized,它将在导入父项目时自动导入和设置,否则,您可能需要手动导入和设置独立项目。查看this answerthis answer了解更多详情。

关于android - 如何为非 Maven 项目创建 apklib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13884512/

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