【发布时间】:2019-04-08 11:04:06
【问题描述】:
我创建了一个依赖于约束布局的库。该库通过 aar 文件包含在新项目中。该项目对其使用的所有 appNS 属性都给出以下错误。
home/vishal/.gradle/caches/transforms-1/files-1.1/my_library.aar/9012247ff26b45ffb7af7d608db342c5/res/layout/activity_main.xml:70: AAPT:错误:属性 layout_constraintBottom_toTopOf(又名 com.example.sampleapp:layout_constraintBottom_toTopOf) 未找到。
库编译 sdk : 28 支持版本:28.0.0
ConstraintLayout 作为实现添加到库中。项目中包含的 aar 库如下:
dependencies {
implementation fileTree(include: ['*.aar'], dir: 'libs')
implementation files('libs/my_library.aar')
}
我已尝试将库和项目转换为 androidX,但问题仍然存在。
注意:
为了使用现有库测试场景 [更新]: 我在刮刮卡库 [https://github.com/Veeshal/scratchCardLayout] 中添加了约束布局以及实现约束布局的活动及其布局。将其作为 aar 文件导入。我在构建时没有收到任何错误。 验证创建一个示例项目并添加从上面共享的 github 存储库中的模块 scratchcardlayout 生成的 AAR 文件。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
.....
<!-- Optional Design -->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone">
....
</android.support.constraint.ConstraintLayout>
<!-- Selected Design -->
<android.support.constraint.ConstraintLayout
android:id="@+id/cl_cropping_layer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
....
</android.support.constraint.ConstraintLayout>
.....
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
传递依赖不包含在 aar 中,如果您希望它们自动包含在您的应用程序中,您可以将 aar 作为 maven 工件发布
-
该库不应该是公开可用的,所以不能把它放在 maven 中。只能共享 aar。
-
我觉得你不需要公开发布,你应该可以在本地“发布”它,查看this article
-
传递依赖项不包含在 aar 中,并且有意如此,您要么在使用 aar 的应用程序中明确声明传递依赖项,要么将 aar 作为 maven 工件发布,以便传递依赖在 pom 文件中声明。您发布的项目生成的 aar 不包括 ConstraintLayout,如果它与其他示例应用程序一起使用,则意味着示例应用程序已经具有该依赖项(如项目本身中的演示应用程序)。
-
在您使用 aar 的应用程序中运行
./gradlew dependencies,您应该能够看到哪个依赖项正在导入 ConstraintLayout。
标签: android android-gradle-plugin android-constraintlayout android-library