Google Protobufs in iOS app crashing at GPBDescriptor - ios

This one is a real head-scratcher...
PART ONE
We have a swift iOS application with different targets for Dev and Prod (normal stuff).
We've incorporated Google Protobufs into it for one of our latest features. This was done using Google's J2ObjC library and the pod 'Protobuf', '= 3.11.4' pod. (Our .proto files were made with v3.11.4).
Running our Dev target works fine (mostly, see Part Two). Running our Prod target crashes in the constructor of any GPBMessage object.
It crashes within the + (GPBDescriptor *)descriptor function of the pbobc.m file of our message object...eventually getting to this error within GPBDescriptor.m
Line:
enumHandling_.enumDescriptor_ = coreDesc->dataTypeSpecific.enumDescFunc();
Error:
(lldb) po coreDesc->dataTpeSpecific
error: <user expression 2>:1:11: no member named 'dataTpeSpecific' in 'GPBMessageFieldDescription'
coreDesc->dataTpeSpecific
~~~~~~~~ ^
What's weird is this crashes in Prod and not Dev. Combing through both targets' Build Settings...they're identical. Build Phases are the same, Build Rules are the same, Plists are basically the same...
I don't know what else to check.
PART TWO
There is one GPB message that crashes on init in both our Dev and Prod targets. (We can run without it, so I've commented it out during development.)
The difference between this message and the others is that this one is a list of enums.
It crashes on the same line. ¯\(ツ)/¯
Thank you SO MUCH in advance! :D

of course immediately after I post the question I find the answer...
Google protocol buffers on iOS
Needed to add -fno-objc-arc to every ...pbobjc.m file in the Compile Sources of Build Phases.
I had already done this for a few files in Dev, hence the (very subtle!) difference.

Related

Xcode12 po command in lldb in console cannot find variables in scope

Ever since I updated to Xcode 12, I have not been able to print out variables in the console while debugging with lldb.
Using print() statements directly in Swift code outputs to the console as expected.
A command in the console such as po "hi" outputs "hi" to the console as expected.
Trying to run po <variable_name>, instead, always outputs this line:
error: <EXPR>:3:1: error: cannot find 'variable_name' in scope
instead of the expected variable's value.
Steps I took
Add these lines to Swift code
let example = "hi"
print(example)
Put a breakpoint on the second line, the one with the print() statement
Run the code and wait for the breakpoint to be hit
Try to run po example in the debug console
Expected result
It should print "hi" in the console
Actual result
It prints this error line
error: <EXPR>:3:1: error: cannot find 'example' in scope
It's the same when running on the simulator or a device. I've tried activating the console, and restarting Xcode.
I've tried creating a new project in Xcode12 and that works fine, my other older projects created with previous versions of Xcode work fine in Xcode 12.
I've tried confronting the Build settings both with the other projects and with a newly created project and it seems nothing's wrong: optimization is set to None as it should for debug build configurations and the run scheme is set to launch a debug build configuration.
Where else could the problem be?
I had this issue as well, everything was set correctly in build settings, I had the same situation as in the question.
For me the problem was solved after I moved all my SPM dependencies back to CocoaPods, but that's not the silver bullet because I have other projects where some dependencies are on CocoaPods and some on SPM and those work perfectly fine.
What can be useful, though, is that to come to this solution I checked out older commits until I found a working one and then tried to restore things that changed since that commit. This should help find the cause in every specific case.
This issue is so unpredictable that, if you are experiencing it, I think it's worth filing a feedback to Apple, if you can, attaching your projects to the feedbacks.
You can change optimization level to "none" value in build settings. Its works for me.
In my case the problem was caused by 'GoogleAPIClientForREST' installed as Cocoapod dependency in a project containing also a Swift Package.
You can find the issue reported here: https://github.com/google/google-api-objectivec-client-for-rest/issues/478
I don't know if the responsible for the problem is SPM or GoogleAPIClientForREST, but a good workaround for now is to install a previous version of GoogleAPIClientForREST:
pod 'GoogleAPIClientForREST/Drive', '~> 1.3.11'
pod 'GoogleAPIClientForREST/Calendar', '~> 1.3.11'

Beware the dangling -Xfrontend: (was Xcode: Archive fails, but builds and runs for simulator and devices)

Trying to Archive my app is failing with the following error(s):
<unknown>:0: error: cannot load underlying module for 'CoreFoundation'
The project builds and runs on both the simulator and my iPhone, and builds for "Generic iOS Device".
The one big thing that I've changed in my project is how I'm integrating GooglePlaces and GoogleMaps. Previously, I had been using a hacked Carthage integration method, but that started failing to build when Archiving, though again worked fine in all other scenarios.
So I removed the Carthage integration and followed the Google prescribed way of manually integrating it, which involved adding a variety of frameworks to the Link Binary With Libraries Build Phase. CoreFoundation was not one of them, but including that didn't fix it.
Any ideas?
Well after painstakingly going through commits to determine exactly where it broke I figured out the problem.
TL;DR - if you have a compiler option that is -Xfrontend without another
option following, it is a mistake and will break things!
While cleaning up all warnings, I changed what I thought was an option to warn about functions taking more than x to compile:
`-Xfrontend -warn-long-function-bodies=150";`
In Xcode, this appears to be 2 options on 2 lines, so I deleted the second one. I was not thinking about -Xfrontend so I left it in. For debug builds I left in the whole thing but upped the number.
-Xfrontend is a 2 part option which passes along the option that follows to the front end compiler. So what was happening is that whatever followed was not only passed to the Swift front end compiler, but not passed to where it should be.

Swift - Command failed due to signal: Segmentation fault: 11 when build in configuration Release

I'm trying to compile a project then the Xcode said that.
I hope to receive the answers for these concerns, here are the situation:
Xcode 8.3.2
Swift 3.0
All Frameworks are built via Carthage (Exclude Fabric & Crashlitics)
When I build in Debug configuration everything are ok, but when I change to configuration Release then the compile always failed.
I tried to change the Optimization Level to Fast, Single-File Optimization[-O] then the Xcode works well and I also can archive to ipa file.
I have some concerns, could you please review ?
+ How do I completely resolve this problem and keep the default Optimization Level value for configuration Release ?
+ If I change Optimization Level value to Fast, Single-File Optimization[-O], could I submit the binary file to App store review ? Does it violet Apple's tos ?
Thank you,
you can get this error when the compiler gets too confused about what's going on in your code. I noticed you have a number of what appear to be functions nested within functions. You might try commenting out some of that at a time to see if the error goes away. That way you can zero in on the problem area. You can't use breakpoints because it's a compile time error, not a run time error.
And it might be possible that you have used a custom frameworks so just remove that custom framework which shows error

Class GAD_GTMStringEncoding is implemented in both <framework> and <app>. One of the two will be used. Which one is undefined

I have an iOS project in Xcode. It contains a load of linked libraries including GoogleInteractiveMediaAds.framework as well as an internal player library that I believe is also linked against this framework. Both are also embedded binaries.
The project compiles just fine but at runtime I get the following error:
Class GAD_GTMStringEncoding is implemented in both
/GoogleInteractiveMediaAds.framework/GoogleInteractiveMediaAds
and APP_PATH. One of the two will be used. Which one is undefined.
On simulator the app works as expected every time despite this warning - I get the pre-roll, mid-roll and post-roll ads that I'm expecting. Every time. On device it's a different story with the ads sometimes working and sometimes not. I'm aware that the above issue results in different behaviour on different targets and I suspect this conflict is to blame for the broken functionality on devices.
Solutions I've found here on SO suggest either changing the namespaces or removing the linkage from either my app or the library that I'm linking against. The problem is, if I remove the embedded binary in my project then it fails to compile:
dyld: Library not loaded:
#rpath/GoogleInteractiveMediaAds.framework/GoogleInteractiveMediaAds
Referenced from: APP_PATH
Reason: image not found
(lldb)
I've seen a few people suggest what would be removing the linkage from the app and using the player's internal instance (where I then have to hope that the player is compiled against the version that I need), but how on earth do you do that? And would that even work in this case?
Also, is there a way to find out for sure where this other instance of GoogleInteractiveMediaAds.framework is coming from? I'm only assuming that it's inside the internal player library but I don't know for sure as I don't have the source. The error message just provides me with the path to the compiled app which is of little help since there's like 30 linked libraries inside it.
Thanks in advance.
After initially insisting that the issue was somewhere in our code, the Google team responsible for this framework were eventually forced to admit (after we provided a sample app) that it was a problem with their code and not ours. It was resolved in an update.

Xcode 6 warning: Argument unused during compilation and I get several .d files in message

I get this Xcode 6 warning: "Argument unused during compilation", and I get several .d files in the Issue Navigator.
Some background of how the project is organized will probably point to where my issue lies. I have two targets, and they have slightly different settings. One is for the automated build, and the other is the development one. The Develop does not have this warnings. The automated build one was duplicated from the Develop one. Of course, Xcode generated different plist files, so I had to make sure they both used the same to not have to maintain duplicate settings. I also had to change the Product Name, since the auto build one would otherwise export with it's funny name (it has _CI appended to the name of the App). That would cause some issue.
Also, I'm using Cocoa Pods, in case this might have to do with the issue?
I'm using both Swift and Objective C, and I have unit tests set up.
Here's what the warning looks like, exactly:
Argument unused during compilation: '-MF /Users/user.name/Library/Developer/Xcode/DerivedData/App_iOS-akqwlfytlhwajobqkbaqgojblmet/Build/Intermediates/App_iOS.build/Debug-iphonesimulator/App_iOS_CI.build/Objects-normal/x86_64/MenuModel.d'
Hope this helps pinpoint the issue.
Thanks in advance.

Resources