Kotlin-Native CompileKotlinIos task fails beacuse Cinterop task can not update when I change Objective-C code - kotlin-native

#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.
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:
and my cinterop configuration looks like this:

Related

Adding unit tests for an existing objective c + swift project

I have an existing iOs project which I would like to add a unit test target to. The classes I'd like to test are both in objective c and swift.
I've managed to create a test target which allows me to test swift only code by adding the implementation swift files to the test target.
However, as soon as I import or use a class that imports objective c code, I run into Linker issues when building the test target:
...
Symbols not found for architecture x86_64
I've tried adding the objectivec mm files to my target which gets my passed the linker error, but I then get an unresolved identifier error for the class I'm importing.
I'm using xcode 9 and swift 3.
edit: I think this may have something to do with the fact the swift bridging header is not available in the test target, however I'm not sure how to add it.
Your test project is a separate target and should have all files it relies upon to be tested linked separately. So first of all click one of the .m files it's missing and check if the test project is also included in the targets. If this is the case there might be a problem with the bridging header your test project uses. Figure out which one it uses from the build settings of your target and see if it includes the same files as your main project.

Import ResearchKit breaks my build for UnitTests

I am trying to use Research Kit in my iOS app (Xcode 8 and Swift 3), so I installed it using CocoaPods. Before that, I already had some Unit and UI tests.
I'm able to use Research Kit modules, but when I try to run all of my tests, the build fails. I noticed that this just happens with the Unit tests, not with the UI tests.
Some of the errors are:
Include of non-modular header inside framework 'Researchkit.ORKVideoInstructionStep'
Include of non-modular header inside framework 'Researchkit.ORKVideoCaptureStep'
Duplicate interface definition
Property has a previous declaration
This happens if I just use import ResearchKit. If I comment the import, the test builds successfully.
I already tried other solutions like checking the files are public and putting some script at the bottom of the Podfile but doesn't fix my problem.
EDIT: I removed ResearchKit and imported it again but directly with the Xcode folder from the repo, and this time my Unit tests build successfully.
Maybe it's a problem with Cocoapods? I did some research but I still can't solve this. Maybe I just have to use ResearchKit with the "Embedded Binaries" approach.

Unit Testing Issue in Xcode

I have recently integrated XCTest into my project. It works fine when I run test cases using the play button in source editor or Using the play button in test navigator. My problem is, when I use the Test Button (The Spanner like symbol) in the ToolBar I am getting compilation errors.I already have integrated pods in my project and there is a static library created by me as well.
Note : During thorough checking I figure out all the compilation errors coming in the static library created by myself.The error count is too large so compiler shows "too much error" message
Is there any additional setup needed for including the static library into tests?
This issue arise only in case of testing I can succesfuly build and run the project
Thanks
Test Succeeded Here
Compilation Error Here
Try doing a clean build to see if xcode hasn't cached anything when you try to do a full test.
Got the solution finally, the issue is because of test target added as part of my custom library. When I try to run the test from toolbar xcode try to run all the unit test targets (My main project's test and my custom library's test case ). Library's test case can't run independently because it has some coupling with main project. Remove the test target and run test cases everything perfect.

How to import own classes from your own project into a Playground

Assume a setup like this:
You have an Xcode 6 project, where you've implemented your own classes (say MyView and MyViewController) with both Objective-C and Swift
You have added a Playground into your project
In the Playground, it's possible to import modules (frameworks) like UIKit with the import keyword. How do you enable access to the project's other classes from the Playground?
Just trying to access project classes directly results with an error message:
Use of unresolved identifier 'MyView'
As of Xcode 6.0 Beta 5, it is now possible to import your own frameworks into a playground. This provides a way to share code between your applications and playgrounds, which can both import your frameworks. To do this:
Your playground must be in the same workspace as the project that produces your framework. Your workspace must contain a target that produces the framework, instead of using a pre-built framework.
You must have already built your framework. If it is an iOS framework, it must be built for a 64-bit run destination (e.g. iPhone 5s), and must be built for the Simulator.
You must have an active scheme which builds at least one target (that target's build location will be used in the framework search path for the playground).
Your "Build Location" preference (in advanced "Locations" settings of Xcode) should not be set to "Legacy".
If your framework is not a Swift framework the "Defines Module" build setting must be set to "Yes".
You must add an import statement to your playground for the framework.
Once all these conditions are fulfilled, importing your framework will work in a playground.
In Xcode 7 we introduced another mechanism that you can use to import your own classes as source, instead of importing a framework; you can read about this "Auxiliary Sources" support at http://help.apple.com/xcode/mac/8.0/#/devfa5bea3af
I actually managed to refer to other Swift files in the current project by doing this:
Create an empty Playground and place is somewhere under your project.
Open the YourPlayground.playground bundle (yes, it's a bundle = directory) in Terminal.
Edit contents.xcplayground for example with vi and add another section like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator'>
<sections>
<code source-file-name='section-1.swift'/>
<code source-file-name='section-2.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
Rename section-1.swift to section-2.swift (if you created the Playground from scratch, there should be an example section-1.swift in your bundle)
Add a hard link (symbolic link doesn't seem to work) named section-1.swift which will point outside the bundle to your Swift class file like:
ln ../../Classes/MyView.swift section-1.swift
Close Xcode and open the Playground again.
Now there should be two sections, one with the contents of your Swift class file and the other one with the example content you got from creating the Playground from scratch.
This way I can actually run code lying outside the Playground, but Xcode seems to crash more often when doing it like this.
Edit:
As of Xcode 6 beta 5 you're now able to refer to project files, as Rick Ballard instructs in his answer.
Since Beta 5 of Xcode 6 it is possible to import your code if it is in a framework. What you need to do is create a framework target, add the Swift files there and in your playground do
import ModuleName
You can look up the module name in the build settings. It's usually the same as the target name.
Remember to make the code you want to see public. You'll need to build the project before changes are available in the playground. (You'll also need to edit the playground to trigger re-execution.)
Important
Do not give the playground file the same name as the target! If you do, importing seems to work but you'll get the following error when the playground tries to execute:
Playground execution failed: error: Couldn't lookup symbols:
I wasted an hour on figuring that out. :)
I wasn't able to get it working using any of the answers here, so I started playing around and found a simple way that worked for me to import a swift class into a playground.
Just create a playground in your project, theres a directory inside it called 'sources', just drag a copy of the swift class into that folder and the playground then will have access to it.
For example:
I just put links to all my swift files in the Sources folder:
cd /path/to/project/MyPlayground.playground/Sources
ln -s ../../*.swift .
This way changes in your source file will take effect in your playground immediately. Worked very nicely.
Xcode 8.2, Swift 3.0.1, macOS Sierra
All you have to do - is write in the beginning:
import ModuleName
(assuming your playground placed in the same workspace as framework/project)
If it's doesn't work:
Rebuild your project
Recreate playground and copy all from old playground there
It solves a lot of strange errors with failed init's and imports of whatever!

Can I build a static library for iOS without using the Xcode IDE?

I can't handle the Xcode IDE for this particular project anymore!
I have a simple C project I want to build into a static library for iOS, and I don't want to use the Xcode IDE.
I'm familiar with xcodebuild but my understanding is that I'd first need to create an Xcode project to use it - and simply being able to build the project on the command line isn't my goal.
I want a standard make-style build process for this project but can't seem to find any information about doing such a thing. It seems like I can't. Is that true?
You absolutely CAN use a makefile project. It's just a matter of using the correct paths, etc...
Here's something to get you started:
iOS static lib cross-compile script

Resources