依賴了aar庫的module被導入工程時出現failed to resolve的錯誤

在Android Studio中創建一個module或者導入一個module的時候,如果這個module中依賴了aar庫,當build工程的時候,會出現failed to resolve這個錯誤,如下圖:

                                                                                

這時候,只要在你的app build.gradle(不是project的build.gradle)中加入下面代碼就可以完美解決了:

repositories {
    flatDir {
        dirs project(':taesdk').file('libs')
    }
}

上面代碼中的“taesdk“替換成你的module的名字,libs是module依賴的aar庫所在的目錄。如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.paxsz.ossdemo"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    flatDir {
        dirs project(':taesdk').file('libs')
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.1'
    testCompile 'junit:junit:4.12'
    compile project(':taesdk')
}

這時候再去編譯,發現不會出錯了。


發佈了35 篇原創文章 · 獲贊 35 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章