我想使用gradle为我自己的项目制作一个android库,将一些typescript文件编译成JS并将其添加到android asset文件夹中。
我不想让 gradle 做任何 java 的事情。
每当
src
目录下的文件发生更改时,如何告诉 gradle 进行构建?
plugins {
id "com.android.library"
}
// a wrapper closure around executing a string
// can take either a string or a list of strings (for arguments with spaces)
// prints all output, complains and halts on error
def runCommand = { strList ->
if(strList instanceof GString) strList = strList.toString()
assert (strList instanceof String ||
(strList instanceof List && strList.each { it instanceof String }) \
)
def proc = strList.execute()
proc.in.eachLine { line -> println line }
proc.out.close()
proc.waitFor()
print "[INFO] ( "
if (strList instanceof List) {
strList.each { print "${it} " }
} else {
print strList
}
println " )"
if (proc.exitValue()) {
println "gave the following error: "
println "[ERROR] ${proc.getErrorStream()}"
}
assert !proc.exitValue()
}
def src = new File(projectDir, "src").absolutePath
def build = new File(projectDir, "output").absolutePath
tasks.register('buildWeb') {
mustRunAfter tasks.build
group "Build"
description "Builds the web side of Sharing app"
doFirst {
runCommand "npm run build --prefix $src"
}
}
android {
compileSdk 34
namespace "src"
sourceSets {
main.assets.srcDirs += build
}
}