Fix compose gradle plugin for iOS device deployment: (#2407)

- Move cleaning up build directory from packComposeUikitApplicationForXCode Gradle task to registerConnectedDeviceTasks as the first one runs during xcode build and could delete files placed by xcode in parallel before (such as Info.plist).

- Remove workaround of running xcodebuild twice as the original problem the most probably was provoded by incorrect build directory cleanup

- Remove sources from xcodegen configuratiom as we do not need them in the resulting .app
This commit is contained in:
Nikita Lipsky
2022-10-17 16:50:16 +03:00
committed by GitHub
parent d457a520d7
commit aecf6bb9a1
3 changed files with 27 additions and 36 deletions

View File

@@ -42,16 +42,6 @@ internal fun Project.configureTaskToGenerateXcodeProject(
name: GradleCompile
info:
path: plists/Ios/Info.plist
properties:
UILaunchStoryboardName: ""
method: "development"
sources:
- path: "../../../src/"
excludes:
- "jvm*/**"
- "desktop*/**"
- "android*/**"
- "*Test/**"
settings:
LIBRARY_SEARCH_PATHS: "$(inherited)"
ENABLE_BITCODE: "YES"

View File

@@ -53,26 +53,27 @@ fun Project.registerConnectedDeviceTasks(
// xcrun xcodebuild -showsdks (list all sdk)
val sdk = SDK_PREFIX_IPHONEOS + getSimctlListData().runtimes.first().version
val scheme = projectName // xcrun xcodebuild -list -project . (list all schemes)
repeat(2) {
// todo repeat(2) is workaround of error (domain=NSPOSIXErrorDomain, code=22)
// The bundle identifier of the application could not be determined
// Ensure that the application's Info.plist contains a value for CFBundleIdentifier.
runExternalTool(
MacUtils.xcrun,
listOf(
"xcodebuild",
"-scheme", scheme,
"-project", ".",
"-configuration", configName,
"-derivedDataPath", "build",
"-arch", "arm64",
"-sdk", sdk,
"-allowProvisioningUpdates",
"-allowProvisioningDeviceRegistration",
),
workingDir = xcodeProjectDir
)
}
val buildDir = "build"
// cleanup build directory as xcodebuild does not do it (provoking unexpected side effects).
project.delete(xcodeProjectDir.resolve(buildDir))
runExternalTool(
MacUtils.xcrun,
listOf(
"xcodebuild",
"-scheme", scheme,
"-project", ".",
"-configuration", configName,
"-derivedDataPath", buildDir,
"-arch", "arm64",
"-sdk", sdk,
"-allowProvisioningUpdates",
"-allowProvisioningDeviceRegistration",
),
workingDir = xcodeProjectDir
)
}
}

View File

@@ -12,6 +12,8 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import java.io.File
import java.nio.file.Files
import java.nio.file.StandardCopyOption
abstract class ExperimentalPackComposeApplicationForXCodeTask : DefaultTask() {
@get:Input
@@ -32,8 +34,6 @@ abstract class ExperimentalPackComposeApplicationForXCodeTask : DefaultTask() {
@TaskAction
fun run() {
val destinationDir = destinationDir.get().asFile
project.delete(destinationDir)
project.mkdir(destinationDir)
val executableSource = kotlinBinary.get().asFile
val dsymSource = File(executableSource.absolutePath + ".dSYM")
@@ -46,14 +46,14 @@ abstract class ExperimentalPackComposeApplicationForXCodeTask : DefaultTask() {
val destFile = dsymDestination.resolve(relativePath)
destFile.parentFile.mkdirs()
if (sourceFile.name == executableSource.name) {
sourceFile.copyTo(destFile.resolveSibling(executableDestination.name))
sourceFile.copyTo(destFile.resolveSibling(executableDestination.name), true)
} else {
sourceFile.copyTo(destFile)
sourceFile.copyTo(destFile, true)
}
}
executableDestination.parentFile.mkdirs()
executableSource.copyTo(executableDestination)
// We need to preserve executable flag for resulting executable, "FileKt.copyTo" extension method does not allow this.
Files.copy(executableSource.toPath(), executableDestination.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING)
}
internal enum class UikitTarget(val simulator: Boolean, val targetName: String) {