mirror of
https://github.com/recloudstream/gradle.git
synced 2024-08-14 23:56:59 +00:00
add resource compilation
This commit is contained in:
parent
7f27d97abb
commit
a6a5597c28
5 changed files with 89 additions and 2 deletions
|
@ -38,6 +38,7 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) {
|
|||
|
||||
internal var pluginClassName: String? = null
|
||||
|
||||
var requiresResources = false
|
||||
var description: String? = null
|
||||
var authors = listOf<String>()
|
||||
var adult = false
|
||||
|
|
|
@ -21,6 +21,7 @@ fun Project.makeManifest(): PluginManifest {
|
|||
pluginClassName = extension.pluginClassName,
|
||||
name = this.name,
|
||||
version = version ?: -1,
|
||||
requiresResources = extension.requiresResources
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,5 +3,6 @@ package com.lagradost.cloudstream3.gradle.entities
|
|||
data class PluginManifest(
|
||||
val pluginClassName: String?,
|
||||
val name: String,
|
||||
val version: Int
|
||||
val version: Int,
|
||||
val requiresResources: Boolean
|
||||
)
|
|
@ -0,0 +1,57 @@
|
|||
package com.lagradost.cloudstream3.gradle.tasks
|
||||
|
||||
import com.android.build.gradle.BaseExtension
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
import java.io.File
|
||||
|
||||
abstract class CompileResourcesTask : Exec() {
|
||||
@get:InputDirectory
|
||||
@get:SkipWhenEmpty
|
||||
@get:IgnoreEmptyDirectories
|
||||
abstract val input: DirectoryProperty
|
||||
|
||||
@get:InputFile
|
||||
abstract val manifestFile: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputFile: RegularFileProperty
|
||||
|
||||
override fun exec() {
|
||||
val android = project.extensions.getByName("android") as BaseExtension
|
||||
|
||||
val aaptExecutable = android.sdkDirectory.resolve("build-tools")
|
||||
.resolve(android.buildToolsVersion)
|
||||
.resolve(if (OperatingSystem.current().isWindows) "aapt2.exe" else "aapt2")
|
||||
|
||||
val tmpRes = File.createTempFile("res", ".zip")
|
||||
|
||||
execActionFactory.newExecAction().apply {
|
||||
executable = aaptExecutable.path
|
||||
args("compile")
|
||||
args("--dir", input.asFile.get().path)
|
||||
args("-o", tmpRes.path)
|
||||
execute()
|
||||
}
|
||||
|
||||
execActionFactory.newExecAction().apply {
|
||||
executable = aaptExecutable.path
|
||||
args("link")
|
||||
args(
|
||||
"-I",
|
||||
android.sdkDirectory
|
||||
.resolve("platforms")
|
||||
.resolve(android.compileSdkVersion!!)
|
||||
.resolve("android.jar")
|
||||
)
|
||||
args("-R", tmpRes.path)
|
||||
args("--manifest", manifestFile.asFile.get().path)
|
||||
args("-o", outputFile.asFile.get().path)
|
||||
execute()
|
||||
}
|
||||
|
||||
tmpRes.delete()
|
||||
}
|
||||
}
|
|
@ -55,6 +55,31 @@ fun registerTasks(project: Project) {
|
|||
it.outputFile.set(intermediates.resolve("classes.dex"))
|
||||
}
|
||||
|
||||
val compileResources = project.tasks.register("compileResources", CompileResourcesTask::class.java) {
|
||||
it.group = TASK_GROUP
|
||||
|
||||
val processManifestTask = project.tasks.getByName("processDebugManifest") as ProcessLibraryManifest
|
||||
it.dependsOn(processManifestTask)
|
||||
|
||||
val android = project.extensions.getByName("android") as BaseExtension
|
||||
it.input.set(android.sourceSets.getByName("main").res.srcDirs.single())
|
||||
it.manifestFile.set(processManifestTask.manifestOutputFile)
|
||||
|
||||
it.outputFile.set(intermediates.resolve("res.apk"))
|
||||
|
||||
it.doLast { _ ->
|
||||
val resApkFile = it.outputFile.asFile.get()
|
||||
|
||||
if (resApkFile.exists()) {
|
||||
project.tasks.named("make", AbstractCopyTask::class.java) {
|
||||
it.from(project.zipTree(resApkFile)) { copySpec ->
|
||||
copySpec.exclude("AndroidManifest.xml")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.afterEvaluate {
|
||||
project.tasks.register("make", Zip::class.java) {
|
||||
val compileDexTask = compileDex.get()
|
||||
|
@ -81,7 +106,9 @@ fun registerTasks(project: Project) {
|
|||
it.from(compileDexTask.outputFile)
|
||||
|
||||
val zip = it as Zip
|
||||
//zip.dependsOn(compileResources.get())
|
||||
if (extension.requiresResources) {
|
||||
zip.dependsOn(compileResources.get())
|
||||
}
|
||||
zip.isPreserveFileTimestamps = false
|
||||
zip.archiveBaseName.set(project.name)
|
||||
zip.archiveExtension.set("cs3")
|
||||
|
|
Loading…
Reference in a new issue