I’m unable to build an archive in Xcode so I can p...
# kotlin-native
t
I’m unable to build an archive in Xcode so I can publish a build to TestFlight. I have no issues doing a normal build to a device/simulator but the Archive option fails with the following error:
Copy code
> Task :common:generateDefCrashlytics

> Task :common:cinteropCrashlyticsIOS
Exception in thread "main" org.jetbrains.kotlin.konan.KonanExternalToolFailure: The /Users/thomas/.konan/dependencies/clang-llvm-6.0.1-darwin-macos/bin/clang command returned non-zero exit code: 1.
	at org.jetbrains.kotlin.konan.exec.Command.handleExitCode(ExecuteCommand.kt:105)
	at org.jetbrains.kotlin.konan.exec.Command.getResult(ExecuteCommand.kt:94)
	at org.jetbrains.kotlin.konan.exec.Command.getOutputLines(ExecuteCommand.kt:73)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.runCmd(main.kt:66)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:281)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:38)
	at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:67)
	at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:18)

> Task :common:cinteropCrashlyticsIOS FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':common:cinteropCrashlyticsIOS'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at <https://help.gradle.org>

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See <https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings>

BUILD FAILED in 5s
2 actionable tasks: 2 executed
Command PhaseScriptExecution failed with a nonzero exit code
I don’t know what I need to look at as the exception doesn’t really show the cause of the issue. In case it might be related; I am using the Cocoapods plugin and have a Crashlytics pod in the Gradle file. Anyone have any ideas how to proceed?
s
I haven't use the pods plugin, does it generate the .def files for you? It looks like there is a problem generating the kotlin c interop files for crashlytics. It could be that it isn't finding the framework headers or some other step is failing. Does --info or --debug provide any further clues?
t
@Sam It does generate the def files for normal (debug) builds, as they do not have any issues. So I would think that would be the same for release builds, but I am not sure how to check. I only get this error when building a release version using the “Archive” option in Xcode. I also checked the output with --info and --debug but did not find anything useful.
It started working after I removed every pod I was using from the Gradle file. So for some reason I cannot build an archive if I reference Pods in the Gradle file. Is there a way to get the real error message?
i
@Thomas The def files are the same for both debug and release builds. I cannot reproduce this error. Could you please share your buildscript or provide a link to your project?
You also can try to run the
cinterop
tool manually. Probably you will be able to get a more detailed error message. To get the arguments, run the Gradle build with
--info
and find a line starting with
Run tool: cinterop
. This line contains all arguments passed to the tool by Gradle, so you can copy them and use to run the tool manually. The
cinterop
-tool is located in
$HOME/.konan/<kotlin-native-distribution>/bin
.
t
@ilya.matveev Thank you for your help. These are the pods I included in my project:
Copy code
pod("FirebaseCore")
pod("FirebaseAnalytics")
pod("FirebaseInAppMessagingDisplay")
pod("Fabric", "~> 1.9.0")
pod("Crashlytics", "~> 3.12.0")
I ran the cinterop tool manually. I found a line like this:
Copy code
Run tool: cinterop with args: X
(replaced long output with X). I then executed the following in the terminal:
Copy code
./cinterop X
And I got the following error: https://gist.github.com/Thomas-Vos/10ff65563b69b432016859cb9a494666
I might have found the cause of the issue. My Xcode scheme name had a space in it, which caused the error I linked above. I removed the space in the scheme name and it looks like my project is building now (cinterop had no issues). I’ll try to reproduce it in a another project.
@ilya.matveev I can confirm the space in the scheme name is the issue. It fails every time with the space when doing an Archive. Without the space the Archive is successful.
i
Thank you, I'll take a look.
t
@ilya.matveev I can only reproduce it in another project using Gradle version 5.4.1. Gradle 5.1 has no issues. Are you able to reproduce the issue now?
i
@Thomas I've tried to reproduce this issue using our
cocoapods
sample and haven't managed to get the crash you described. I've added the pods you mentioned in the Kotlin project, upgraded Gradle to 5.4.1 and created a separate iOS project with a space in its scheme name (see this branch: https://github.com/JetBrains/kotlin-native/tree/repro-crashlytics). I made the following steps trying to reproduce the error: 1. Checkout the branch mentioned above and switch to the
samples/cocoapods
directory 2. Run
./gradlew podspec
in the
kotlin-library
directory 3. Run
pod install
in the
space repro
directory 4. Open the
space repro/space repro.xcworkspace
and run the Archive command for a
Generic iOS device
. Could you share a project where you reproduced the error?
t
@ilya.matveev I followed your steps and I do not get any errors. I also tried to reproduce the issue again in another project, but am unable to get the error. I tried to use the same versions for Kotlin/Gradle. I’m sorry but if I can’t reproduce it I don’t know how I could send you a sample project. In my original project I still have the error every time I add the space. I escaped the spaces in the args manually, and ran the cinterop command again. It just returned with the same error as in Xcode. I can send you the command with output in a PM if you would like to see it.
Do you want to look into this issue further or do you want to leave it as it is? I guess there's probably something wrong in my project, which causes this error if I include a space in the scheme name.
i
I can send you the command with output in a PM if you would like to see it.
Yes, please send it. Probably it will help. But run
cinterop
with
-verbose
option to get more detailed output.
Do you want to look into this issue further or do you want to leave it as it is? I guess there's probably something wrong in my project, which causes this error if I include a space in the scheme name.
The issue looks strange so I would like to investigate it. Does your project have a proprietary code? I mean is it possible to share it and use as a reproducer?