Android的 - 是否有可能创建一个自定义库在多个应用程序中使用?多个、有可能、自定义、创建一个

2023-09-12 11:31:16 作者:浪够了你的逼也烂透了

是否有可能跨多个Android应用程序使用创建的Andr​​oid定制库(有自己的布局资源)?

Is it possible to create a custom library in Android (having its own layout resources) for use across several Android applications?

我创建了一个普通的* .jar文件,但是当我试图创建/风格我的看法动态大部分属性不工作。即使从的android.jar文件中引用的简单风格,如 android.attr.listSeparatorTextViewStyle 的没有工作。

我创建了一个Android项目没有任何活动,有其自身的资源文件,然后引用该项目从另一个Android项目在其构建路径来使用。一切似乎都在正常工作,但模拟器总是崩溃(在任何有意义的错误消息,在 LogCat中),当我尝试运行该项目。

I created an Android project without any Activity, having its own resource files and then referenced this project from another Android project to use in its build path. Everything seems to work fine but the emulator keeps crashing (with no meaningful error message in the LogCat) when I try to run the project.

我缺少的东西?

推荐答案

嗯,我认为是有办法做到这一点(虽然我没有尝试自己),但它需要你的库的用户不必建立他们的APK通过 AAPT 手动。

Well, I think there is a way to do it (although I didn't try it myself), but it requires the users of your library having to build their APKs manually via aapt.

问题是这样的:要导出的JAR包含它保存库的资源ID的研究类文件。因此,任何应用都可以通过简单的连接你的JAR访问这些ID。但是,这还不够,因为默认情况下,只有在应用程序的资源/文件夹中的资源捆绑在一起的APK。因此,您可以使用AAPT,告诉它也包括任何资源库中创建APK自己。检查AAPT工具帮助以获取更多信息。

The problem is this: The JAR you're exporting contains the R class file which holds the resource IDs of your library. So, any application can access these IDs by simply linking your JAR. However, that's not enough, because by default, only resources in the app's res/ folder are bundled with the APK. Hence, you have to create the APK yourself using aapt, telling it to also include any resources from your library. Check the aapt tool help for more information.

由于这意味着你的库的用户必须引入人工生成过程(或至少修改),它使一个贫穷的经验。

Since this implies that users of your library have to introduce a manual build process (or at least modify it), it makes for a poor experience.

 
精彩推荐
图片推荐