[Android]依赖了包含aar包的库后出现Failed to resolve库aar包问题的解决办法

本文介绍了解决Android Studio中因依赖AAR库而出现的编译错误的方法。通过在Gradle文件中添加特定配置,可以成功引入依赖并完成项目编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android Studio中创建一个module或者导入一个module的时候,如果这个module中依赖了aar库,当build工程的时候,会出现failed to resolve这个错误

这时候,只要在app的build.gradle中加入下面代码就可以完美解决了:

[java]  view plain  copy
  1. repositories {  
  2.     flatDir {  
  3.         dirs project(':taesdk').file('libs')  
  4.     }  
  5. }  

上面代码中的“taesdk“替换成module的名字,libs是module依赖的aar库所在的目录。如下:

[java]  view plain  copy
  1. apply plugin: 'com.android.application'  
  2.   
  3. android {  
  4.     compileSdkVersion 25  
  5.     buildToolsVersion "25.0.0"  
  6.     defaultConfig {  
  7.         applicationId "com.paxsz.ossdemo"  
  8.         minSdkVersion 19  
  9.         targetSdkVersion 25  
  10.         versionCode 1  
  11.         versionName "1.0"  
  12.         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"  
  13.     }  
  14.     buildTypes {  
  15.         release {  
  16.             minifyEnabled false  
  17.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  
  18.         }  
  19.     }  
  20. }  
  21. repositories {  
  22.     flatDir {  
  23.         dirs project(':taesdk').file('libs')  
  24.     }  
  25. }  
  26. dependencies {  
  27.     compile fileTree(include: ['*.jar'], dir: 'libs')  
  28.     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {  
  29.         exclude group: 'com.android.support', module: 'support-annotations'  
  30.     })  
  31.     compile 'com.android.support:appcompat-v7:25.0.1'  
  32.     testCompile 'junit:junit:4.12'  
  33.     compile project(':taesdk')  
  34. }  

这时候再去编译,就不会出错了
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值