0

I build an aar file. It use some dependency. build.gradle file of my libray:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        vectorDrawables.useSupportLibrary = true

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }


}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

My aar file path -> app/libs/mylibrary.aar

I edit top level build.gradle file

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

Add the library as a dependency

implementation(name:"mylibrary", ext:"aar") {
    transitive = true
}

My application id: my.sample.app

./gradlew app:assembleRelease

Task :app:processReleaseManifest /SampleApp/app/src/main/AndroidManifest.xml:6:5-21:19 Warning: application@android:label was tagged at AndroidManifest.xml:6 to replace other declarations but no other declaration present /SampleApp/app/src/main/AndroidManifest.xml:6:5-21:19 Warning: application@android:icon was tagged at AndroidManifest.xml:6 to replace other declarations but no other declaration present /user/.gradle/caches/transforms-2/files-2.1/eb66b88fff0dbb2e75f036f5373b5bbf/res/layout/activity_btb.xml:10: AAPT: error: attribute 'my.sample.app:layout_constraintLeft_toLeftOf' not found.

I add dependencies that used by library, the error is gone.

implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

implementation(name:"mylibrary", ext:"aar") {
    transitive = true
}

But this is not best way. How can I fix this error? Why my library couldn't find its dependecies.

zakjma
  • 2,030
  • 12
  • 40
  • 81

1 Answers1

0

I just found the reason of this error.

The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.

It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.

You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue. In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.

Original answer is here: https://stackoverflow.com/a/36475009/4319615

zakjma
  • 2,030
  • 12
  • 40
  • 81