How to debug Unity project with iOS simulator? - xcode

As somebody said, the Unity project must be run on devices, but that is a lot of trouble. Is there any way to run a project in iOS's simulator?

Prerequisites:
Mac
XCode
Unity3D for Mac
Guide:
Go to Edit > Player settings > Inspector > iOS tab. Change the Target SDK to Simulator SDK then build the project again.
Open Build Settings and switch platform to iOS.
In the same window set Run XCode as Debug, check Development Build and Script Debugging.
Click Build and Run, choose a directory for iOS builds (for example, create a new directory named Build.iOS)
Build's a long process, take a break.
Unity3D documentation - Building your Unity game to an iOS device for testing.

It was supported until Unity3D 3.3. and iOS 4.??? But the current release 3.4 crashes. See this posting in Unity3D forum.
Anyway I find it easier to run the project in in editor player for debugging and do real testing on the device. Deploying to iPhone via XCode is always annoyingly slow. So I designed my code to distinguish at startup between device and player like
if (Application.platform == RuntimePlatform.IPhonePlayer) {
// do what ever you need
} else ...
Working with the abstract factory design pattern or singletons makes it pretty easy.

Related

Flutter - Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator

After updating to Catalina 10.15.4 beta with Xcode 13.4 beta, which also updated Simulator to 13.4 (921.4).
The application compiles and runs correctly on a physically attached device, but no simulators of any devices can pass this stage.
I got the errors
Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator.
or
Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS.
How can I fix this?
Xcode 11.4 changed the way frameworks are linked and embedded, and you may experience issues switching between iOS devices and simulators. Flutter v1.15.3 and later will automatically migrate your Xcode project.
To get unstuck, follow the instructions below;
Quick fix (make your simulator work)
rm -rf ios/Flutter/App.framework
Official recommended Steps to migrate manually
From the Flutter app directory, open ios/Runner.xcworkspace in
Xcode.
In the Navigator pane, locate the Flutter group and remove App.framework and Flutter.framework.
In the Runner target build settings Build Phases > Link Binary With Libraries confirm App.framework and Flutter.framework are no longer present. Also confirm in Build Phases > Embed Frameworks.
Change the Runner target build settings Build Phases > Thin Binary script as follows:
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh"
embed
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh"
thin
In the Runner target Build Settings > Other Linker Flags
(OTHER_LDFLAGS) add $(inherited) -framework Flutter
Hope it helps!
Select your Target from "TARGETS"
Select 'Build Settings'
Under 'Build Options' -> Set 'Validate Workspace' To 'YES'
After successfully building, set it back to 'NO'
Reason :
"In Xcode 12+, the default option for Validate Workspace is internally not set. We need to set it manually to avoid this kind of error. There is no problem in setting back to the default 'NO' option.
Xcode 11.4 changed the way frameworks are linked and embedded, which is causing issues switching between iOS devices and simulators.
Please follow official guide on how to migrate your project.
After several days trying to find a solution to test the Flutter app on iOS device, I finally found this:
flutter clean
flutter build ios
-Open xCode and run app on your device.
Updated to Xcode 11.4. Ios 13.4, Iphone X. App just fetches data using API.
App started on white screen and then finally crashes, both on simulator and device.
I followed the offical guide (I also rm -rf ios/Flutter/App.framework)
flutter.dev/docs/development/ios-project-migration.
I ran several times flutter clean
I also tried deleting Pods/ folder and Podfile.lock, then reinstalling using pod install in the ios folder.
As I am using async data I also added as 1st line in main()
WidgetsFlutterBinding.ensureInitialized();
No help, app did not started either simulator.
Then I removed ios/ and android/ folders. After that in project folder I ran command flutter create . that regenerates mentioned folders.
After this my app started fine both on simulator and on device.
I hope this would be help to others. NOTE!! if you have done any modifications manually to those folders please take backup or commit beforehand.
I have tried the solution on the official website of flutter but it didn't work for me, so I found a temporary solution which worked for me, but it took me some hard works:
Here is my example with project stuck_framework which is a fresh new project (first time run on the simulator)
I created 2 folders inside flutter project called
"ios_simulator" and "ios_real_device".
enter image description here
Now my first build was for the simulator, then I want to switch to a real device, I will move ios folder inside Flutter project to the "ios_simulator"
I open the project with visual studio code and run "flutter create ." and now I will choose a real device to rebuild the project ( if your simulator is online, please quit ).
enter image description here
Now I wait for the build finish and run on the real device without any errors. Now I have 2 ios project 1 for simulators and one for real devices.
Next time when I want to run on the simulator again, I just remove the current ios folder and copy the ios folder which I placed on "ios_simulator" back out to flutter project folder. Hope this help
Manually upgrading flutter to version 1.15 solve this issue as well. Running flutter version v1.15.17 helped me.
Also, you can switch to beta or dev channels by running flutter channel command but be sure you check your code against all BC changes...
In my case, it works only simulator(debug). if you want to deploy your app on the app store(release) i highly recommend you to upgrade flutter version using
flutter version v1.15.17
otherwise you would encounter crashed app with white screen.
just upgrade flutter version then all things work well
This error is caused by the Xcode 11.4 and can be resolved by Removing / Re-Embedding frameworks and adding a new Run Script Phase.
Under General -> "Frameworks, Libraries, and Embedded Content"
Delete the frameworks that are causing errors.
After deleting, re-embed the frameworks in the same location.
Under Build Phases add a new run script phase.
Select the "+" button in the "Build Phases" pane to create a "New Run Script Phase".
Confirm the script is the bottommost build phase, and configure its fields.
The Shell text field should read /bin/sh (which is the default value).
In the text-input area, enter the shell command rm -r "FRAMEWORK_DIRECTORY/YOUR_FRAMEWORK.framework/"
None of the other solutions here worked for me. In my case, the problem was fixed by searching my project for ONLY_ACTIVE_ARCH and changing them all to YES. I found my solution here:
https://developer.apple.com/forums/thread/656509

How to force an app to simulate in iPhone simulation using an iPad using Expo?

I'm currently using Expo to build an iPhone app.
I'm not supporting iPad and I have it so when it builds on iPad it runs in an iPhone Simulation.
The problem is I can't develop with Expo using this approach.
The app shows up as an iPad app, but this is not the mode being shipped to users.
According to this I might have some luck adding ios.supportsTablet to the app.json file and setting it to false but it didn't change anything.
Is there another configuration value I'm missing to force iPhone simulation mode on an iPad?
I'd rather not eject if I don't have to.
According to this, there currently isn't a way to live develop using "iPhone mode" on an iPad.
The Expo Client app can’t change its tablet support on the fly,
unfortunately, so it will always adapt your project to the iPad
viewport.
So, following the above forum here is how you get around it:
Run exp build:ios -t simulator
Open Simulator
Select Hardware/Device/iOs 11.x/iPad x generation
Unpack the generated build from the first command
You should have a file named yourApp.app
Drag that file into the iPad you are running in Simulator
It will install the app on the device and you can then view your creation
This is faster than doing a whole build cycle with TestFlight just to see your changes.
But it still leaves a bit to be desired.

Appcelerator App Conversion iOS to Android.

One of our developer developed an app in appcelerator using alloy framework for iOS which works fine. Now we want to run the same app in Android, since the appcelerator is a cross platform tool, we wish to make the Android version of the App. I tried searching about it and explored the applcelerator ide for options but couldn't find it. Can some one please guide me into the right direction?
First of all have a look at this link : http://docs.appcelerator.com/platform/latest/#!/guide/Supporting_Multiple_Platforms_in_a_Single_Codebase this will guide you to update the application for multiple platforms.
Their are basically two different ways to port any application from android to iOS or vise-versa, but before that just let me clear one more thing to you about tiapp.xml.
In the tiapp.xml of your project you need to updated the Development Target by checking for which platform you are developing the application for (iPhone, iPad, android, Mobile Web).
Option 1 :
Cross Platform is build to make code re-usable (i.e. re-use same code for all the platforms), but we have exceptions with many things. Their are lot of components that work fine in iOS but when you use them in android then you will face errors. So in that case you just need to apply conditions for android and iOS like below :
if(OS_ANDROID)
// do something
else if(OS_IOS)
// do something
What you need to do is that you need run the application in android simulator and test the application for these changes and then apply the changes accordingly.
Basically a developer has to target the UI for both the platforms, as their will not be any logical differences between the two. Also their will be UI changes between the same components, like for example a picker in iOS will not look the same as it will when you look it in an android application.
Option 2 :
Now in the project you have assets folder with the platform that you have selected in the tiapp.xml (i.e. iPhone, android etc).
You can create similar structure in the style and view folder, create two folders iOS and android in both the directory (i.e. style and view).
First, move .tss of style folder (except app.tss and index.tss) in the iOS folder, then copy the files in the android folder also.
Repeat the similar process with the View folder also.
Now you have two different structures (i.e. view and styles) according to their platform. Now you can run the application in android simulators and resolve the error that you face.
Hope this small information helps the cause, you can also have look at the documentation of all the components from below link :
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TableView

How to check cpu usage for scripts and gameObjects in unity?

I have created the action game in unity. But the frame rate is too low on mobile devices. How do I check how much cpu is currently using for my scripts and gameObject in unity?. Similar like how we do in "Instruments" in iOS.
there is built-in function called Profiler in unity3D though It's restricted if you are using free ver of Unity
Check http://docs.unity3d.com/Documentation/Manual/iphone-InternalProfiler.html
In the case you have Xcode on your system,You can also use Instruments for your unity project.
1.Check Development build in the build menu and build your unity project into iOS/OSX app.
2.Open Xcode and select Edit Scheme.... then choose Debug for Build Configuration
3.Do Clean and Build
4.Select the Profile and Run Instruments
If you want to check the usage of specific script you wrote,Check
BehaviourManager::Update -> MonoBehaviour::Update -> CallUpdateMethod

Xcode default scheme and architecture setting mismatch (iPhone development)

I am developing iPhone application and choosing to build iPhone project. However, I don't know which setting or which part I edited in info.plist. Now the default scheme and architecture is set to be Mac application development.
Can anyone tell me how to edit the .plist file or make any setting to make the project build in iPhone/iPad stimulator nor Mac, when I choose to build an iPhone/iPad project. (I had edited the plist file using terminal, so I not sure which part I did wrong and cause this problem).
Because now every iPhone application project cannot be built, even for the new iOS application project (due to the setting will auto set to Mac nor iPhone).
in the build settings for your project (and you may have to do this for each target) change BaseSDK to Latest iOS.
i have no idea why changing the info.plist in one project would affect any new projects you create, tho.

Resources