@@ -7,103 +7,43 @@ You can also reuse other libraries and frameworks from the iOS ecosystem in your
7
7
interoperability with Objective-C dependencies and Swift dependencies if their APIs are exported to Objective-C with
8
8
the ` @objc ` attribute. Pure Swift dependencies are not yet supported.
9
9
10
- Integration with the CocoaPods dependency manager is also supported with the same limitation – you cannot use pure Swift
11
- pods.
10
+ To handle iOS dependencies in Kotlin Multiplatform projects, you can manage them with the [ cinterop tool ] ( #with-cinterop )
11
+ or use the [ CocoaPods dependency manager ] ( #with-cocoapods ) (pure Swift pods are not supported) .
12
12
13
- We recommend [ using CocoaPods] ( #with-cocoapods ) to handle iOS dependencies in Kotlin Multiplatform projects.
14
- [ Manage dependencies manually] ( #without-cocoapods ) only if you want to tune the interop process specifically or if you
15
- have some other strong reason to do so.
13
+ ### With cinterop
16
14
17
- ### With CocoaPods
18
-
19
- 1 . Perform [ initial CocoaPods integration setup] ( native-cocoapods.md#set-up-an-environment-to-work-with-cocoapods ) .
20
- 2 . Add a dependency on a Pod library from the CocoaPods repository that you want to use by including the ` pod() `
21
- function call in ` build.gradle(.kts) ` of your project.
22
-
23
- <tabs group =" build-script " >
24
- <tab title =" Kotlin " group-key =" kotlin " >
25
-
26
- ``` kotlin
27
- kotlin {
28
- cocoapods {
29
- version = " 2.0"
30
- // ..
31
- pod(" SDWebImage" ) {
32
- version = " 5.20.0"
33
- }
34
- }
35
- }
36
- ```
37
-
38
- < / tab>
39
- < tab title= " Groovy" group- key= " groovy" >
40
-
41
- ```groovy
42
- kotlin {
43
- cocoapods {
44
- version = ' 2.0'
45
- // ..
46
- pod(' SDWebImage' ) {
47
- version = ' 5.20.0'
48
- }
49
- }
50
- }
51
- ```
52
-
53
- < / tab>
54
- < / tabs>
55
-
56
- You can add the following dependencies on a Pod library:
57
- * [From the CocoaPods repository](native- cocoapods- libraries.md#from- the- cocoapods- repository)
58
- * [On a locally stored library](native- cocoapods- libraries.md#on- a- locally- stored- library)
59
- * [From a custom Git repository](native- cocoapods- libraries.md#from- a- custom- git- repository)
60
- * [From a custom Podspec repository](native- cocoapods- libraries.md#from- a- custom- podspec- repository)
61
- * [With custom cinterop options](native- cocoapods- libraries.md#with- custom- cinterop- options)
62
-
63
- 3 . Run ** Reload All Gradle Projects ** in IntelliJ IDEA (or ** Sync Project with Gradle Files ** in Android Studio )
64
- to re- import the project.
65
-
66
- To use the dependency in your Kotlin code, import the package `cocoapods.< library- name> `. For the example above, it' s:
67
-
68
- ```kotlin
69
- import cocoapods.SDWebImage.*
70
- ```
71
-
72
- ### Without CocoaPods
73
-
74
- If you don' t want to use CocoaPods , you can use the cinterop tool to create Kotlin bindings for Objective - C or Swift
15
+ You can use the cinterop tool to create Kotlin bindings for Objective-C or Swift
75
16
declarations. This will allow you to call them from the Kotlin code.
76
17
77
- The steps differ a bit for [libraries](#add- a- library- without - cocoapods)
78
- and [frameworks](#add - a - framework - without - cocoapods), but the idea remains the same.
18
+ The steps differ a bit for [ libraries] ( #add-a-library ) and [ frameworks ] ( #add-a-framework ) ,
19
+ but the general workflow looks like this:
79
20
80
21
1 . Download your dependency.
81
22
2 . Build it to get its binaries.
82
- 3 . Create a special `.def` file that describes this dependency to cinterop.
23
+ 3 . Create a special ` .def ` [ definition file] ( native-definition-file.md ) that describes this dependency to cinterop.
83
24
4 . Adjust your build script to generate bindings during the build.
84
25
85
- #### Add a library without CocoaPods
26
+ #### Add a library
86
27
87
28
1 . Download the library source code and place it somewhere where you can reference it from your project.
88
-
89
29
2 . Build a library (library authors usually provide a guide on how to do this) and get a path to the binaries.
90
-
91
30
3 . In your project, create a ` .def ` file, for example ` DateTools.def ` .
92
-
93
31
4 . Add a first string to this file: ` language = Objective-C ` . If you want to use a pure C dependency, omit the language
94
32
property.
95
-
96
33
5 . Provide values for two mandatory properties:
34
+
97
35
* ` headers ` describes which headers will be processed by cinterop.
98
36
* ` package ` sets the name of the package these declarations should be put into.
99
37
100
38
For example:
39
+
101
40
``` none
102
41
headers = DateTools.h
103
42
package = DateTools
104
43
```
105
44
106
45
6. Add information about interoperability with this library to the build script:
46
+
107
47
* Pass the path to the `.def` file. This path can be omitted if your `.def` file has the same name as cinterop and
108
48
is placed in the `src/nativeInterop/cinterop/` directory.
109
49
* Tell cinterop where to look for header files using the `includeDirs` option.
@@ -173,18 +113,15 @@ property in the `.def` file. For the example above, this will be:
173
113
import DateTools.*
174
114
```
175
115
176
- #### Add a framework without CocoaPods
116
+ #### Add a framework
177
117
178
118
1 . Download the framework source code and place it somewhere that you can reference it from your project.
179
-
180
119
2 . Build the framework (framework authors usually provide a guide on how to do this) and get a path to the binaries.
181
-
182
120
3 . In your project, create a ` .def ` file, for example ` MyFramework.def ` .
183
-
184
121
4 . Add the first string to this file: ` language = Objective-C ` . If you want to use a pure C dependency, omit the
185
122
language property.
186
-
187
123
5 . Provide values for these two mandatory properties:
124
+
188
125
* ` modules ` – the name of the framework that should be processed by the cinterop.
189
126
* ` package ` – the name of the package these declarations should be put into.
190
127
@@ -196,6 +133,7 @@ import DateTools.*
196
133
```
197
134
198
135
6. Add information about interoperability with the framework to the build script:
136
+
199
137
* Pass the path to the .def file. This path can be omitted if your `.def` file has the same name as the cinterop and
200
138
is placed in the `src/nativeInterop/cinterop/` directory.
201
139
* Pass the framework name to the compiler and linker using the `-framework` option. Pass the path to the framework
@@ -266,10 +204,66 @@ import MyFramework.*
266
204
Learn more about [ Objective-C and Swift interop] ( native-objc-interop.md ) and
267
205
[ configuring cinterop from Gradle] ( multiplatform-dsl-reference.md#cinterops ) .
268
206
207
+ ### With CocoaPods
208
+
209
+ 1 . Perform [ initial CocoaPods integration setup] ( native-cocoapods.md#set-up-an-environment-to-work-with-cocoapods ) .
210
+ 2 . Add a dependency on a Pod library from the CocoaPods repository that you want to use by including the ` pod() `
211
+ function call in ` build.gradle(.kts) ` of your project.
212
+
213
+ <tabs group =" build-script " >
214
+ <tab title =" Kotlin " group-key =" kotlin " >
215
+
216
+ ``` kotlin
217
+ kotlin {
218
+ cocoapods {
219
+ version = " 2.0"
220
+ // ..
221
+ pod(" SDWebImage" ) {
222
+ version = " 5.20.0"
223
+ }
224
+ }
225
+ }
226
+ ```
227
+
228
+ < / tab>
229
+ < tab title= " Groovy" group- key= " groovy" >
230
+
231
+ ```groovy
232
+ kotlin {
233
+ cocoapods {
234
+ version = ' 2.0'
235
+ // ..
236
+ pod(' SDWebImage' ) {
237
+ version = ' 5.20.0'
238
+ }
239
+ }
240
+ }
241
+ ```
242
+
243
+ < / tab>
244
+ < / tabs>
245
+
246
+ You can add the following dependencies on a Pod library:
247
+
248
+ * [From the CocoaPods repository](native- cocoapods- libraries.md#from- the- cocoapods- repository)
249
+ * [On a locally stored library](native- cocoapods- libraries.md#on- a- locally- stored- library)
250
+ * [From a custom Git repository](native- cocoapods- libraries.md#from- a- custom- git- repository)
251
+ * [From a custom Podspec repository](native- cocoapods- libraries.md#from- a- custom- podspec- repository)
252
+ * [With custom cinterop options](native- cocoapods- libraries.md#with- custom- cinterop- options)
253
+
254
+ 3 . Run ** Reload All Gradle Projects ** in IntelliJ IDEA (or ** Sync Project with Gradle Files ** in Android Studio )
255
+ to re- import the project.
256
+
257
+ To use the dependency in your Kotlin code, import the package `cocoapods.< library- name> `. For the example above, it' s:
258
+
259
+ ```kotlin
260
+ import cocoapods.SDWebImage.*
261
+ ```
262
+
269
263
## What' s next?
270
264
271
265
Check out other resources on adding dependencies in multiplatform projects and learn more about:
272
266
273
- * [ Connecting platform-specific libraries] ( multiplatform-share-on-platforms .md#connect-platform-specific-libraries )
267
+ * [Connecting platform libraries](native - platform - libs .md)
274
268
* [Adding dependencies on multiplatform libraries or other multiplatform projects](multiplatform- add- dependencies.md)
275
269
* [Adding Android dependencies](multiplatform- android- dependencies.md)
0 commit comments