使用 <uses- library> 创建依赖于外部 JAR 库的模块的正确方法

Correct way to use <uses- library> to create module that depend on an external JAR library

在此页面中:https://developer.android.com/studio/projects/android-library.html#Considerations

它指出:

You can develop a library module that depends on an external library. (for example, the Maps external library). In this case, the dependent app must build against a target that includes the external library (for example, the Google APIs Add-On). Note also that both the library module and the dependent app must declare the external library in their manifest files, in a element.


所以我试着按照上面段落所说的去做。

1- 我创建了一个模块 gradle:

compile 'com.twitter.sdk.android:twitter-core:3.0.0'
compile 'com.twitter.sdk.android:tweet-ui:3.0.0'

2- 我在 manifest.xml

中添加了这个
<uses-library
android:name="com.twitter.sdk"
android:required="true"/>

3- 我将 .aar 文件导入了我的主应用程序。

4- 我将相同的代码添加到我的 主应用程序 manifest.xml

<uses-library
android:name="com.twitter.sdk"
android:required="true"/>

但它当然会显示错误:

从您的清单中删除 <uses-library>。它 适用于您尝试使用作为设备固件一部分的 "library" 的情况。他们引用的 "Maps" 示例来自长期过时的 Google Maps V1 for Android 实现。

据我所知,有任何设备制造商建议其开发人员将 <uses-library> 元素添加到其 com.twitter.sdk 的清单中。