本文介绍了使用“flatDirs"将本地 .aar 文件添加到 Gradle 构建不管用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题:添加本地 .aar 文件到我的 gradle 构建,但该解决方案对我不起作用.

我尝试将此语句添加到我的 build.gradle 文件的顶层:

存储库 {MavenCentral()平面目录{目录'库'}}

我还将 slidingmenu.aar 文件放入 /libs 并在 dependencies 部分中引用它: compile 'com.slidingmenu.lib:slidingmenu:1.0.0@aar' 但它根本不起作用.

我也试过compile files('libs/slidingmenu.aar'),但没有成功.

我错过了什么?有什么想法吗?

附言安卓工作室 0.8.2

解决方案

以 Josiah 的回答为基础,这是我如何让它工作的.

按照他的指示(在编辑下)(文件 -> 新建 -> 新模块 -> 导入 .JAR/.AAR)并导入您的 .AAR.

然后在您的项目 build.gradle(不是顶级的,'app' 下的那个)中添加以下内容(在依赖项部分):

依赖项{编译项目(':Name-Of-Your-Project')}

注意 Name-Of-Your-Project 应该和你导入 AAR 文件后添加的文件夹的名字一致(与 app/.idea 同级在最顶层文件夹下).或者换一种说法...

我的应用程序.主意应用程序build.gradle(这里是将 compile project(':ProjectName') 添加到依赖项部分的位置)ProjectName(导入后自动添加,匹配你的aar文件名)建造等级等等

这对我运行 Android Studio 0.8.0 很有用.执行此操作后,不要忘记同步 gradle(使用工具栏按钮或在 File->Synchronize 中).

(感谢 Josiah 让我朝着正确的方向前进)

(注意:在此之前,我尝试将其添加到 libs 文件夹中,尝试操作顶级 build.gradle 和应用程序级别 build.gradle,但是这些都不适用于我的 aars 文件——jar 可以正常工作,但不适用于 aar 文件)

I'm aware of this question: Adding local .aar files to my gradle build but the solution does not work for me.

I tried adding this statement to the top level of my build.gradle file:

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

I've also put the slidingmenu.aar file into /libs and referenced it in the dependencies section: compile 'com.slidingmenu.lib:slidingmenu:1.0.0@aar' but it did not work at all.

I tried compile files('libs/slidingmenu.aar') as well but with no luck.

What am I missing? Any ideas?

P.S. Android Studio 0.8.2

解决方案

Building upon Josiah's answer, here's how I got it to work.

Following his instructions (under edit) (File -> New-> New Module -> Import .JAR/.AAR) and import your .AAR.

Then in your project build.gradle (not the top level one, the one under 'app') add the following (in the dependencies section):

dependencies {
    compile project(':Name-Of-Your-Project')
}

Note Name-Of-Your-Project should match the name of the folder that was added after you imported the AAR file (at the same level as app/.idea under the top most level folder). Or to put it another way...

MyApplication
  .idea
  app
  build.gradle (here's where to add compile project(':ProjectName') to dependency section)
  ProjectName (added automatically after importing, matching the name of your aar file)
  build
  gradle
  etc

This worked for me running Android Studio 0.8.0. Don't forget to synchronize gradle (using toolbar button or in File->Synchronize) after you do this.

(Thanks to Josiah for getting me going in the right direction)

(Note: prior to this I tried adding it to the libs folder, trying to manipulate the top level build.gradle and the app level build.gradle, but none of that worked for my aars files--jar's will work fine, but not the aar files)

这篇关于使用“flatDirs"将本地 .aar 文件添加到 Gradle 构建不管用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 04:05