如何设置 Kotlin/Native 项目以便将资源与可执行文件放在一起?
How to set up a Kotlin/Native project so that it places resources alongside the executables?
我的 Kotlin/Native 项目的目标是 windows exe 文件。
我想将一个文本文件(我们称之为 resource.txt)与 exe 文件一起发送,目标是在构建目录中,我将有一个包含构建的 exe 文件和资源文件的目录(这样我需要做的就是将该目录复制到例如 C:\Program Files\MySoftware).
在 Android,我会把这些类型的文件放在 assets 目录中,它们会被捆绑在 APK 中。
是否有 Kotlin/Native 的等价物?
基本上我想将文本文件放在 Kotlin 代码旁边(例如 commonMain/resources)
然后我想得到一个构建输出目录,其中包含构建的 exe 文件以及文本文件。
有没有标准化的方法来做到这一点?或者我是否需要创建自己的 gradle 脚本来捆绑我的 exe + 其他文件?
它被跟踪为支持(Gradle 任务,或者可能是编译器)但尚不可用,因此必须是自定义 Gradle 任务
youtrack
正如@Dmitri 所回答的那样,它还没有实现(参见 on youtrack , or an issue on github )
我用一组 gradle 任务解决了这个问题:
package
:将发布二进制文件复制到新目录 package
packageToZip
: 为了方便起见,从包目录制作一个 zip。
runPackaged
: 在包目录中执行二进制文件,其中存在所需的资源文件。
tasks {
val thePackageTask = register("package", Copy::class) {
group = "package"
description = "Copies the release exe and resources into one directory"
from("$buildDir/processedResources/myprojectname/main") {
include("**/*")
}
from("$buildDir/bin/myprojectname/releaseExecutable") {
include("**/*")
}
into("$buildDir/packaged")
includeEmptyDirs = false
dependsOn("myprojectnameProcessResources")
dependsOn("assemble")
}
val zipTask = register<Zip>("packageToZip") {
group = "package"
description = "Copies the release exe and resources into one ZIP file."
archiveFileName.set("packaged.zip")
destinationDirectory.set(file("$buildDir/packagedZip"))
from("$buildDir/packaged")
dependsOn(thePackageTask)
}
named("build").get().dependsOn(zipTask.get())
val runPackaged = register<Exec>("runPackaged") {
group = "package"
description = "Run the exe file in the \"packaged\" directory."
workingDir = File("$buildDir/packaged")
dependsOn(thePackageTask)
}
}
这可能会得到改进,这样就不必对构建目录名称和项目名称进行硬编码,但这对我有用 ;-)
我的 Kotlin/Native 项目的目标是 windows exe 文件。 我想将一个文本文件(我们称之为 resource.txt)与 exe 文件一起发送,目标是在构建目录中,我将有一个包含构建的 exe 文件和资源文件的目录(这样我需要做的就是将该目录复制到例如 C:\Program Files\MySoftware).
在 Android,我会把这些类型的文件放在 assets 目录中,它们会被捆绑在 APK 中。
是否有 Kotlin/Native 的等价物? 基本上我想将文本文件放在 Kotlin 代码旁边(例如 commonMain/resources) 然后我想得到一个构建输出目录,其中包含构建的 exe 文件以及文本文件。
有没有标准化的方法来做到这一点?或者我是否需要创建自己的 gradle 脚本来捆绑我的 exe + 其他文件?
它被跟踪为支持(Gradle 任务,或者可能是编译器)但尚不可用,因此必须是自定义 Gradle 任务 youtrack
正如@Dmitri 所回答的那样,它还没有实现(参见 on youtrack , or an issue on github )
我用一组 gradle 任务解决了这个问题:
package
:将发布二进制文件复制到新目录package
packageToZip
: 为了方便起见,从包目录制作一个 zip。runPackaged
: 在包目录中执行二进制文件,其中存在所需的资源文件。
tasks {
val thePackageTask = register("package", Copy::class) {
group = "package"
description = "Copies the release exe and resources into one directory"
from("$buildDir/processedResources/myprojectname/main") {
include("**/*")
}
from("$buildDir/bin/myprojectname/releaseExecutable") {
include("**/*")
}
into("$buildDir/packaged")
includeEmptyDirs = false
dependsOn("myprojectnameProcessResources")
dependsOn("assemble")
}
val zipTask = register<Zip>("packageToZip") {
group = "package"
description = "Copies the release exe and resources into one ZIP file."
archiveFileName.set("packaged.zip")
destinationDirectory.set(file("$buildDir/packagedZip"))
from("$buildDir/packaged")
dependsOn(thePackageTask)
}
named("build").get().dependsOn(zipTask.get())
val runPackaged = register<Exec>("runPackaged") {
group = "package"
description = "Run the exe file in the \"packaged\" directory."
workingDir = File("$buildDir/packaged")
dependsOn(thePackageTask)
}
}
这可能会得到改进,这样就不必对构建目录名称和项目名称进行硬编码,但这对我有用 ;-)