iOS Question App does not even start when referencing an XCode Library.

JordiCP

Expert
Licensed User
Longtime User
I am building a B4I library with XCode i order to integrate it in my project using the Local Builder.
This library uses frameworks. I have done it in the past with other frameworks and has worked normally but I'm having problems with this one.

Now the situation is as follows:
  • I have the XCode project and build it to a static B4I lib (generates the *.a, *.h files)
  • Then I copy these files and the needed frameworks to my local builder Libs directory, generate the xml and add it to the Additional Libs B4I folder.
  • Just reference the library from my B4I project, not even referencing any object from this library (in order to narrow-down the possible causes)
  • It compiles, but when I deploy it to my target device, the app just closes (the app works normally without referencing my lib)
  • No logs at all appear, so I assume that the B4I app doesn't even start because something is failing when trying to load my lib, but is there any way to get logs (at whatever level) so that I can get any hint of what is happening? I mean, while building the lib I can see where errors are. When starting my B4I app, I can also see the logs in the B4I IDE when the app starts. But if the process fails when this lib is loading and there is a weird error during this stage, I'm totally blind :(

(Not sure if it can give any clue, but the app icon in my iPhone shows a (1) Badge. )

Thanks in advance :)
 

JordiCP

Expert
Licensed User
Longtime User
Thanks for the hint , now I can open the generated XCode project and try to build the B4I app.
(I'm using Builder 6.01 and XCode 11.3)
Surely not related to anything of this, but I must add Architectures to the project (when opening the XCode project, only supports armv7)

Once this is done, the project compiles and deploys to target, but can't be run because of this error
Details
Could not launch “B4iProject”
Domain: IDEDebugSessionErrorDomain
Code: 3

Failure Reason: iPhone has denied the launch request.
Internal launch error: process launch failed: failed to get the task for process 6176
--
process launch failed: failed to get the task for process 6176
Domain: IDEDebugSessionErrorDomain
Code: 3
--
, so I must Edit the schema to "Ask on launch", and then I can see some logs.


The framework is linphone, which uses other related frameworks. They are automatically added to the project when installing the pod

At this moment the (narrowed down) wrapper only exposes a couple of test methods not related to linphone, but the frameworks are anyhow added to the project with cocoapods. Also tried (according to some SO answers, but not sure of what I was doing) to add linphone framework to the Target Build Settings, both in "Compile Sources" and "Link Binary with libraries" just to see if results change.

The error I get in all cases is (Frameworks have also been added to the Builder's Libs folder):
dyld: Library not loaded: @rpath/linphone.framework/linphone
Referenced from: /var/containers/Bundle/Application/D2AD44E7-55A1-4C4D-98F3-57B344ED5B12/B4iProject.app/B4iProject
Reason: image not found


I followed the same reasoning for other projects involving other frameworks, but this time the result is different.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Yes, I added that line (without the .3 ending, where does it come from?) and it crashed before starting the app as described. With the XCode device logs, I could see that it could not find linphone, and then exited.

Now I'm following a new approach to include the frameworks as embedded binaries, so there are no external dependencies. Not sure if it is a correct approach or frameworks must always be referenced with 'Dependson'.

(Assuming that the approach is correct and that this is a new thread 😁)
The lib compiles ok, and now when I compile with the B4I IDE it complains with a linker error
"_bctbx_list_find", referenced from:
-[FastAddressBook updateFriend:] in liblph3.a(FastAddressBook.o)
(and a bunch of similar ones)

so it seems that it does not find some referenced functions --> can it be due to the fact that that the binaries included in the frameworks are fat binaries and they need to be arm64?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
without the .3 ending, where does it come from?
This means that it is a third party framework and is located in the Mac libs folder and not part of the iOS SDK.

There are many libraries that depend on frameworks. You can compile your app with a simulator release build and then open the generated Xcode project with Xcode. If everything is configured properly then you will be able to run the app from Xcode. Hopefully you will be able to understand what is not configured properly.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
This means that it is a third party framework and is located in the Mac libs folder and not part of the iOS SDK.
Thanks. Tried it but it doesn't make any difference.

Also tried the simulator, building the lib also for x86_64, but produces the same result (app simply doesn't launch)

At this moment the situation is as follows
  • This (fail to launch) happens even if I only reference the library from my B4I project, without using it.
  • I have added all the framework dependencies in my Libs folder, and I can see that they are used (if I remove any of them or build them for different architectures. the B4I linker complains)
  • The framework uses VoIP, Pushkit, and Callkit. Perhaps some entitlements and permissions are needed, and these are evaluated when the app is launched (just guessing)
So I have a couple of questions:
  • Regarding this latest point, which entitlements and permissions should be added in the B4I project?
  • To continue debugging with the XCode generated project, are the B4I project entitlements/permissions added to the generated XCode project, or are they also set from the command line?

Thanks for the support :)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Regarding this latest point, which entitlements and permissions should be added in the B4I project?
It really depends on the specific features that you are using.

The way forward is to run your project from Xcode.

To continue debugging with the XCode generated project, are the B4I project entitlements/permissions added to the generated XCode project, or are they also set from the command line?
They are added to the project.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Some progress

The way forward is to run your project from Xcode.
I was trying it all the time 😦, but the app crashed before any code was executed, because it could not load the libraries, sometimes throwing this unreadable error
B4X:
dyld`__abort_with_payload:
    0x1009ee410 <+0>:  mov    x16, #0x209
    0x1009ee414 <+4>:  svc    #0x80
->  0x1009ee418 <+8>:  b.lo   0x1009ee430               ; <+32>
    0x1009ee41c <+12>: stp    x29, x30, [sp, #-0x10]!
    0x1009ee420 <+16>: mov    x29, sp
    0x1009ee424 <+20>: bl     0x1009ed850               ; cerror_nocancel
    0x1009ee428 <+24>: mov    sp, x29
    0x1009ee42c <+28>: ldp    x29, x30, [sp], #0x10
    0x1009ee430 <+32>: ret

By modifying the generated XCode project, I finally got it to run and now I can see how the B4I app starts (from XCode), even place breakpoints. Later, it crashes with a bunch of errors, but at least they are debuggable, so it's a totally different scenario.

The settings that I had to modify so that the generated XCode project could load the libraries and start normally were (both of them are needed):
  1. Menu>Product>Scheme>Edit Scheme>Run (Debug) ---> Check 'Undefined behavior Sanitizer'.
  2. Target>Build Phases -> Embed Frameworks ---> I had to add (drag) the referenced frameworks there.
    • (The external frameworks appear in the generated XCode project but they are only added to the Build Phases> 'Embed Binary with libraries', not in the 'Embed Frameworks')
    • (also tried adding them with #AdditionalLib (with and without the ending .3) with the same result (program crash, when tried to deploy the app from B4I))

My question:
Is there any way to 'automate' the above changes to my generated Xcode project by means of any script or whatever? This way, I would be able start and debug my project from the B4I IDE.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
My fault!! since the reference project was with ObjC, and also there was a tutorial regarding how to build the SDK and integrate it in a ObjC project, I thought it was not a swift framework (lots of missing concepts from my part).

Now I can continue debugging the B4I part from the IDE, and save a lot of time!

Note that it will not run on the simulator.
It works if I rebuild the lib for a specific simulator (instead of Generic iOS device), and just replace the .a file in the builder Lib's folder

Thanks :)
 
Upvote 0
Top