johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 565 forks source link

doesn't work with Swift/Pods combination #38

Closed seboslaw closed 9 years ago

seboslaw commented 9 years ago

Hey,

I'm having issues with my current project. It is a Swift iOS app and it has the following CocoaPods dependencies (using v0.36.0.beta.1):

target 'LingoJam' do
pod 'ReactiveCocoa', '2.4.4'
pod 'SwiftyJSON', '2.1.3'
pod 'Alamofire', '~> 1.1.3'
pod 'Dollar', '~> 2.1.0'
end

target 'LingoJamFramework' do
    pod 'SwiftyJSON', '2.1.3'    
end

target 'LingoJamFrameworkTests' do
    pod 'SwiftyJSON', '2.1.3'
end

Upon trying to inject code into my running app, I get the following error message (added a screenshot since the line-breaks are all messed up when copying):

https://www.dropbox.com/s/k39tymqm6r74sxa/Screenshot%202015-02-09%2014.35.01.png?dl=0

Here's a somewhat cleaned up GIST of the log:

https://gist.github.com/seboslaw/4876a6488264f04852d6

Seems like the project cannot be built, because SwiftyJSON (which is in the Pods-Framework) cannot be found.

johnno1962 commented 9 years ago

You may have two problems. I doubt references betweenPOD frameworks will work with injection but the immediate problem is this line in the build logs: "ls -t (null)/../Logs/Build/*.xcactivitylog” which means the build driectory is coming though as null which in turn will prevent the script from finding how to build the swift file by greping through them. This can happen if you have changed the “Derived Data” location in Xcodes preferences. The frist step is to resolve this issue. then we can look at the Pod problems.

seboslaw commented 9 years ago

Hey John,

thanks. Yeah, I had turned that back to my local directory in between. When I set the Derived Data location back to "Unique" I get the error message I was talking about:

https://gist.github.com/seboslaw/d71dc90384112191b232

(Unfortunately, the error console does not set correct line breaks. That's why the GIST is kinda messed up)

seboslaw commented 9 years ago

The main culprit seems to be this line:

ld: framework not found ReactiveCocoa for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation)

FYI. I have ReactiveCocoa as a pod in my main project.

johnno1962 commented 9 years ago

Hi, still can’t replicate your problem even with a ReactiveCocoa pod, injecting reactive Cocoa itself in my test project or spaces and single quotes in the project directory name. Have you tried deleting the “iOSInjectionProject” directory?

seboslaw commented 9 years ago

yup....no luck there either :(

ld: framework not found ReactiveCocoa for architecture x86_64

Running:

Xcode Version 6.1.1 (6A2008a) Injection: 6.1 Cocoapods: 0.36.0.beta.1

Swift project with the following Podfile:

target 'MyProject' do

pod 'ReactiveCocoa', '2.4.4'
pod 'SwiftyJSON', '2.1.3'
pod 'Alamofire', '~> 1.1.3'
pod 'Dollar', '~> 2.1.0'
pod 'Voltron', '~> 0.2.1'

end

target 'MyProjectTests' do

end

target 'MyProjectFramework' do

    pod 'SwiftyJSON', '2.1.3'
    pod 'Dollar', '~> 2.1.0'

end

target 'MyProjectFrameworkTests' do

    pod 'SwiftyJSON', '2.1.3'
    pod 'Dollar', '~> 2.1.0'

end
johnno1962 commented 9 years ago

Have you tried editing the bundle project to include the path to the ReactiveCocoa framework? Is it a framework??

seboslaw commented 9 years ago

By bundle project you mean the "iOSInjectionProject"? All those pods listed above get compiled into one framework Pods_MyProject.framework by cocoa pods, which is then added as a linked framework to my main project.

johnno1962 commented 9 years ago

To get the file to inject the iOSInjectionProject bundle project needs to build. Try adding the Pods_MyProject.framework and it’s framework path to the bundle project.

seboslaw commented 9 years ago

I tried, but it still says it cannot find some of the frameworks from the Podfile (this time it's SwiftyJSON). If you're up for it, maybe we can do a screen sharing session? Skype name is "seboslaw"

johnno1962 commented 9 years ago

ok, give me a few minutes and I’ll try to connect

johnno1962 commented 9 years ago

Thanks for the prod on this one. Swift with frameworks is kind-of the worst case for injection. The solution thankfully is not that involved. All frameworks are available in the app binary so injection can find them there to link with:

.../DerivedData/zv-glglbauxudkjajdecwpthxgocexo/Build/Products/Debug-iphonesimulator/zv.app/Frameworks: Alamofire.framework libswiftDarwin.dylib Dollar.framework libswiftDispatch.dylib ReactiveCocoa.framework libswiftFoundation.dylib SwiftyJSON.framework libswiftObjectiveC.dylib libswiftCore.dylib libswiftSecurity.dylib libswiftCoreGraphics.dylib libswiftUIKit.dylib libswiftCoreImage.dylib

johnno1962 commented 9 years ago

Hi Sebastian, I’ve pushed a minor change which links frameworks included in the app bundle into the bundle project which should mean they work now. Do you want to try downloading the new source for the plugin from github, building it and kicking the tires for me? Delete the existing iOSInjectionProject to reset the project. Cheers, John

seboslaw commented 9 years ago

Right on John! That solves it for me! Great, great work!!!