I have to add .aar files as a library in a sub project in Android studio. It gives me an error.

你说的曾经没有我的故事 提交于 2019-12-03 15:32:51
classpath 'com.android.tools.build:gradle:1.3.0'
  1. File -> New Module -> Import JAR/AAR Package

  2. "File name" select .aar file, example:

d:/myproject/mylib/build/outputs/aar/mylib-release.aar
  1. "Subproject name",example:

    mylib-release
  2. /app/build.gradle

    dependencies{

    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile project(':mylib-release')

    }

You need to set the dependencies too:

compile fileTree(dir: 'libs', include: ['*.jar','*.aar'])

This can be done in the subprojects build.gradle.


Edit: You might need to specify the file itself:

compile(name:'name-of-file',ext:'aar')

For filename.aar

repositories {
   flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile(name:'filename', ext:'aar')
}
George

In the repositories of your module: app

repositories {

    flatDir {
        dirs 'libs'
    }
}

Add the following in the dependencies of your module: app In the case that your have both a JAR and an AAR file, do the following.

dependencies 
{
  implementation (name: '***library name***', ext: 'aar')
  implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'], )

}

You are adding a aar file in libs folder.
The aar file doesn't contain the dependencies, then you have to add these dependencies also in the main project.

In your module1/build.gradle you should have something like:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('com.android.support:appcompat-v7:22.2.1') //for example
    //..
 }

In your mainModule/build.gradle you have to add all the dependencies used by your module1.

dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile(name:'fileName',ext:'aar')
        compile('com.android.support:appcompat-v7:22.2.1') //for example
        //...
     }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!