How to debug iOS native code in a flutter plugin? - ios

I'm wonder how to debug flutter iOS code in a plugin?
I can open the example app that's generated whenever you create a plugin but I see the plugin code as binary framework, therefore I can't debug it.
For android it's fairly easy, I just open the android folder in A.S. and the plugin + the example are there, I just add run configs and I start debugging right away.
But I really hope to find a similar way for iOS.

Plugins are added to the ios app as pod projects so it is similar to debugging any code in pod project.
Open Runner project workspace
Browse the file in the Pods project
Put Breakpoint
NB: Need to run app from flutter first to work this properly

To set a breakpoint and debug Flutter plugin code from Xcode, try the following:
Open ios/Runner.xcworkspace for the Flutter application you want to debug.
From the Debug menu, select Breakpoints > Create symbolic breakpoint...
In the Symbol field, enter the method you want to break on. For example, to break on the default entrypoint for the plugin defined in the HelloPlugin class, set the symbol to -[HelloPlugin handleMethodCall:result:].
Run your app from Xcode via Product > Run.
From that point, trigger the plugin code through whichever UI actions will hit the code in question.

Make sure to build the example app first using cd hello/example; flutter build ios --no-codesign, then open it in Xcode.
You can find files for the iOS part deep in the project hierarchy: Pods > Development Pods > name_of_your_plugin > ... > Classes
You can put breakpoints in the Xcode as you would normally do, and then you can run the example app straight from the Xcode.
Reference from the Flutter team.

Related

How debug Kotlin on iOS with Xcode

Currently I am working on one KMM project. It would be really useful to be able to debug the shared code which is in kotlin in xcode project.
I am aware of this solution but I have problem to tell Xcode that *.kt files are source files
to be more specific in the above github link it is written :
You need to tell Xcode that *.kt files are source files, and run an lldb formatter script when debugging starts. Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the setup script.
Unless you're using Xcode 11 (in which case look here for help), the following script will install both debugging and formatting support:
./setup.sh
I do not know where and how I should run the ./setup.sh or if there is another way to do it?
The setup script is included in the github repository: https://github.com/touchlab/xcode-kotlin/blob/main/setup.sh
The above plugin is great if you want to debug on Xcode and I highly recommend it.
Just an FYI, in case you didn't notice, there is also a plugin for debugging shared code on iOS for Android Studio: https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile

Can't build Cordova iOS project using CLI but can build/run the Xcode project

Absolutely new to Cordova. These are the steps I've done:
Checked out an existing project
run cordova build ios
The above generates this build error:
(node:10242) UnhandledPromiseRejectionWarning: Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "ios" does not appear to be a valid cordova platform. It is missing API.js. ios not supported.)
I've Googled for a solution to the above and the general consensus seems to be to remove and then add the iOS platform.
Now there's a problem with that. Looking through the commit history, I can see that there have been code changes done to files within the platforms directory so I can't just remove it, or...
Question 1)
Can I?
Question 2)
Is it right to make code changes within the platforms directory? Because it seems like those are generated directories.
Question 3)
Why is it that when I open the Xcode project under platforms/ios, I am able to build/run it fine despite the Cordova CLI error above?
it's not right to manually edit the platform files. And some manual changes might make the project not build, so might be related to the manual changes somebody did. So if you don't want to risk to remove the platform, continue building from Xcode
from root www to platforms/ios is transferred by cordova commands such us cordova prepare ios or cordova build ios or cordova run ios.
So if you can't do a cordova prepare ios because of that error you can try a few things.
Copy your files from www to platforms/ios without replacing the whole folder, just the duplicate files. cordova prepare ios is not just a copy, it's also does some modifications/aditions, but if you don't remove existing files it might work.
Create a new project and copy the platforms/ios/cordova to your own project and see if that fixes the mentioned problem, as that's where the Api.js file is.
Downgrade the Cordova CLI, try to latest 7.x.x and if it doesn't work, try with latest 6.x.x, one of those won't require the Api.js as it relatively new.

How can I debug carthage (owned) dependencies in my iOS application?

I have an iOS application project with couple of private(owned) carthage dependencies, sometimes I'm in the need of debugging bugs or to know what is the code executed by certain methods.
I'd like to know if there is an easy way to setup the framework source code in Carthage/Checkouts using a run script, so that if I do a carthage update and run my app a can debug the frameworks source code without the need of adding sub projects.
Can this be done by including the debugging symbols in the framework build if so what would I need to do, to make it work?
Did you tried to copy the dsym files as mentioned in Carthage - Getting Started?
With the debug information copied into the built products directory, Xcode will be able to symbolicate the stack trace whenever you stop at a breakpoint. This will also enable you to step through third-party code in the debugger.

Remove fabric framework from ios app

I have been landed an iOS project from a client. The main task is to explore and see the user interface so that multiplatform app will be made from scratch with Xamarin.
I notice that the project uses third party framework called fabric. From what i see it is used from crash analytics. I don't need that and i don't have registration so i want to remove all dependencies from the project.
So far I did:
Deleted define ENABLE_FABRIC ( which removed some code from
AptDelegate, replaced logging messages with plain NSLog etc)
Removed some fabric script invocation from build phases
Removed reference from fabric framework in project
So i still have errors building my app:
/bin/sh:
/Users/macmini/Library/Developer/Xcode/DerivedData/../Build/Intermediates/../Script-FDC6FCE81A4488D000F2613D.sh:
(null): bad interpreter: No such file or directory
Does anyone know a quick way to get rid of this?
I know it's an old question but I want to help. When you install Fabric, previously Crashlytics, it asks you to put a script in project->Build Phases-> Run Script
it will look like this
./Fabric.framework/run 123456fd7ec....6e2170Q
I think you should remove that script and other Linked Frameworks and Libraries and then it possibly could run
Try deleting the files DerivedData path and clean build folder
cmd+opt+shift+k
then re run the application.
Also check once again the Framework search path in xcode settings.

Crashlytics in iOS won't proceed past "Build Your Project" in Fabric app

I'm installing Crashlytics for my iOS app. I downloaded it via their site link, and went through all the steps for integrating the frameworks, adding the run script, etc.
I was experiencing an issue, so I removed the frameworks and decided to start over and try a fresh install. But the Fabric app updated to a newer version, and now when I try to reinstall Crashlytics into my app, it doesn't give me the option to reinstall the frameworks. It goes straight from clicking "install" to the "Build your project" screen, which I cannot pass.
To help configure your project, please build it now by pressing ⌘B
I press ⌘B, it builds and nothing happens. I think the issue is because I removed the Crashlytics and Fabric frameworks from my project, but I can't see a way to add them back again. The Fabric app doesn't give me that option.
Go into Build settings of the your target.
Find "Debug Information Format".
Set this from "DWARF" in both debug and release to "DWARF with dSYM File"
Moving from Comment to Answer.
Mike from Fabric here. If you back up through the Mac app, then click on the arrow in the top-left, click on "+ New App", that will walk you through re-adding everything.
If you check the resource navigator you may see the following message:
"DEBUG_INFORMATION_FORMAT should be set to dwarf-with-dsym for all configurations. This could also be a timing issue, make sure the Fabric run script build phase is the last build phase and no other scripts have moved the dSYM from the location Xcode generated it. Unable to process eCreditWebWrapper.app.dSYM at path"
Go to Build Settings and search for "Debug Information Format". Ensure "Debug" is set to "DWARF with dSYM File".
Without the dSYM file Fabric won't work.
As for Xcode 10.2.1, the automated installation via Fabric Mac app won't work anymore. New apps cannot be added via the New App Step-by-step guide.
You have to follow the manual installation instructions. Download and add the 2 frameworks into your Xcode workspace, then add the Run Build Script phase (and related Fabric codes), then build the App. Last (very important), run the app in an actual device.
Once the App is successfully launched, the new App information will be available in the Fabric dashboard as well as the Fabric Mac App (needs to relaunch the App to see the new app).
Here are the steps:
Download the 2 frameworks
Drag to your project where your App Delegate is (make sure ticked "Copy items if needed")
Compile the project / workspace in Xcode
Add the "Run Script Phase" as instructed here; note that Xcode 10+ requires an extra configuration at Input Files
Add the required import and initialization codes in App Delegate
Add the Fabric API keys in Info.plist
Compile again
Run the App in a real device. You will see the line Crashlytics in the Xcode log. If no log appears, checks if your active scheme contains OS_ACTIVITY_MODE settings. Set it to default if the current setting is disabled.
If the Crashlytics line appears, that means the manual installation is working; you will see your App appearing at Fabric online dashboard.
I have solved this issue by the following way. Following the advise from above, I began adding a new app to crashlytics. When I reached to adding new "Run script" build phase, I just copied that text and pasted it over the previous one(created with Crashlytics).
I have also unchecked "Run script only when installing".
After this, I canceleed adding a new app and procedeed back to the UPGRADE. At this moment, building the app, can pass you to the next step and you don't get stuck on that screen anymore.
I was stucked on Build phases too.
I have also unchecked "Run script only when installing" and press again command+B and then I passed to the next step.
If the script is not running, you may have checked the "run script only when installing" in the run script section.
I hope it helps
TL;DR
Tap your scheme -> edit scheme -> set build configuration to "Release"
Explanation:
The most voted answer sounds about right, but there are situations where you just don't need crashlytics in debug builds (who wants crashes sent when you just develop and experiment with your code?). In this case you should disable crashlytics by checking debug compilation flags (out of scope of this answer) and for the first time during installation build app for release to let crashlytics know that you built app.
I had the same issue today. The problem was that i didn't have the run-script :
./Fabric.framework/run <api key>
in my project. Once i put this back in then it all worked perfectly. I also cleaned my project and deleted derived data just to be sure.
you must check that your deployment target version because of "Fabric's minimum iOS version is 6.0"
I was only able to get the Fabric app to continue the installation process after setting my build target to 'Generic iOS Device' and creating an archive from the Product > Archive menu.
Simply building the app or running it on an emulator doesn't seem to trigger the Fabric App to proceed.
If you use Xcode 10.
Project Navigator -> your project -> Targets -> Build Phases -> your Run Script for Fabric -> Input Files -> "+" (add input file) -> clear field and past this line:
$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
Be sure to remove this: $(SRCROOT)/
In the Run Script build phase there is a call:
./Crashlytics.framework/run <your_api_key_here>
Maybe you added some conditions to trigger it only on certain builds like:
releaseConfig="Release"
if [ "$releaseConfig" = "${CONFIGURATION}" ]; then
echo "Running Crashlytics"
./Crashlytics.framework/run <your_api_key_here>
fi
so that it will not just trigger on ⌘B
See https://dev.twitter.com/crashlytics/ios/advanced-setup
In my situation I was following all the steps correctly but got stuck on 'add build phase' step.
Then I just restarted fabric and all works just fine
Also there are some other possible actions:
1) Just restart Fabric, Xcode and your Mac.
2) Also if you use Cocoapods change build phase line from
./Crashlytics.framework/run [yourAPIKey]
to
"${PODS_ROOT}/Fabric/run" [yourAPIKey]
3) After building project if Fabric will stop responding just wait a while. It took about minute on my Mac.
Thanks, I solved the problem by removing folders:
~ / Library / Caches / com.crashlytics.data
~ / Library / Caches / com.crashlytics.mac
Kindly cross verify that run script you adding is to your actual target if u will add to tests target it will not proceed until you add it to actual target
None of the solutions here worked for me. The scenario for me was someone else added the Fabric framework to our project and committed it to the repo. The run script on their computer launched/triggered the Fabric Plugin, but would not launch/trigger on mine, although it did not report errors.
The solution was to create a separate project, using Cocoapods download the same version of Fabric, replace the run script in our project/repo (and the one referenced in the target's run script) with the downloaded version from Cocoapods. Rebuild and then the plugin would respond.
Comparing the two run script files, they are drastically different, but the run script from Cocoapods was not a flat text file and it was unreadable. So I'm not sure what was different between the scripts, but we somehow got different versions of the script while using the same version of Fabric.
What I did wrong was adding the script to the pods project build phase instead of the main project build phase, adding it to the main projects build phase solved the problem.
If you are duplicating the target, remove the run script from build phase and add it again to solve the issue.
If you have multiple TARGETS,
check your Schema selection is correct before you build project.
For Xcode 10. Add your app's built Info.plist location to the Build Phase's Input Files field:
$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
This solved my issue i hope this can solve others issue.
It turned out I had not enough permissions to create new project in Fabric.
Upgrading from Member to Admin resolved the issue.
In my case, removing an app from helped.
1) Remove the app from Fabric.
2) Follow all the steps again to add the app and install Crashlytics.
Nothing helped me. Now Fabric catches my archive creation. But I create the archives via fastlane's build_app.
Open Project in higher version of Xcode. This resolved my issue after waste many hours.
My Project build on Xcode 10.2 and I was running on Xcode 10.1 but when I run the same project on Xocode 11. The build was succeeded.
Try to wrap your run script variable with double quotes ""
"${PODS_ROOT}/Fabric/run"
Go to folder /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/<CURRENT_IOS_SDK>/usr/lib/ and delete all .dylib files.
It worked for me.

Resources