构建时无法识别aar中的constraintlayout属性

时间:2019-04-08 11:04:07

标签: android android-gradle android-constraintlayout android-library

我创建了一个依赖约束布局的库。该库通过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(aka   找不到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>

1 个答案:

答案 0 :(得分:0)

One simply cannot add a local AAR dependency alike a JAR dependency.

It is required setup a local flatDir repository in the root project's build.gradle:

allprojects {
    repositories {
        ...
        flatDir {
            dirs "libs"
        }
    }
}

Then one can reference the AAR almost alike any other dependency; notice the @aar:

implementation "com.acme:somelibrary:1.0.0@aar"

And most likely, you would also have to use api instead of implementation (in the library module)

... in order to expose the ConstraintLayout to the "library consumer" (which is the app module).