Android Studio Java 库模块与 Android 库模块 [英] Android Studio Java Library Module vs. Android Library Module

查看:30
本文介绍了Android Studio Java 库模块与 Android 库模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的最终结果是有一个项目,可以输出共享相同代码库的移动、电视和穿戴应用的不同产品风格.因此,我希望代码库成为所有三种应用程序类型的依赖项,其中每个应用程序模块仅包含活动和与代码库的交互.

My desired end result is to have a Project that can output different productflavors of Mobile, Tv, and Wear apps, that share the same code-base. So I would like the codebase to be a dependency for all three app-types, where each app module would only contain activities and interaction with the codebase.

我的第一个想法是在我新创建的项目中添加一个Android 库模块",但我注意到这实际上只是一个新的应用程序模块,拥有自己的资源和一切.我希望代码库更像一个Java 库",但它需要访问像android.graphics.Color"这样的包.

My first idea was to add a "Android Library Module" to my newly created project, but I noticed that this is really just a new app module with its own resources and everything. I would like the codebase to function more like a "Java Library", but it needs access to packages like "android.graphics.Color".

简而言之,使用具有对 android sdk 的引用的 Java 库是实现此结果的正确方法,还是我只是以错误的方式进行处理?

So in short, is the correct way of achieving this result to use a java library that has a reference to an android sdk or am i just going about this the wrong way?

继续这个问题:Android 库是否需要清单、应用程序名称、图标?

推荐答案

没有中间.如果您想访问 Android API,则该库需要是一个 Android 库,以便构建系统可以将其正确链接到相关项目.确实,Android 库拥有您可能不需要的资源和其他东西,但是如果您愿意,您可以忽略这些部分并将其本质上视为一个普通的 Java 库.即使您不使用资源,您也可能会发现指定 AndroidManifest.xml 属性以合并到依赖应用程序中的功能很有用.

There's no in-between. If you want access to Android APIs, then the library needs to be an Android library so that the build system can properly link it in to dependent projects. It's true that Android Libraries have resources and other things you may not need, but you can ignore those bits and treat it essentially as a plain Java library if you wish. Even if you're not using resources, you may find useful the ability to specify AndroidManifest.xml attributes to be merged into the dependent app.

Android 库项目不会构建成熟的 APK 作为其输出;它生成一个 AAR,它在概念上类似于 JAR 存档,但具有对 Android 项目有用的资源和元信息.

The Android Library project doesn't build a fully-fledged APK as its output; it generates an AAR, which is conceptually similar to a JAR archive, but has resources and meta-information useful to Android projects.

这篇关于Android Studio Java 库模块与 Android 库模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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