代码之家  ›  专栏  ›  技术社区  ›  Liuyanguo

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

  •  1
  • Liuyanguo  · 技术社区  · 8 年前

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

    现在,我想使用maven文件,如何在项目中进行配置 build.gradle ,或在我的模块中 建筑格拉德尔 .

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

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

    在我的模块中 建筑格拉德尔

    并添加

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

    在我的项目中

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

    2 回复  |  直到 8 年前
        1
  •  3
  •   Gabriele Mariotti    8 年前

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

    请注意,因为gradle缓存文件夹不是maven repo。

    然后:

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

    您正在使用 repositories 阻塞内部 buildscript 这与 dependencies 像aar文件。

    如果你有aar文件,你可以把文件放在 libs 文件夹,然后使用:

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

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

    这意味着,如果您使用 flatDir 您还必须在项目中指定依赖项 .

    dependencies {
        compile 'my_dependencies:X.X.X'
    }
    
        2
  •  -1
  •   le0nidas    8 年前

    尝试添加项目的 build.gradle :

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