我已将.aar文件添加到子项目中的libs文件夹中。并将存储库作为:
repositories {
mavenCentral()
mavenLocal()
flatDir {
dirs 'libs'
}
在这个子项目的build.gradle中。我是否还需要在Main项目的build.gradle中添加依赖项?如果是的话,应该怎么做?
classpath 'com.android.tools.build:gradle:1.3.0'
d:/myproject/mylib/build/outputs/aar/mylib-release.aar
您还需要设置依赖项:
compile fileTree(dir: 'libs', include: ['*.jar','*.aar'])
这可以在子项目build.gradle中完成。
编辑:您可能需要指定文件本身:
compile(name:'name-of-file',ext:'aar')
对于filename.aar
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'filename', ext:'aar')
}
您正在libs文件夹中添加aar文件。 aar文件不包含依赖项,然后您还必须在主项目中添加这些依赖项。
在你的module1/build.gradle
你应该有类似的东西:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.android.support:appcompat-v7:22.2.1') //for example
//..
}
在你的mainModule/build.gradle
中,你必须添加你的module1使用的所有依赖项。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name:'fileName',ext:'aar')
compile('com.android.support:appcompat-v7:22.2.1') //for example
//...
}
在您的模块的存储库中:app
repositories {
flatDir {
dirs 'libs'
}
}
在模块的依赖项中添加以下内容:app如果您同时拥有JAR和AAR文件,请执行以下操作。
dependencies
{
implementation (name: '***library name***', ext: 'aar')
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'], )
}