先说一下对我来说不好用的一些方法
网上搜到的最多的就是在app的build.gradle中添加
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation(name: 'xxx', ext: 'aar')
// 或者
implementation fileTree(include: ['*.jar','*.arr'], dir: 'libs')
}
我用的studio是2021.1.1.1,项目是新建的。目录结构不一样。
repositories
并不能在app的build.gradle中添加,repositories
在在项目根目录的settings.gradle中。如下:
pluginManagement {
repositories {
// 添加flatDir,路径是app/libs。也不是libs了
flatDir {
dirs 'app/libs'
}
maven { url 'xxx' }
maven { url 'xxx' }
gradlePluginPortal()
google()
mavenCentral()
}
plugins {
id 'com.android.application' version '7.1.0-alpha11'
id 'com.android.library' version '7.1.0-alpha11'
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
flatDir {
dirs 'app/libs'
}
maven { url 'xxx' }
maven { url 'xxx' }
google()
mavenCentral()
}
}
rootProject.name = "你的项目名字"
include ':app'
在repositories
标签下添加flatDir,路径是app/libs
。也不是libs
了。
然后再app目录下得build.gradle中添加
dependencies {
implementation(name: 'xxx', ext: 'aar')
}
implementation fileTree
的方式是不行的,只能是单独引入arr的依赖。
希望能对其他人有用。如果有高手也可以指点一下为啥是这个情况。