Browse Source

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
pull/2414/head
Nikita Lipsky 2 years ago committed by GitHub
parent
commit
aecf6bb9a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/configureTaskToGenerateXcodeProject.kt
  2. 41
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerConnectedDeviceTasks.kt
  3. 12
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/tasks/ExperimentalPackComposeApplicationForXCodeTask.kt

10
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/configureTaskToGenerateXcodeProject.kt

@ -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"

41
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerConnectedDeviceTasks.kt

@ -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
)
}
}

12
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/tasks/ExperimentalPackComposeApplicationForXCodeTask.kt

@ -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) {

Loading…
Cancel
Save