工程目录:
我们看到,在Java目录里面,每一个目录下都是一个模块,每个模块都有自己的res目录。
Gradle 配置如下:
def srcDirs
= [
'application',
'application/attrs',
'application/legacymultidex',
'application/scope',
...
'transition/hero',
'windowpreferences'
]
sourceSets
{
main
{
manifest
.srcFile
'java/io/material/catalog/AndroidManifest.xml'
java
.srcDir
'java'
java
.includes
= srcDirs
.collect
{
'io/material/catalog/' + it
+ '/**/*.java'
}
java
.excludes
= [
'**/build/**',
]
res
.srcDirs
= ['java/io/material/catalog/res']
srcDirs
.forEach
{
res
.srcDirs
+= 'java/io/material/catalog/' + it
+ '/res'
}
}
// androidTest
.java
.srcDir
'androidTest/javatests'
// test
.java
.srcDir
'test/javatests'
}
自定义方法:
api
compatibility("annotation")
api
compatibility("appcompat")
api
compatibility("cardview")
自定义一个方法:
def
compatibility(name
) {
switch (name
) {
case "annotation":
return "androidx.annotation:annotation:${androidXVersions.annotation}"
case "appcompat":
return "androidx.appcompat:appcompat:${androidXVersions.appCompat}"
default:
throw new IllegalArgumentException("No mapping exists for name: $name.")
}
}
ext
{
compileSdkVersion
= 29
minSdkVersion
= 14
targetSdkVersion
= 29
androidXVersions
= [
annotation
: '1.0.1',
appCompat
: '1.1.0',
cardView
: '1.0.0',
dynamicanimation
: '1.0.0',
]
testRunnerVersion
= '1.1.0'
espressoVersion
= '3.1.0'
mockitoCoreVersion
= '2.25.0'
truthVersion
= '0.45'
}
转载请注明原文地址:https://tech.qufami.com/read-7611.html