如何在Android的主项目中包含库项目中使用的aar文件 [英] How to include aar files used in library projects in main project in Android
问题描述
我的项目包括一些图书馆项目.库正在使用一些 aar 文件,并且它的依赖已经在模块:gradle 文件中定义.我在将这个库包含在我的项目中时遇到了问题.
如果我在 app->lib 中保留重复的 aar 文件并在 app->gradle 文件中定义它们的依赖项,则没有问题.但这不应该是正确的方法.
请在下面找到错误:
配置项目:app"时出现问题.
无法解析配置:app:_qaDebugCompile"的所有依赖项.找不到 :api-release:.在以下位置搜索:https://jcenter.bintray.com//api-release//api-release-.pomhttps://jcenter.bintray.com//api-release//api-release-.aar文件:/D:/sample/sample-android-app/app/libs/api-release-.aar文件:/D:/sample/sample-android-app/app/libs/api-release.aar要求:sample-android-app:app:unspecified >示例-android-app:misnapworkflow:未指定
请在下面找到项目结构:
示例|-- 应用|-- 错误的工作流程||-- 库|-- api-release.aar
在应用程序 gradle 文件中提到了以下包含项目
<块引用><块引用>dependencies { compile project(':misnapworkflow') }
请在 misnapworkflow gradle 文件下方找到:
应用插件:'com.android.library'安卓 {compileSdkVersion 23构建工具版本23.0.1"默认配置{minSdk 版本 10目标SDK版本23consumerProguardFiles 'proguard-rules.pro'}lintOptions {abortOnError false}//发布调试和发布库发布非默认为真构建类型{调试{可调试真jniDebuggable 真minifyEnabled false收缩资源错误testCoverageEnabled true}释放 {签名配置signingConfigs.debug可调试假jniDebuggable falseminifyEnabled true收缩资源错误proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'}}}任务授予权限(类型:Exec,dependsOn:'installDebugTest'){logger.warn('授予权限...')命令行adb shell pm grant com.miteksystems.misnap.misnapworkflow.test android.permission.WRITE_EXTERNAL_STORAGE".split(' ')命令行adb shell pm grant com.miteksystems.misnap.misnapworkflow.test android.permission.CAMERA".split(' ')logger.warn('已授予权限.')}tasks.whenTaskAdded { 任务 ->if (task.name.startsWith('connected')||task.name.startsWith('create')) {task.dependsOn 授予权限}}依赖{编译文件树(包括:['*.jar'],目录:'libs')编译'com.android.support:appcompat-v7:23.0.1'//为 MiSnap 外部 API 添加依赖编译(名称:'api-release',分机:'aar')//为 MiSnap 添加依赖编译(名称:'错误释放',分机:'aar'){排除模块:'appcompat-v7'}//事件总线依赖编译de.greenrobot:eventbus:2.4.0"//为 Manatee 添加可选的依赖项编译(名称:'海牛释放',分机:'aar')编译(名称:'cardio-release',分机:'aar')}存储库{平面目录{目录'库'}}
aar 文件 不包含 传递 依赖项,并且没有描述库使用的依赖项的 pom 文件.
这意味着,如果您使用 flatDir
存储库导入 aar 文件您还必须在项目中指定依赖项.
您应该使用 maven 存储库(您必须在私有或公共 Maven 存储库中发布库),您将不会遇到相同的问题.
在这种情况下,gradle 使用包含依赖项列表的 pom 文件下载依赖项.
My project is including some library project. Library is using some aar files and its dependecny is already defined in the module: gradle file. I am facing problem in including this library in my project.
If I keep duplicate aar files in app->lib and define their dependency in app->gradle file then there is no problem. But it shouldn't be the right approach.
Please find below the error:
A problem occurred configuring project ':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
please find below the project structure:
sample
|-- app
|-- misnapworkflow
|
|-- lib
|-- api-release.aar
In app gradle file following has been mentioned to include the project
dependencies { compile project(':misnapworkflow') }
Please find below the misnapworkflow gradle file:
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'
}
}
The aar file doesn't contain the 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.
这篇关于如何在Android的主项目中包含库项目中使用的aar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!