2

I am facing build error, while compiling Main project for custom build configuration in the below project setup.But i don't get build errors for Debug config.

MainProject ( Mixed Objective-C and Swift)
 |_ SubProject1 ( Only Objective-C)

MainProject build configs :
 |_ Debug
 |_ Inhouse
 |_ Adhoc
 |_ Store

SubProject1 build configs:
 |_ Debug
 |_ Release

Pod File:

workspace 'MainProject.xcworkspace'
platform :ios, '9.0'

target 'MainProject' do
   use_frameworks!

   def shared_pods
     # all the pods go here
     pod 'CocoaLumberjack/Swift'
   end

   target 'MainProject' do
     project 'MainProject'
     shared_pods
   end

   target 'SubProject1' do
     project 'Subprojects/SubProject1/Subproject1'
     shared_pods
   end
end

Both Main project and sub project uses Cocoalumberjack. Since subproject is a obj-c project, it uses cocoalumberjack obj-c version with following import statement.

#import "CocoaLumberjack/CocoaLumberjack.h"

while the debug config is build, there is no build failure. But when the Inhouse/Adhoc/Store config is build, it is not able to find cocoalumberjack header file in the header search path. From the build logs, i can infer that,

When Main project Debug config is build, same config is used for building pods and subprojects. So, Pods are placed in Debug-iphonesimulator path. Since subprojects have Debug config, it also refer the pod headers in Debug-iphonesimulator path.So build succeeds.

when other custom config in Mainproject is build,let say, Inhouse, Pods are placed in Inhouse-iphonesimulator path. Since subproject doesn't have Inhouse config, it defaults to release config. This leads to searching cocoalumberjack header file in release intermediate path, while building subprojects. But Cocoalumberjack headers is not present in release config path but present in Inhouse intermediate path. This results in build error. Please find the build error log below.

CompileC /Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Intermediates/Subproject1.build/Release-iphonesimulator/SubProject1.build/Objects-normal/x86_64/SubProject1.o

/Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Intermediates/Subproject1.build/Release-iphonesimulator/SubProject1.build/SubProject1-generated-files.hmap -F/Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Products/Release-iphonesimulator

> -F/Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Products/Release-iphonesimulator/CocoaLumberjack -iquote /Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Products/Release-iphonesimulator/CocoaLumberjack/CocoaLumberjack.framework/Headers -c /Users/someusername/Anand/iOS/Practices/StackOverflow/MainProject/Subprojects/SubProject1/SubProject1/SubProject1.m -o /Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Intermediates/Subproject1.build/Release-iphonesimulator/SubProject1.build/Objects-normal/x86_64/SubProject1.o

In file included from /Users/someusername/Anand/iOS/Practices/StackOverflow/MainProject/Subprojects/SubProject1/SubProject1/SubProject1.m:10: /Users/someusername/Anand/iOS/Practices/StackOverflow/MainProject/Subprojects/SubProject1/SubProject1/Logger.h:9:9: fatal error: 'CocoaLumberjack/CocoaLumberjack.h' file not found

import "CocoaLumberjack/CocoaLumberjack.h"

    ^ 1 error generated.

Could someone help me in resolving this build error for custom configs? Please let me know if more details is needed.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Anand
  • 1,820
  • 2
  • 18
  • 25

1 Answers1

0

This should fix your issue:

Step 1

Update your Podfile with this:

workspace 'MainProject.xcworkspace'
platform :ios, '9.0'
use_frameworks!

def shared_pods
  # all the pods go here
  pod 'CocoaLumberjack/Swift'
end

target 'MainProject' do
 project 'MainProject'
 shared_pods
end

target 'SubProject1' do
 project 'Subprojects/SubProject1/Subproject1'
 shared_pods
end

Step 2

Run this command on terminal for uninstall pod from project for clean install it later:

pod deintegrate

Step 3

remove Podfile.lock

rm -rf Podfile.lock

Step 4

Run install again:

pod install

Step 5

If you're using Lumberjack as a framework, you can import like:

@import CocoaLumberjack

Hope it'll fix, please let me know the result...

Note:

Alternatively you can try NSLogger works with mixed objective-c + swift projects too.

Also other alternatives

MGY
  • 7,245
  • 5
  • 41
  • 74
  • Thanks @gyer. But still i am getting same build error after modifying the pod file as you suggested. – Anand Aug 21 '17 at 14:09
  • You're welcome @Anand, I just added step 5, sorry I forget that at first time:) – MGY Aug 21 '17 at 18:52
  • I still get the same error after changing the import statement. Getting "Module 'Cocoalumberjack' not found" error. – Anand Aug 22 '17 at 04:42
  • Try to use pod 'CocoaLumberjack' for subproject, and 'CocoaLumberjack/Swift' pod for main project. Hybrid projects can be really headache. Better not use shared for this pod maybe. Please try and let me know the result. I'll update my answer if it's works. – MGY Aug 22 '17 at 05:50
  • Tried that.But got the following error during pod install. "[!] The 'Pods-MainProject' target has frameworks with conflicting names: cocoalumberjack." I think we cannot use different subspecs of same pod in the project. – Anand Aug 22 '17 at 15:25