How to Add PhoneGap sources to Xcode project

2,582 views
Skip to first unread message

John Gentilin

unread,
Apr 8, 2012, 2:34:06 AM4/8/12
to phon...@googlegroups.com
I cloned the PhoneGap sources and I can run the CordovaLibApp with full debugging
but when I try to  run one of my apps I get Exceptions. Here is what I do.

1) Delete the Cordova.framework from my project.

2) Add the CordovaLib.xcodproj to the root of my project

3) In my projects build settings, I add CordovaLib as a dependent an
I add libCordova.a in the Link Binary With Libraries section.

Then the project builds fine but when I try to run it I get the following error about the time
the splash screen should disappear.

2012-04-07 23:32:33.391 PhoneGapCamera[4608:307]  Initialized listener for icon updates
warning: Unable to read symbols for /Library/MobileSubstrate/DynamicLibraries/libstatusbar.dylib (file not found).
warning: No copy of libstatusbar.dylib found locally, reading from memory on remote device.  This may slow down the debug session.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.1/Symbols/usr/lib/libsubstrate.dylib (file not found).
warning: No copy of libsubstrate.dylib found locally, reading from memory on remote device.  This may slow down the debug session.
2012-04-07 23:32:34.320 PhoneGapCamera[4608:307] Multi-tasking -> Device: YES, App: YES
2012-04-07 23:32:34.348 PhoneGapCamera[4608:307] -[__NSCFDictionary dictionaryWithLowercaseKeys]: unrecognized selector sent to instance 0x175120
2012-04-07 23:32:34.364 PhoneGapCamera[4608:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary dictionaryWithLowercaseKeys]: unrecognized selector sent to instance 0x175120'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x344aaed3 __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x33975811 objc_exception_throw + 24
    2   CoreFoundation                      0x344ac683 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x344541d9 ___forwarding___ + 508
    4   CoreFoundation                      0x34453f90 _CF_forwarding_prep_0 + 48
    5   PhoneGapCamera                      0x00006763 -[CDVViewController viewDidLoad] + 586
    6   PhoneGapCamera                      0x00003b1b -[MainViewController viewDidLoad] + 34
    7   UIKit                               0x31b3782b -[UIViewController view] + 110
    8   PhoneGapCamera                      0x00003257 -[AppDelegate application:didFinishLaunchingWithOptions:] + 702
    9   UIKit                               0x31ada481 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
    10  UIKit                               0x31ad09e7 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 206
    11  UIKit                               0x31b29fdd -[UIApplication handleEvent:withNewEvent:] + 1396
    12  UIKit                               0x31b29901 -[UIApplication sendEvent:] + 44
    13  UIKit                               0x31b29337 _UIApplicationHandleEvent + 5110
    14  GraphicsServices                    0x3026c04b PurpleEventCallback + 666
    15  CoreFoundation                      0x3443fce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    16  CoreFoundation                      0x3443fca7 __CFRunLoopDoSource1 + 166
    17  CoreFoundation                      0x3443256d __CFRunLoopRun + 520
    18  CoreFoundation                      0x34432277 CFRunLoopRunSpecific + 230
    19  CoreFoundation                      0x3443217f CFRunLoopRunInMode + 58
    20  UIKit                               0x31ad0103 -[UIApplication _run] + 370
    21  UIKit                               0x31ace12f UIApplicationMain + 670
    22  PhoneGapCamera                      0x00002efb main + 66
    23  PhoneGapCamera                      0x00002e80 start + 52
)
terminate called after throwing an instance of 'NSException'
(gdb)

Shazron

unread,
Apr 8, 2012, 1:00:37 PM4/8/12
to phon...@googlegroups.com
It's a linker/loader problem. See step 14 of this document [1],
section "Adding Cleaver to your Xcode project (CordovaLib
sub-project)"

[1] https://github.com/apache/incubator-cordova-ios/blob/master/guides/How%20to%20Use%20Cordova%20as%20a%20Component.md

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

John Gentilin

unread,
Apr 9, 2012, 9:45:44 PM4/9/12
to phon...@googlegroups.com
Shazron, that you to the pointer. That helped with my initial problem.. Version 1..6.0rc (master) runs,
I am still having issues with the camera but it gets past the splash screen. If I use the 1.5.0 branch,
right when the splash screen disappears, It crashes at CDVViewController::deviceProperties in the
code block below, cordovaVersion is returning null (0x0).

I am assuming that 1.5.0 is latest 1.5.0 and that 1.5.0rc1 is prior to that.

CDVViewController
- (NSDictionary*) deviceProperties
{
    UIDevice *device = [UIDevice currentDevice];
    NSMutableDictionary *devProps = [NSMutableDictionary dictionaryWithCapacity:4];
    [devProps setObject:[device model] forKey:@"platform"];
    [devProps setObject:[device systemVersion] forKey:@"version"];
    [devProps setObject:[device uniqueIdentifier] forKey:@"uuid"];
    [devProps setObject:[device name] forKey:@"name"];
    [devProps setObject:[[self class] cordovaVersion ] forKey:@"gap"];

Looking at the code below, I copied the VERSION file from the PhoneGap source to
the same directory where my xcodeproj folder and also one level deeper where the
.plist file is stored.. In both cases, the pathForResource failed to load the file.

+ (NSString*) cordovaVersion
{
#ifdef CDV_VERSION
    cdvVersion = SYMBOL_TO_NSSTRING(CDV_VERSION);
#else
   
    if (cdvVersion == nil) {
        NSBundle *mainBundle = [NSBundle mainBundle];
        NSString *filename = [mainBundle pathForResource:@"VERSION" ofType:nil];


Stack Trace   

[Switching to process 12803 thread 0x3203]
2012-04-09 18:32:04.786 PhoneGapCamera[6394:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: gap)'

*** Call stack at first throw:
(
    0   CoreFoundation                      0x344aaed3 __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x33975811 objc_exception_throw + 24
    2   CoreFoundation                      0x344aad15 +[NSException raise:format:arguments:] + 68
    3   CoreFoundation                      0x344aad4f +[NSException raise:format:] + 34
    4   CoreFoundation                      0x3442eb9f -[__NSCFDictionary setObject:forKey:] + 190
    5   PhoneGapCamera                      0x000369ef -[CDVViewController deviceProperties] + 306
    6   PhoneGapCamera                      0x00034ddf -[CDVViewController webViewDidFinishLoad:] + 134
    7   PhoneGapCamera                      0x00002a63 -[AppDelegate webViewDidFinishLoad:] + 170
    8   UIKit                               0x31c7d63d -[UIWebView webView:didFinishLoadForFrame:] + 244
    9   UIKit                               0x31c7cb3f -[UIWebViewWebViewDelegate webView:didFinishLoadForFrame:] + 22
    10  CoreFoundation                      0x34456434 __invoking___ + 68
    11  CoreFoundation                      0x34456305 -[NSInvocation invoke] + 108
    12  CoreFoundation                      0x34455e61 -[NSInvocation invokeWithTarget:] + 36
    13  WebKit                              0x34287525 -[_WebSafeForwarder forwardInvocation:] + 352
    14  CoreFoundation                      0x3445421d ___forwarding___ + 576
    15  CoreFoundation                      0x34453f90 _CF_forwarding_prep_0 + 48
    16  CoreFoundation                      0x34456434 __invoking___ + 68
    17  CoreFoundation                      0x34456305 -[NSInvocation invoke] + 108
    18  WebCore                             0x34b9981d _ZL11SendMessageP12NSInvocation + 16
    19  WebCore                             0x34ba7ec5 _ZL20HandleDelegateSourcePv + 68
    20  CoreFoundation                      0x34460f25 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
    21  CoreFoundation                      0x34432ba7 __CFRunLoopDoSources0 + 382
    22  CoreFoundation                      0x3443244b __CFRunLoopRun + 230
    23  CoreFoundation                      0x34432277 CFRunLoopRunSpecific + 230
    24  CoreFoundation                      0x3443217f CFRunLoopRunInMode + 58
    25  GraphicsServices                    0x3026b5f3 GSEventRunModal + 114
    26  GraphicsServices                    0x3026b69f GSEventRun + 62
    27  UIKit                               0x31ad0123 -[UIApplication _run] + 402
    28  UIKit                               0x31ace12f UIApplicationMain + 670
    29  PhoneGapCamera                      0x0000210f main + 66
    30  PhoneGapCamera                      0x00002094 start + 52

)
terminate called after throwing an instance of 'NSException'
[Switching to process 11523 thread 0x2d03]
(gdb)


On Sunday, April 8, 2012 10:00:37 AM UTC-7, Shazron Abdullah wrote:
It's a linker/loader problem. See step 14 of this document [1],
section "Adding Cleaver to your Xcode project (CordovaLib
sub-project)"

[1] https://github.com/apache/incubator-cordova-ios/blob/master/guides/How%20to%20Use%20Cordova%20as%20a%20Component.md

tribalvibes

unread,
Apr 12, 2012, 9:35:57 PM4/12/12
to phon...@googlegroups.com
Having a similar problem that seems link-related--but it generates no errors, e.g. missing symbols, at build time. When it runs, it bombs with
-[__NSCFDictionary dictionaryWithLowercaseKeys]: unrecognized selector sent to instance 0x7b965a0

So it seems that things are not getting linked with libCordoba.a although it is a dependency of the app, is being built, the derived data folder is in the -L lib search paths, and the Cordova Framework is removed.  Either that or somehow it is not extending NSDictionary specifically with the Cordova extensions?

Could you please help?   Here's the ld command from the build log:

Ld /Users/moi/Library/Developer/Xcode/DerivedData/app-grlkykqcqrckrdefsbpwhpcaq/Build/Products/Debug-iphonesimulator/app.app/app normal i386

    cd /Users/moi/dev/app/app/mobile

    setenv MACOSX_DEPLOYMENT_TARGET 10.6

    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/moi/Library/Developer/Xcode/DerivedData/app-grlkykqcqrckrdefsbpwhpxxxcaq/Build/Products/Debug-iphonesimulator -L/Users/moi/dev/app/app/mobile/../../../../Library/Developer/Xcode/DerivedData/app-grlkykqcqrckrdefsbpwhpxxxcaq/Build/Products/Debug-iphonesimulator -F/Users/moi/Library/Developer/Xcode/DerivedData/app-grlkykqcqrckrdefsbpwhpxxxcaq/Build/Products/Debug-iphonesimulator -filelist /Users/moi/Library/Developer/Xcode/DerivedData/app-grlkykqcqrckrdefsbpwhpxxxcaq/Build/Intermediates/app.build/Debug-iphonesimulator/app.build/Objects-normal/i386/app.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -weak_framework UIKit -weak_framework AVFoundation -weak_framework CoreMedia -weak_library /usr/lib/libSystem.B.dylib -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 -framework Foundation -framework UIKit -framework CoreGraphics -framework AddressBook -framework AddressBookUI -framework AudioToolbox -framework AVFoundation -framework CoreLocation -framework MediaPlayer -framework QuartzCore -framework SystemConfiguration -framework MobileCoreServices -framework CoreMedia -lCordova -o /Users/moi/Library/Developer/Xcode/DerivedData/app-grlkykqcqrckrdefsbpwhaxcaq/Build/Products/Debug-iphonesimulator/app.app/app




tribalvibes

unread,
Apr 12, 2012, 9:54:56 PM4/12/12
to phon...@googlegroups.com
Ah, solved that, needed to add  -all_load and -Obj-C to the Other Linker Flags.  However, now it is still missing some def and is throwing:

2012-04-12 18:50:24.392 flyersup[51852:13403] Device initialization: (function() {                                     try {                                         cordova.require('cordova/plugin/ios/device').setInfo({"name":"iPad Simulator","uuid":"03D4725B-4996-8A23-22DF6658F04C","platform":"iPad Simulator","version":"5.0"});                                     } catch (e) {                                         return "Error: executing module function 'setInfo' in module 'cordova/plugin/ios/device'. Have you included the iOS version of the cordova-(null).js file?";                                     }                                })()

Clearly (null) is supposed to be 'ios'.   What def is missing?   This was all working fine previously linking with the Framework, but need to link statically for debugging. 


(gdb)

Shazron

unread,
Apr 13, 2012, 11:34:27 AM4/13/12
to phon...@googlegroups.com
Hi,
Can you tell me what steps I need to repro your case i.e you converted
it from X to Y using doc Z? I recently added a new step to add the
VERSION file if you are using a CordovaLib subproject in the "How to
use Cordova as a Component" for 1.6.0.

John Gentilin

unread,
Apr 14, 2012, 3:48:15 AM4/14/12
to phon...@googlegroups.com
Shazron,

I think this is only a problem with the 1.5.0 branch of PG. The specific problem is
that the method CDCViewController::cordovaVersion returns nill, because it is
unable to open the file @"VERSION". When I try to build PG from 1.3.0 to 1.6.0
it all works find except for 1.5.0, Note I did not try to build 1.5.0rc1

The specific steps are:
Clone repository
Check out 1.5.0
Add the xcodeproj to my project
Add the Cordova(PhoneGap) project as a dependency
Add cordovaLib.a as a linked binary
Add the loadAll ObjC linker options
Copy over the .plist file
Copy over the cordova.{version}.js
Fixup the js file in the index.html.

For 1.5.0, no matter where I put the VERSION File this line can't find the file and returns
"" which caused the method to return nil.

  NSString *filename = [mainBundle pathForResource:@"VERSION" ofType:nil];

Note: in the 1.6.0 source, the VERSION file looks a bit odd as the String 1.6.0
is in there 3 times but it appears harmless as the code only reads the first line.

Note: With all the other versions it was not necessary to copy over the VERSON file
from the source tree to get the PG project to work. This could be that the other versions
operate better with default data.

-John Gentilin


On Friday, April 13, 2012 8:34:27 AM UTC-7, Shazron Abdullah wrote:
Hi,
Can you tell me what steps I need to repro your case i.e you converted
it from X to Y using doc Z? I recently added a new step to add the
VERSION file if you are using a CordovaLib subproject in the "How to
use Cordova as a Component" for 1.6.0.

 

> Ah, solved that, needed to add  -all_load and -Obj-C to the Other Linker


> Flags.  However, now it is still missing some def and is throwing:
>
> 2012-04-12 18:50:24.392 flyersup[51852:13403] Device initialization:
> (function() {                                     try {
>
> cordova.require('cordova/plugin/ios/device').setInfo({"name":"iPad
> Simulator","uuid":"03D4725B-4996-8A23-22DF6658F04C","platform":"iPad
> Simulator","version":"5.0"});                                     } catch
> (e) {                                         return "Error: executing
> module function 'setInfo' in module 'cordova/plugin/ios/device'. Have you
> included the iOS version of the cordova-(null).js file?";
>                   }                                })()
>
> Clearly (null) is supposed to be 'ios'.   What def is missing?   This was
> all working fine previously linking with the Framework, but need to link
> statically for debugging.
>>
>>
>> (gdb)
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.

Shazron

unread,
Apr 14, 2012, 4:09:20 AM4/14/12
to phon...@googlegroups.com
If it can't find this file, it must not be copied in your bundle.
Normally when you add it, it will be added to the Copy Bundle Phase.
Check that it exists in the phase - see screenshot: http://cl.ly/FpnQ

I would recommend step #8 of the FAQ to create a project with the CDV
sub-project: https://github.com/apache/incubator-cordova-ios/blob/master/README.md

Try that, see if it works and compare the settings (screenshot) to yours.

> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com

Mobile Dan

unread,
May 3, 2012, 2:22:48 PM5/3/12
to phonegap
Thanks to those contributing to this discussion. You helped me get
this working. I struggled at first since I am new to XCode.

I posted the steps I went through to get this working on my blog at:
http://mobiledan.net/2012/05/02/compile-phonegap-source-code-in-your-ios-phonegap-project/

Dan
Reply all
Reply to author
Forward
0 new messages