0

@Kevin Galligan My company has a iOS project using Kotlin-Native, and I add a cinterop to the project like this in build.gradle.kts:

val CommonInterop by cinterops.creating {
      defFile(project.file("${commonBridgePath}/CommonBridge.def"))
      compilerOpts("-I$commonBridgePath")
    }

Everything runs well, the ios project compiles successfully, but when I add a objective-C function in cinterop and invoke this function in kotlin file, then build ios project, Xcode tells me that kotlin-native module compile fails.

I know why the compile fails, because compiler does not create corresponding kotlin function when I add new Objective-c function.

The cinterop task is skipped, In fact the task should not be skipped because objc code changed. enter image description here

But after I run the command "gradelw clean", then rebuild the project in xcode, it runs well, objc function is invocked successfully.

Hope Kotlin-Native team can fix this bug quickly, thanks a lot!

my xcode podspec file look like this: enter image description here

and my cinterop configuration looks like this: enter image description here

yuzhiyun
  • 41
  • 3
  • Do you make changes in the header file, or in the source files? – Artyom Degtyarev Jun 02 '21 at 17:25
  • Yes, I make changes in 3 files ( 2 objc file and 1 kotlin file ) . I add a objc function declareration in objc header file and a implementation in objc source file. Then I add some kotlin code to invoke this objc function. Finaly I build the project @ArtyomDegtyarev in Xcode, xcode show errors. But after I run the command "gradelw clean", then rebuild the project in xcode, it runs well, objc function is invocked successfully. But it's a waste of time. I have to gradelw clean after I add Cinterop objc function in already existed Cinterop objc class. – yuzhiyun Jun 03 '21 at 04:13
  • Sorry, but I'm missing how exactly you build the library to interoperate with? As far as I understand, changing headers lead to cinterop tasks re-run(see https://youtrack.jetbrains.com/issue/KT-43601 for example) – Artyom Degtyarev Jun 03 '21 at 10:34
  • @ArtyomDegtyarev hi, I update two picture in my question. Maybe picture help you understand my project. In fact I find that my changing in header file does not lead to cinterop tasks re-run. But if I run 'gradlew clean',and rebuild project in XCode, the error dismiss and runs well, my newly added cinterop objc function is invoked successfully in kotlin files. So I think there is something wrong with cinterop up-to-update. Compiler cannot find I changed the objc file (as picture 3, I change KYNUderDefault.h and KYNUderDefault.m )and re-run cinterop. – yuzhiyun Jun 04 '21 at 04:19
  • I did another experiment, after the error occurs, I remove the correspoding cinterop klib file in build directory, and then build ios project in xcode,It runs successfully. Xcode log shows that : cinterop is not up-to-date, so re-run the interop. – yuzhiyun Jun 04 '21 at 08:15
  • @ArtyomDegtyarev And please add my account (yuyuyuyuyuyu329@gmail.com) in kotlinlang.slack.com ,thank you very much. My company wants to keep contact with your team. We are one of top 5 technology in China. – yuzhiyun Jun 07 '21 at 10:18
  • As I said already, right now it is unclear how exactly your `.m` file change affects your cinterop. Your project structure is not described in the question. Please try to construct a simplified project to share as an archive. – Artyom Degtyarev Jun 08 '21 at 07:27
  • @ArtyomDegtyarev hey, bro. I reproduced the bug in a demo project. https://github.com/yuzhiyunAtTencent/LostStackFrameFixedKampkit ,please run the project. After you run it successfully, add a new objc function in KYNUserDefault.h and corresponding implement in KYNUserDefault.m ,and finnaly invoke the objc function in kotlin function named "updateBreedFavorite" in NativeViewModel.kt. After you change 3 files, build this project in XCode again, the log in xcode will tell you ( Task :shared:compileKotlinIos FAILED) ,because NativeViewModel.kt has a unresloved reference :XXX. – yuzhiyun Jun 08 '21 at 12:13
  • But if I run command './gradlew clean', and rebuild the project, it works successfully. @ArtyomDegtyarev – yuzhiyun Jun 08 '21 at 12:14
  • @ArtyomDegtyarev hi, the demo project is provided, please help me find the cause. – yuzhiyun Jun 10 '21 at 08:49
  • I was able to reproduce the problem, and transferred the https://youtrack.jetbrains.com/issue/KT-43601 ticket to the developers' team. Now I'm waiting for their comment. However, as far as I understand, this problem is not a major one, so the we should be patient. – Artyom Degtyarev Jun 10 '21 at 10:50

0 Answers0