如何在我的 Android 项目中使用下载的 maven aar 文件?

How to use the downloaded maven aar file in my Android project?

我的Android项目从别人的个人maven下载maven aar文件,它存在于目录:

C:\Users\username\.gradle\caches\modules-2\files-2.1

现在我想使用 maven 文件,如何在我的项目 build.gradle 或我的模块 build.gradle.

中配置

我尝试了很多方法来解决这个问题,包括添加

repositories{
    flatDir{
        dirs 'libs'
    }
}
dependencies {
    compile(name: 'myaarfilename.aar', ext: 'arr')
}

在我的模块中build.gradle

并添加

buildscript{
    repositories{
        jcenter()
        mavencentral()
        mavenLocal() //to use my local maven aar file
    }
}

在我的项目中build.gradle

所有这些方法都不起作用,那么我如何使用我的 maven 缓存 aar 文件,或者我如何配置 maven?希望有人能帮助我,非常感谢。

尝试在项目的build.gradle中添加:

allprojects {
    repositories {       
        maven { url 'file://' + new File('path/to/repository').canonicalPath }
    }
}

My Android project download the maven aar file from others' personal maven,it exists in the directory:

C:\Users\username\.gradle\caches\modules-2\files-2.1

请注意,因为 gradle 缓存文件夹不是 Maven 存储库。

然后:

buildscript{
    repositories{
        jcenter()
        mavencentral()
        mavenLocal() //to use my local maven aar file
    }
}

您正在 buildscript 中使用 repositories 块,它与 aar 文件一样与 dependencies 无关。

如果您有 aar 文件,您可以将文件放在 libs 文件夹中,然后使用:

dependencies {
   compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
 }
repositories{
      flatDir{
              dirs 'libs'
       }
 }

请注意,因为 aar 文件 不包含传递依赖项 并且没有描述库使用的依赖项。

这意味着,如果您使用 flatDir 存储库导入 aar 文件 您还必须在项目中指定依赖项

否则,如果你有一个 maven 仓库,只需使用:

dependencies {
    compile 'my_dependencies:X.X.X'
}