@@ -2188,19 +2188,43 @@ public static void UpdateProjectDeps(
2188
2188
podPathToProjectPaths [ filename . Substring ( podsDir . Length + 1 ) ] =
2189
2189
filename . Substring ( pathToBuiltProject . Length + 1 ) ;
2190
2190
}
2191
+
2192
+ var podsProjectPath = GetProjectPath ( podsDir , PODS_PROJECT_NAME ) ;
2193
+ UnityEditor . iOS . Xcode . PBXProject podsProject = null ;
2194
+
2195
+ if ( File . Exists ( podsProjectPath ) ) {
2196
+ podsProject = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
2197
+ podsProject . ReadFromString ( File . ReadAllText ( podsProjectPath ) ) ;
2198
+ }
2199
+
2191
2200
// Add a reference to each source file in the target project.
2192
2201
foreach ( var podPathProjectPath in podPathToProjectPaths ) {
2193
- project . AddFileToBuild (
2194
- target ,
2195
- project . AddFile ( podPathProjectPath . Value ,
2196
- podPathProjectPath . Value ,
2197
- UnityEditor . iOS . Xcode . PBXSourceTree . Source ) ) ;
2198
- // Some source pods (e.g Protobuf) can include files relative to the Pod root,
2199
- // add include paths relative to the Pod's source files for this use case.
2200
- project . UpdateBuildProperty (
2201
- new [ ] { target } , "USER_HEADER_SEARCH_PATHS" ,
2202
- new [ ] { "$(SRCROOT)/" + Path . GetDirectoryName ( podPathProjectPath . Value ) } ,
2203
- new string [ ] { } ) ;
2202
+ // Get the relative path inside 'Pods/'.
2203
+ var sourceFilePathInPod = podPathProjectPath . Value . Substring ( PODS_DIR . Length + 1 ) ;
2204
+
2205
+ // Only add source files that are included in the Pod project, this way we
2206
+ // can avoid adding source files that are not part of the Pod dependencies.
2207
+ if ( podsProject != null && podsProject . ContainsFileByRealPath ( sourceFilePathInPod ,
2208
+ UnityEditor . iOS . Xcode . PBXSourceTree . Source ) )
2209
+ {
2210
+ Log ( "Adding source file " + sourceFilePathInPod + " to Xcode project." , true ) ;
2211
+ project . AddFileToBuild (
2212
+ target ,
2213
+ project . AddFile ( podPathProjectPath . Value ,
2214
+ podPathProjectPath . Value ,
2215
+ UnityEditor . iOS . Xcode . PBXSourceTree . Source ) ) ;
2216
+ // Some source pods (e.g Protobuf) can include files relative to the Pod root,
2217
+ // add include paths relative to the Pod's source files for this use case.
2218
+ project . UpdateBuildProperty (
2219
+ new [ ] { target } , "USER_HEADER_SEARCH_PATHS" ,
2220
+ new [ ] { "$(SRCROOT)/" + Path . GetDirectoryName ( podPathProjectPath . Value ) } ,
2221
+ new string [ ] { } ) ;
2222
+ }
2223
+ else
2224
+ {
2225
+ Log ( "Skipping adding source file " + sourceFilePathInPod +
2226
+ " to Xcode project due to it is not part of the pod project" , true ) ;
2227
+ }
2204
2228
}
2205
2229
2206
2230
// Each source pod library target name shares the name of the directory containing
@@ -2348,11 +2372,9 @@ public static void UpdateProjectDeps(
2348
2372
}
2349
2373
2350
2374
// Attempt to read per-file compile / build settings from the Pods
2351
- // project.
2352
- var podsProjectPath = GetProjectPath ( podsDir , PODS_PROJECT_NAME ) ;
2353
- if ( File . Exists ( podsProjectPath ) ) {
2354
- var podsProject = new UnityEditor . iOS . Xcode . PBXProject ( ) ;
2355
- podsProject . ReadFromString ( File . ReadAllText ( podsProjectPath ) ) ;
2375
+ // project. Note that we have a valid podsProject if Pod pbxproj exists.
2376
+ // We have a valid podsProject if Pod pbxproj exists.
2377
+ if ( podsProject != null ) {
2356
2378
foreach ( var directory in Directory . GetDirectories ( podsDir ) ) {
2357
2379
// Each pod will have a top level directory under the pods dir
2358
2380
// named after the pod. Also, some pods have build targets in
0 commit comments