2016-05-20 46 views
2

我尝试添加一个本地.aar文件,因为它描述为here,因为我不想在每次更改我的库代码时都实现this例程。本地.aar文件不支持

所以,在我的项目build.gradle文件我补充:

repositories { 
    mavenCentral() 
    flatDir { 
     dirs 'libs' 
    } 
} 

我的图书馆,我的应用程序都有两个版本 - alphaTestmyRelease。我希望每个库都被严格添加到应用程序的相应版本中。

而且在我的应用程序的build.gradle我有以下dependencies块:

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar', '**/*.aar']) 
    compile 'com.android.support:appcompat-v7:23.0.0' 
    alphaTestCompile files ('libs/myLib-alphaTest-release.aar') 
    myReleaseCompile files('libs/myLib-myRelease-release.aar') 
} 

不幸的是,结果我总是受到这样那样的错误:

Error:Project myApp: Only Jar-type local dependencies are supported. Cannot handle: C:\Users\...\myApp\libs\myLib-myRelease-release.aar 

我tryed使用这种格式

alphaTestCompile ('my.package:libs/myLib-alphaTest-release:[email protected]') 

也是这个

alphaTestCompile (name:'myLib-alphaTest-release', ext:'aar') 

但在这种情况下,gradle不能事件解析文件。

我怎样才能让.aar文件也被编译?

+0

的可能的复制[如何使用本地AAR依赖?](http://stackoverflow.com/questions/28869213/how-to-use -local-aar-dependency) – sschuberth

回答

1

下面是我的配置使用aar文件:

//dependencies 
compile fileTree(include: ['*.jar'], dir: 'libs') // dont change anything here 
compile(name: 'yourLib', ext: 'aar') // yourLib.aar is put in libs folder 

repositories { 
    flatDir { 
     dirs 'libs' 
    } 
} 
+0

你的线条和我的一个tryes之间的本质区别是什么? – user2957954

+0

@ user2957954它完全不同。 1.'fileTree',2.编译库lib –

+0

不!你有相同的fileTree(我也有'* .aar'),你实现了我的一种编译格式。 – user2957954