如何在Android主项目中包含库项目中使用的AAR文件

曼尼什

我的项目包括一些图书馆项目。库正在使用一些aar文件,其依赖关系已在模块gradle文件中定义。在将这个库包含在我的项目中时,我遇到了问题。

如果我在app-> lib中保留重复的aar文件,并在app-> gradle文件中定义它们的依赖关系,那么就没有问题。但这不应该是正确的方法。

请在错误下方找到:

配置项目':app'时发生问题。

Could not resolve all dependencies for configuration ':app:_qaDebugCompile'. Could not find :api-release:. Searched in the following locations:
         https://jcenter.bintray.com//api-release//api-release-.pom
         https://jcenter.bintray.com//api-release//api-release-.aar
         file:/D:/sample/sample-android-app/app/libs/api-release-.aar
         file:/D:/sample/sample-android-app/app/libs/api-release.aar
     Required by:
         sample-android-app:app:unspecified > sample-android-app:misnapworkflow:unspecified

请在下面的项目结构中找到:

sample
|-- app
|-- misnapworkflow
    |
    |-- lib
        |-- api-release.aar

在应用程序gradle文件中,已提及以下内容以包含该项目

依赖项{编译项目(':misnapworkflow')}

请在misnapworkflow gradle文件下面找到:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 23
        consumerProguardFiles 'proguard-rules.pro'
    }

    lintOptions {
        abortOnError false
    }

    // Publish both debug and release libraries
    publishNonDefault true

    buildTypes {
        debug {
            debuggable true
            jniDebuggable true
            minifyEnabled false
            shrinkResources false
            testCoverageEnabled true
        }

        release {
            signingConfig signingConfigs.debug
            debuggable false
            jniDebuggable false
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

task grantPermissions(type: Exec, dependsOn: 'installDebugTest') {
    logger.warn('Granting permissions...')
    commandLine "adb shell pm grant com.miteksystems.misnap.misnapworkflow.test android.permission.WRITE_EXTERNAL_STORAGE".split(' ')
    commandLine "adb shell pm grant com.miteksystems.misnap.misnapworkflow.test android.permission.CAMERA".split(' ')
    logger.warn('Permissions granted.')
}

tasks.whenTaskAdded { task ->
    if (task.name.startsWith('connected')
            || task.name.startsWith('create')) {
        task.dependsOn grantPermissions
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'

    // Add dependency for MiSnap external API
    compile(name: 'api-release', ext: 'aar')

    // Add dependency for MiSnap
    compile(name: 'misnap-release', ext: 'aar') {
        exclude module: 'appcompat-v7'
    }

    // Eventbus dependency
    compile 'de.greenrobot:eventbus:2.4.0'

    // Add OPTIONAL dependency for Manatee
    compile(name: 'manatee-release', ext: 'aar')

    compile(name: 'cardio-release', ext: 'aar')
}

repositories {
    flatDir {
        dirs 'libs'
    }
}
加布里埃尔·马里奥蒂(Gabriele Mariotti)

AAR文件不包含传递的依赖关系,并没有描述库所使用的依赖关系的POM文件。

这意味着,如果你使用的是导入AAR文件flatDir回购,你也必须指定项目的依赖关系

您应该使用Maven存储库(您必须在私有或公共Maven存储库中发布库),不会遇到相同的问题。
在这种情况下,gradle使用pom文件下载依赖项,该文件将包含依赖项列表。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Android库项目中使用匕首

如何在Java项目中使用Kotlin库?

如何在项目中包含字体并在NetBeans IDE的项目文件夹中使用字体?

如何在Android项目中使用@WorkerThread批注?

如何在Elixir项目中使用开源Erlang库?

如何在Android Studio项目中使用最新的FFMPEG?

如何在Android Studio项目中使用特定的外部库查找哪些文件

如何在Android Studio项目中包含共享库?

包含主项目中的文件时,单元测试项目中出现错误

如何在Django项目中使用静态文件?

如何在项目中使用Angular库中的服务

从主项目中查找类库的资源

如何在Scalajs项目中使用Javascript库

如何在C ++项目中使用Swift静态库(.a)?

如何在包含的Android库上过渡地使用Android项目中Java项目中的jar?

如何在C#项目中使用LIB文件?

如何在libgdx项目中使用android类?

添加库项目并在主项目中使用它

如何在C ++项目中使用共享动态库?

如何在不基于gradle构建的android项目中使用ShowcaseView库?

如何在项目中使用Printf

在android项目中使用库

如何在Maven项目中使用ASM库

如何在我的项目中包含GitHut库(Android Studio)

如何在我的 Android 项目中使用下载的 maven aar 文件?

除非在主项目中使用,否则静态库中的链接错误

如何在android studio项目中使用Material Design

如何在我的整个项目中使用 phpdotenv 库?

如何在android studio项目中使用Sketch设计