Using Appcode with Kotlin/Native and Cocoapods - ios

I'm starting to use Kotlin/native and Appcode for iOS development. I'm trying to get Cocoapods to work with Kotlin/native, but I'm having some challenges.
I've started with the empty Kotlin/native application in AppCode and built that, it builds fine and runs in the Emulator.
Then I try to add Cocoapods with "AFNetworking" I run into trouble. I have tried to follow the JetBrains Kotlin/native sample : https://github.com/JetBrains/kotlin-native/tree/master/samples/cocoapods , but still no luck.
The problems that I'm facing is :
I'm not able to import the cocoapods.AFNetworking in my Kotlin file.
I'm getting the following error when I try to build the project : "Cannot perform cinterop processing for AFNetworking: cannot determine headers location."
I might have overlooked some configurations, but I cant't figure it out.
I'm using Appcode 2019.3.1 , Xcode 11.3(11C29) and Cocoapods 1.8.4
My Podfile looks like this :
My Gradle file looks like this :
My main.kt file looks like this :
Any help is appreciated.

You have to build the project from Xcode first.
Generate the podspec using the podspec gradle task and modify that accordingly then add that to your Podfile
target 'project' do
...
pod 'YourFrameworkName', :path => 'path/to/your-kotlin-library'
end
You could check it here:
https://kotlinlang.org/docs/reference/native/cocoapods.html#interoperability
Edit:
Also, here's a sample of a Kotlin/Native using AFNetworking in the Kotlin code. https://github.com/JetBrains/kotlin-native/tree/master/samples/cocoapods
Edit 2:
Again, you have to link the K/N project to your Xcode Project and build it there.
Step 1: Add the pod to your Gradle file
kotlin {
cocoapods {
...
pod("AFNetworking")
}
}
Step 2: Generate the podspec file through ./gradlew shared-module:podspec
This will generate the podspec file which you might have to modify before building.
Step 3: Use this in your Podfile
target 'project' do
...
pod 'YourFrameworkName', :path => 'path/to/your-kotlin-library'
end
Step 4: pod install
Step 5: Build it in Xcode
After that, you'll be able to reference it in K/N by importing cocoapods.AFNetworking.*

Thanks for the instructions Kurt. I tried to follow them , but still run into problems.
Starting new project in Appcode ( test1) , build ok in Appcode. Opening same project in Xcode , builds ok.
Adds the Cocoapod plugin reference and the pod to my Gradle file and also sets version= "1.0"
Runs the podspec task
Issues "pod setup" , and "pod init"
Adds the pod enty into the Podfile : "pod 'test1', :path => '/Users/trond/Desktop/test1/test1'" . (This comes from the output of podspec)
Issues "pod install"
Reopens Xcode with project : "test1.xcworkspace' and tries to build. It fails with a permision error on "gradlew"
Fixing permisions on "gradlew" with "chmod 777 gradlew"
Tries to build with Xcode again, it fails with : "Project 'test1' not found in root project 'test1' . The task that fails is : "$REPO_ROOT/../Supporting Files/gradlew" -p "$REPO_ROOT" :test1:syncFramework -Pkotlin.native.cocoapods.target=$KOTLIN_TARGET -Pkotlin.native.cocoapods.configuration=$CONFIGURATION -Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" -Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" -Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS""
$REPO_ROOT = PODS_TARGET_SRCROOT =/Users/trond/Desktop/test1/Pods/../test1

Related

AppCenter build fails with no such module

My automatic iOS build on AppCenter fails with the following error (snippet):
ViewController.swift:10:8: error: no such module 'MBCircularProgressBar'
import MBCircularProgressBar
^
But I don't know what the problem might be. I'm using CocoaPods to import that framework.
My Podfile looks like this (removed all other pods):
target 'MyApp' do
use_frameworks!
pod 'MBCircularProgressBar'
end
And I have a Post Clone script appcenter-post-clone.sh which is recognized in AppCenter that contains:
#!/usr/bin/env bash
pod repo update
pod install
EDIT: After moving the offending file down in the list of files to compile, I get the same error for another CocoaPod. So it seems to me that no CocoaPods are being found
What is going wrong here?
Can you check you are building your projects workspace? You'll need to build the workspace in orde to get Cocoapods to work, not the Xcode project.

RealmSwift: No such module 'RealmSwift'

I configured RealmSwift 1.0.0 Latest Using Docs into the Xcode project. After installation i created a class file and getting module error - like: No such module 'RealmSwift' in class file.
1.
2.
3.
4.
After adding the Realm Plugin, i created a class and get the module error below.
Please help me to solve this error.
A very important sanity check: if you run into this and you're using Cocoapods, please make sure you open the .xcworkspace and not the .xcodeproj file!
Follow below steps, it may be useful for you.
Go To: Product > Schemes > New Scheme...
Select: RealmSwift and click OK
Build the RealmSwift target (cmd + b)
It looks like you've added the path to RealmSwift.framework to your framework search paths. The Realm Swift installation instructions say to add the parent path of RealmSwift.framework (i.e., the containing directory) to your framework search paths.
I had the same problem like you.
I resolved it by add the following code into pod file.
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
Follow below instructions:
Clean from Xcode (Shift+Cmd+K)
Delete the Derived Data directory (~/Library/Developer/Xcode/DerivedData)
Build the project (Cmd+B)
After "pod install" or "pod update" fix it
else
try this:
sudo gem install cocoapods-deintegrate cocoapods-clean
pod deintegrate
pod cache clean --all
rm Podfile
pod "deinitialize" to fix that issues.
I've struggled with this problem as well for 2 hours; I tried several things, like cleaning, uninstalling and reinstalling the Realm pod, changing the Podfile, and so on.
Nothing worked until I restarted the computer.
I use Xcode 8.3.3 and Xcode 9.2 Beta, Swift 3, High Sierra MacOS.
After "pod install" restart Xcode
You can add Run script file for your project.
"${SRCROOT}/Pods/Target Support Files/Pods-Realm Database/Pods-Realm Database-frameworks.sh"
For me there first was an error like 'could not build Objective-C module 'RealmSwift'' which I could fix by deleting the Derived Data Folder, Pods Folder, Podfile.lock and the .xcworkspace and after that there was the error saying 'No such module 'RealmSwift'' which only disappeared when I first tried to build the project. Now everything works fine for me!
In my case i tried other suggested solutions and it didn't work for me but this replacement fixed problem and the error have gone
Try use
pod 'RealmSwift'
instead
pod 'Realm', '~> 10.1'
Let me tell you how I get that error and how I solved it.
I am using Carthage in my project, but I am new team member, so I did git clone the project. But I opened the project before run cathage upload command. Although I ran the cathage command, I got that error.
I could fix it doing the next:
Go to the project file.
In build phaces -> run script -> Input file.
Add $(SRCROOT)/Carthage/Build/iOS/Realm.framework and
$(SRCROOT)/Carthage/Build/iOS/RealmSwift.framework
I do not know why it is not always automatically linked.
In my case, setting project format to current Xcode version in pod target helped:

"No such module 'Alamofire'" Xcode won't recognize Alamofire framework

I realize that the same error was asked in other questions (like here), but their solutions are not working for me.
I keep getting a build failure in my app: "No such module 'Alamofire'". I followed the cocoadocs installation instructions (here) for installing Alamofire and it still is not working. I made sure everything has the same deployment target.
Embedded Binaries and Frameworks
Here's my podfile text.
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘9.2’
use_frameworks!
target 'MyApp' do
pod 'Alamofire', '~> 3.0'
end
target 'MyAppTests' do
end
target 'MyAppUITests' do
end
Also, I tried "$ pod install" again in Terminal and got this message:
[!] The `App [Debug]` target overrides the `EMBEDDED_CONTENT_CONTAINS_SWIFT` build setting defined in `Pods/Target Support Files/Pods-App/Pods-App.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
After following Sohil's suggestions, XCode now recognizes the Alamofire module, but 22 new issues have arisen.
Update #2: So I'm now on Xcode 7.3 and Swift 2.2, but I'm receiving a new error with the workspace Link: "ld: framework not found Alamofire. clang: error: linker command failed with exit code 1 (use -v to see invocation)."
Do the following things and you can import any swift file from "Pods"
1) Clean your project
2) Make sure that all your "Pods" > "Build Settings" > "Build Active
Architecture Only" is set to "NO".
3) Don't run, just build your project.
4) Now, import any file from "Pods" to any swift file
E.g.: import Alamofire
5) Again, build project and it will work as expected. Finally, you can
access it properties
Update:
For the updated question, I hope you are using Xcode 7.3 so please update the Alamofire to Swift 2.2
Hope this helps!
Please check this screenshot
and compare to your build setting
may this is helpful to you
For me the solution was to open the "App".xcworkspace as pointed by the cocoapods documentation
The steps was:
Close project
Close xcode
Go to terminal
type "open |App|.xcworkspace"
When I opened Xcode it was still pointing the error then I built the project (cmd+b) and everything is fine now.
The target overrides the OTHER_LDFLAGS build setting.
Use the $(inherited) flag in TARGENTS -> Build Settings -> Framework Search Paths
in my case, i couldn't run archive after change bundle name. I've cleaned build folder and run pod install then everything worked fine.

Cannot install third party library

I keep trying to add https://github.com/jessesquires/JSQMessagesViewController into my project but it keeps coming up with a linking error.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't know what I am doing wrong I can't seem to add the demo into a blank project and get it to work.
This is what I'm doing:
I download the zipfile which contains the demo project folder (not an entire xcode project, just the .h and .m files needed for the demo).
I open a blank xcode project and insert the demo project folder.
I delete the blank project's plist, storyboard, main and app delegate files.
From the terminal, I cd into the project and make a podfile that looks like this:
platform :ios, '7.0'
pod 'JSQMessagesViewController'
pod 'JSQSystemSoundPlayer'
I run pod install.
I open the project in its new workspace that has the pods and I try to run it.
It throws the linking error.
What step am I missing? I see on the GitHub installation process it says:
#import <JSQMessagesViewController/JSQMessages.h> // import all the things
but I don't know what that means. I figured it meant something about updating your headers seach path but when I look at that under Build Settings its already pointing to the header file in the pods.
Is there an obvious step I'm missing when adding a third party library?
I installed JSQMessagesViewController through cocoapods in my project, I did not get any errors successfully installed.Please try the following steps:
Open Terminal and navigate to the directory containing your project by using the cd command:
cd ~/Path/To/Folder/Containing/Project
Next enter this command: pod init
Type this command to open Podfile using Xcode for editing:open -a Xcode Podfile.
Copy and paste this line: pod 'JSQMessagesViewController', '6.1.3' and save it.
Type this command: pod install
This installs dependent libraries related to JSQMessagesViewController and JSQSystemSoundPlayer.
After this close the project and go to your project folder ,use the workspace intead of xcodespace : yourProject.xcworkspace. Hope this post might help you.
1.Open a brand new project from Xcode, do not delete anything.
2.cd ~/ROOT_PATH_OF_YOUR_PROJECT
3.Edit your Podfile if your already had one
Podfile
platform :ios, '7.0'
pod 'JSQMessagesViewController'
pod 'JSQSystemSoundPlayer'
4.run pod install
5.open yourproject.xcworkspace
6.Build

Pod CoreData+MagicalRecord.h file not found

I recently had to delete a xcode project from my computer and re-clone it down. After cloning it, I ran a pod install and then went to build the project. However, I kept hitting a error in my .pch file that claimed a file (a pod file) was not found.
I looked into the following SO posts:
iOS - Build fails with CocoaPods cannot find header files
Unit Test build failing when importing MagicalRecord
From there I gathered that I needed to add to Header Search Paths the $(inherited) flag. I've done that, I've cleaned the project, and then re-built it, and still am having the following error..
As of version 2.3.0 (released on 1 June 2015) the file CoreData+MagicalRecord.h seems to have been renamed to MagicalRecord.h only.
If you installed MagicalRecord using CocoaPods and ran pod install or pod update again you might have gotten this new version and will end up with the same error message: CoreData+MagicalRecord.h file not found
So you should change the import of the header in your pch file then. This is what I have now:
Try to add this line on top of your podfile:
link_with ['ProjectName', 'ProjectNameTests']
before this line
platform :ios, '8.0'
Install pod, and at your project Build Setting->Other Linker Flags, add $(inherited).
import "MagicalRecord/MagicalRecord.h"
Try to run command (1) in terminal, then add import in step (2)
In your project directory,run pod update
You should now be able to add
#import <MagicalRecord/CoreData+MagicalRecord.h>
to any of your target's source files and begin using MagicalRecord!
I think with 2 steps you can be solved this problem.

Resources