【问题标题】:Android - AAR file causes errorsAndroid - AAR 文件导致错误
【发布时间】:2019-11-16 14:49:33
【问题描述】:

我建立了一个 aar 文件。它使用了一些依赖。我的库的 build.gradle 文件:

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'
}

我的aar文件路径->app/libs/mylibrary.aar

我编辑顶级 build.gradle 文件

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

将库添加为依赖项

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

我的应用程序 ID:my.sample.app

./gradlew app:assembleRelease

任务:app:processReleaseManifest /SampleApp/app/src/main/AndroidManifest.xml:6:5-21:19 警告: application@android:label 在 AndroidManifest.xml:6 处被标记以替换其他声明,但不存在其他声明 /SampleApp/app/src/main/AndroidManifest.xml:6:5-21:19 警告: application@android:icon 在 AndroidManifest.xml:6 处被标记以替换其他声明,但不存在其他声明 /user/.gradle/caches/transforms-2/files-2.1/eb66b88fff0dbb2e75f036f5373b5bbf/res/layout/activity_btb.xml:10:AAPT:错误:找不到属性“my.sample.app:layout_constraintLeft_toLeftOf”。

我添加了库使用的依赖项,错误消失了。

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
}

但这不是最好的方法。我该如何解决这个错误?为什么我的库找不到它的依赖项。

【问题讨论】:

    标签: android android-library aar aapt manifest-merging


    【解决方案1】:

    我刚刚找到了这个错误的原因。

    aar 文件不包含嵌套(或传递)依赖项 并且没有描述所使用的依赖项的 pom 文件 图书馆。

    这意味着,如果您使用 flatDir 存储库导入 aar 文件 您还必须在项目中指定依赖项。

    您应该使用 maven 存储库(您必须在 私人或公共 Maven 回购),你不会有同样的问题。在 在这种情况下,gradle 使用 pom 文件下载依赖项 将包含依赖项列表。

    原答案在这里:https://stackoverflow.com/a/36475009/4319615

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多