@@ -65,4 +65,53 @@ dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.22"
|
||||
implementation 'androidx.webkit:webkit:1.8.0'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
||||
// JSONObject is provided by Android SDK (org.json)
|
||||
}
|
||||
|
||||
// Task: package webapp assets into a zip for release and optionally upload
|
||||
def webappSrc = file("src/main/assets")
|
||||
def webappZip = file("${buildDir}/outputs/webapp/webapp.zip")
|
||||
|
||||
tasks.register("zipWebApp") {
|
||||
group = "release"
|
||||
description = "Create zip of web assets (app/src/main/assets -> webapp.zip)"
|
||||
inputs.dir(webappSrc)
|
||||
outputs.file(webappZip)
|
||||
doLast {
|
||||
webappZip.parentFile.mkdirs()
|
||||
ant.zip(destfile: webappZip) {
|
||||
fileset(dir: webappSrc)
|
||||
}
|
||||
println "Created webapp zip: ${webappZip.absolutePath}"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("uploadWebApp") {
|
||||
group = "release"
|
||||
description = "Upload webapp zip to remote server if UPLOAD_WEBAPP_URL is set"
|
||||
dependsOn "zipWebApp"
|
||||
doLast {
|
||||
def uploadUrl = System.getenv('UPLOAD_WEBAPP_URL')
|
||||
def token = System.getenv('UPLOAD_WEBAPP_TOKEN')
|
||||
if (!uploadUrl) {
|
||||
println "UPLOAD_WEBAPP_URL not set, skipping upload"
|
||||
return
|
||||
}
|
||||
if (!webappZip.exists()) {
|
||||
throw new GradleException("webapp zip not found: ${webappZip}")
|
||||
}
|
||||
println "Uploading webapp to ${uploadUrl}"
|
||||
def cmd = ["curl", "--fail", "-X", "PUT", "-H", "Content-Type: application/zip"]
|
||||
if (token) {
|
||||
cmd += ["-H", "Authorization: Bearer ${token}"]
|
||||
}
|
||||
cmd += ["--data-binary", "@${webappZip.absolutePath}", uploadUrl]
|
||||
def process = cmd.execute()
|
||||
process.in.eachLine { println it }
|
||||
process.err.eachLine { System.err.println it }
|
||||
def rc = process.waitFor()
|
||||
if (rc != 0) throw new GradleException("Upload failed with exit code ${rc}")
|
||||
println "Upload successful"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user