Android emulators are not working on macOS Big Sur 11.3+ - android-emulator

I have upgraded the mac OS to Big Sur and none of the emulators are working. It seems that all Android emulators Fails on Mac OS Big Sur Beta. I deleted the old emulators and created new ones with different HW/SW, unsuccessfully. Introduced the following issues in the android emulator.
ffffffffb69b4dbb: unhandled exit 1d
Emulator Engine Failed
adb Device Offline
https://issuetracker.google.com/issues/165038831
Does anyone have a solution?
EDIT 27.04.2021
~/Library/Android/sdk/emulator/emulator -gpu host -read-only -feature HVF -avd Pixel_4_API_29
emulator: Android emulator version 30.5.5.0 (build_id 7285888) (CL:N/A)
handleCpuAcceleration: feature check for hvf
cannot add library /Users/dunatv/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed
added library /Users/dunatv/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib
cannot add library /Users/dunatv/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libMoltenVK.dylib: failed
HVF error: HV_ERROR
qemu-system-x86_64: failed to initialize HVF: Invalid argument
HAX is working and emulator runs in fast virt mode.
qemu-system-x86_64: Back to HAX accelerator
added library /Users/dunatv/Library/Android/sdk/emulator/lib64/vulkan/libMoltenVK.dylib
emulator: INFO: GrpcServices.cpp:301: Started GRPC server at 127.0.0.1:8554, security: Local
UPDATE: 11 Aug 2021
Currently the Emulators and Arctic Fox are working. Tested on Big Sur 11.5.1

Update: this should now be fixed by version 30.5.6 of the Android emulator in the stable channel.
However, if you are now experiencing issues after updating to the latest version of the Android Emulator you can fix this by removing and then adding back the Android Emulator from the SDK Manager.
Tools > SDK Manager > SDK Tools
Uncheck Android Emulator and hit apply.
Check Android Emulator and hit apply.
Original answer:
This worked for me https://www.arthurkoziel.com/qemu-on-macos-big-sur
Essentially, create an XML file called entitlements.xml with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.hypervisor</key>
<true/>
</dict>
</plist>
Copy the XML file to ~/Library/Android/sdk/emulator/qemu/darwin-x86_64
Then run the following commands in terminal:
codesign -s - --entitlements entitlements.xml --force qemu-system-aarch64
codesign -s - --entitlements entitlements.xml --force qemu-system-aarch64-headless
codesign -s - --entitlements entitlements.xml --force qemu-system-armel
codesign -s - --entitlements entitlements.xml --force qemu-system-armel-headless
codesign -s - --entitlements entitlements.xml --force qemu-system-i386
codesign -s - --entitlements entitlements.xml --force qemu-system-i386-headless
codesign -s - --entitlements entitlements.xml --force qemu-system-x86_64
codesign -s - --entitlements entitlements.xml --force qemu-system-x86_64-headless

Update, 10-1-2020
The Android Emulator team has pushed 30.1.5 which fixes this issue in stable. The dev build, 30.2.0 does not contain this fix. It should be available "soon" according to the Googler's working on this.
Another note, if you experience poor performance in your emulator you may wish to try using the host's GPU for rendering. This can be accomplished by running the following command in your terminal where -avd is the name of your emulator device with spaces turned to underscores.
~/Library/Android/sdk/emulator/emulator -gpu host -feature HVF -avd pixel_3a_api_29
Old information, kept for educational value:
This is the reference to the commit fixing this issue for Big Sur. This looks like it should be released in the emulator 30.1.5 (see log https://android.googlesource.com/platform/external/qemu/+log/refs/heads/emu-30-release) which should be in the next canary build.
If you can't wait, you should be able to build off that branch. Lightly tested guide heavily pulling from the readme of the repo:
# Get the google repo tool - you can skip if you already have it
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo && chmod +x /usr/local/bin/repo
# Get the code, will take some time. Probably best to go get a coffee here or run on a server if you have poor internet
mkdir -p $HOME/emu-master-dev && cd $HOME/emu-master-dev
repo init -u https://android.googlesource.com/platform/manifest -b emu-master-dev
repo sync -j8
# Get XCode 10.1 - required
https://download.developer.apple.com/Developer_Tools/Xcode_10.1/Xcode_10.1.xip
sudo xcodebuild -license accept &&
sudo xcode-select --install
# Get MacOS 10.13 SDK which is required
export XCODE_PATH=$(xcode-select -print-path 2>/dev/null)
git clone https://github.com/phracker/MacOSX-SDKs
cp -r MacOSX-SDKs/MacOSX10.13.sdk/ "$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs"
# Build the emulator, which will be another coffee break...
cd external/qemu && android/rebuild.sh
# run it :)
./objs/emulator -list-avds

Steps to fix the issue:
1.Open Terminal and go to the directory /Users/<username>/Library/Android/sdk/emulator/qemu/darwin-x86_64/
2.Create an xml file named entitlements.xml with touch or cat commands
3.Add this content to the entitlements.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.hypervisor</key>
<true/>
</dict>
</plist>
4.Then simply sign the qemu-system-x86_64 with it:
codesign -s - --entitlements entitlements.xml --force qemu-system-x86_64
5.Now simply restart Android Studio and the Android Emulator should work again!

My solution is wiping data from Android studio AVD, then start it again and again until it is successfully launched, using ./emulator #Pixel_3a_API_29 command.

After trying many of the answers / comments on SO, found this workaround to work and be reproducible:
Setup a new AVD
I used Pixel 3 & 3a, API 30, default options
Launch the AVD using the emulator CLI
$ ~/Library/Android/sdk/emulator/emulator #Pixel_3a_API_30
You'll see the infamous ...unhandled exit 1d
Cancel the command with ⌃ + c or press the x on the emulator sidebar
You should see a spinner about Saving State...
Run the emulator again (step 2), this time it should show:
5. Click DISMISS (or wait) and the emulator should boot into Android
Note: Starting the same AVD from Android Studio / AVD Manager GUI will still run into this exception, so when you need it - start the emulator like in step 2.

Running the emulator like this:
~/Library/Android/sdk/emulator/emulator -wipe-data #Pixel_3a_API_30
Fixed it for me.

As mentionned by #Demirezen, for the time being, it is a code signing issue see details here.
Either code signing by yourself or using emulator 30.6.4 from canary build solves the problem.

Go to /Users/<your user>/Library/Android/sdk/emulator/qemu/
Inside this file you will see files. If the names of those files contain the number 64 then:
Create virtual device with image arm64-v8a + API LEVEL= S
After those steps emulator should be opened.

Spent a whole day trying out different methods, including downloading qemu. Finally...went into Android SDK> SDK tools > updated everything, made sure HAXM installer is installed and ticked. Worked!

After last BigSur beta update (11.0 Beta (20A5395g)), Android Studio keeps shuting down. UI is not responding if I open any subwindow...
Never more beta

Seems to work with emulator 30.2.6 (latest in beta channel at this moment)
Although there was a problem with a lockfile that prevented the emu from launching.
Here's what brought everything back to normal:
Wiping data of all AVDs (not sure if this is required)
Looking through every ~/.android/avd/*.avd/ folder and removing the hardware-qemu.ini.lock file if present.

invalidate caches / restart and re-create the image, seems like some behind-the-curtains configuration is not forward-compatible.

I had the same problem, just update your android studio and all your sdk tools to the latest version and everything will work just fine.

Adding proper ANDROID_AVD_HOME helps somehow.
You can add export ANDROID_AVD_HOME=$HOME/.android/avd to ~/.bash_profile

Related

flutter stuck on Compiling, linking and signing

Flutter project is stuck in Compiling, linking and signing... i dont just understand why this is stuck here...
even using verbose i dont get any stack trace on why this is stuck...
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...
Running pod install... 11.6s
Running Xcode build...
└─Compiling, linking and signing...
The problem should be in the existing project created on previous environment (old versions) and has to be resolved by creating a new one and moving content in.
Move all my custom contents from existing my project (assets, fonts, lib folders and config files...) to this new project and ran the command : the flutter build ios command works well now !
following this : Fixing Xcode 9 issue: "iPhone is busy: Preparing debugger support for iPhone"
I TRIED :
On Xcode:
Go to "Window" -> "Devices and Simulators"
"Unpair iPhone" (on the side list, right clic)
Then:
Unplug and plug again the USB cable
Press Trust in the prompt message in the device
in Flutter Terminal, paste and enter :
flutter clean
flutter pub get
cd ios
pod install --repo-update
cd ..
Then run the app.
==> Worked only 1st time for me.
My work around for launching IOS devices for now:
Each time I want IOS device,
I COPY/ PASTE and press ENTER on the Terminal:
flutter clean
flutter pub get
cd ios
pod install --repo-update
cd ..
flutter run

I get an error when I try to run the emulator. Is it a problem with the version? [duplicate]

I'm receiving the following error while running flutter run on some projects, however, on other projects it works fine:
(base) Nusraths-MacBook-Pro:flutter_uber_clone rahama$ flutter emulators --launch Pixel_2_XL_API_28
(base) Nusraths-MacBook-Pro:flutter_uber_clone rahama$ flutter run
Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing Gradle... 0.8s
Resolving dependencies... 1.4s
Running Gradle task 'assembly debug'...
Running Gradle task 'assembly debug'... Done 9.3s
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk... 1.9s
Error: ADB exited with exit code 1
Performing Streamed Install
ADB: failed to install /Users/rahama/development/flutter_uber_clone/build/app/outputs/apk/app.apk: Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]
Error launching the application on Android SDK built for x86.
It's just the flutter demo project, I haven't made any changes to it.
Actually, the answer lies in the error message of your question:
[ADB: failed to install /Users/rahama/development/flutter_uber_clone/build/app/outputs/apk/app.apk: Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]Error launching the application on Android SDK built for x86.]
Your Emulator is running out of space, clear its cache:
Click on AVD Manager
Wipe Data (Your Target Device )
You are set to go..
Flutter had a new update (I think last night), run flutter upgrade in the terminal and it should work fine (at least that did it for me).
Docs:
To update both the Flutter SDK and the packages that your app depends on, use the flutter upgrade command from the root of your app (the same directory that contains the pubspec.yaml file)
https://flutter.dev/docs/development/tools/sdk/upgrading
Run in terminal
$ flutter clean
and then
$ flutter pub get
and then
$ flutter packages get
then
$ flutter run
Although I don't have any other apps installed on my emulator, when I install the flutter app, I get the same error.
I found that the storage space of the emulator is indeed not enough. Because when I created the emulator, the default was only 1024M. When I changed the storage space of the emulator to 4096M, the problem was solved.
In my case, it was caused by an adb glitch, not a flutter problem.
This was solved by doing a combination of the following, not sure which step fixed it exactly
Reset adb server on desktop, macOS in mycase: adb kill-server, and then adb start-server
Reset USB debugging on the mobile device.
Restarted the device.
None of the existing answers worked for me, so it wasn't a flutter problem. A plain adb install any.apk didn't work. So I narrowed it down to an adb/usb issue.
this common problem with the Emulator and all you need to clear the Emulator cache .
in my case it was the solution...
1- open AVD Manger.
2- click on the (bottom arrow) that beside (Edit) button.
3- choose Wipe Data.
Sometimes it can work by uninstalling your app and and all it's data then try again,
another fix is to send the apk you are trying to install from projectname/build/app/outputs/apk and to your device and install it and try again.
Note: Following is answer for stuck at Performing Streamed Install by adb install xxx.apk:
phenomenon
use adb install xxx.apk and showing Performing Streamed Install but stuck, hang forever.
Have tried
re-plug USB cable
change USB adapter
change USB cable
reboot PC(Mac)
reboot android phone
restart VSCode
make adb command shorter
from: adb -s hxxxxxxxxs install -r /Users/limao/dev/xxx/crawler/appAutoCrawler/AppCrawler/task/20201202_xxx_0192LeiMoChuanShuo/20201202_xxx_0192LeiMoChuanShuo_gameApp_Android/20201202_xxx_0192LeiMoChuanShuo_gameApp_Android_0.apk
to: adb -s hxxxxxxxxs install -r /var/folders/gt/5868sbcd1jq4rxvryqhy2_1sz8n0s3/T/tmpq3ypjfgd/20201202_xxx_0192LeiMoChuanShuo_gameApp_Android_0.apk
tried adb shell pm install but not support
etc...
all not work.
Final solution
update (original old version 29.0.5) adb to latest version (30.0.5)
Q: how to update adb to latest version
A:
goto
https://developer.android.com/studio/releases/platform-tools
to download your platform adb
下载适用于 Windows 的 SDK Platform-Tools
下载适用于 Mac 的 SDK Platform-Tools
下载适用于 Linux 的 SDK Platform-Tools
or:
goto
https://www.xda-developers.com/google-releases-separate-adb-and-fastboot-binary-downloads/
to download:
windows
https://dl.google.com/android/repository/platform-tools-latest-windows.zip
Mac
https://dl.google.com/android/repository/platform-tools-latest-darwin.zip
Linux
https://dl.google.com/android/repository/platform-tools-latest-linux.zip
unzip to got folder platform-tools
add the folder to your PATH variable
eg:
vi ~/.zshrc
PATH=/Users/limao/dev/tools/android/adb/platform-tools:$PATH
In my case, this was resolved by updating android studio and all the flutter and dart plugins.
Go to File>> invalidate caches
By this way I resolved this issues on BlueStack.Do these steps for running android applications on BlueStack Emulator.
Go to setting of BlueStack Emulator
Then click on Advance and then
Turn on Android Debug Bridge (ADB)
I experienced this same problem on a physical device, tried all solution i could see out there but none worked.
What worked at the end of the day was to ensure my device API version was also installed in the android studio.
image1
image2
Forewords
This question gets the first result from Google, so my answer covers a bit different error.
The error in question has [INSTALL_FAILED_INSUFFICIENT_STORAGE] code. My answer is for any Performing Streamed Install error that does not specifically define [INSTALL_FAILED_INSUFFICIENT_STORAGE] code.
My Environment
KDE Neon 5.24 (a.k.a. Ubuntu 20.04 but latest KDE stuff)
Visual Studio Code from Snap (I use this mainly)
Android Studio from Snap (I use this to install SDK, Platform Tools and Build Tools)
Troubleshooting
The problem is this globally installed /usr/bin/adb overrides the adb that Flutter uses. As you know, Ubuntu has many outdated packages (to protect their system's stability). ADB is one of them. So, if you try to do:
adb kill-server
adb start-server
You will highly likely get an output similar to below:
* daemon not running; starting now at tcp:5037
ADB server didn't ACK
Full server startup log: /tmp/adb.1000.log
Server had pid: 12668
--- adb starting (pid 12668) ---
adb I 03-26 03:19:35 12668 12668 main.cpp:57] Android Debug Bridge version 1.0.39
adb I 03-26 03:19:35 12668 12668 main.cpp:57] Version 1:8.1.0+r23-5ubuntu2
adb I 03-26 03:19:35 12668 12668 main.cpp:57] Installed as /usr/lib/android-sdk/platform-tools/adb
adb I 03-26 03:19:35 12668 12668 main.cpp:57]
adb I 03-26 03:19:35 12668 12668 adb_auth_host.cpp:416] adb_auth_init...
adb I 03-26 03:19:35 12668 12668 adb_auth_host.cpp:174] read_key_file '/home/erayerdin/.android/adbkey'...
adb I 03-26 03:19:35 12668 12668 adb_auth_host.cpp:391] adb_auth_inotify_init...
adb I 03-26 03:19:35 12668 12668 adb_auth_host.cpp:467] Calling send_auth_response
adb server killed by remote request
* failed to start daemon
error: cannot connect to daemon
In some flutter run sessions, I've got an output similar to "adb server version (whatever) does not match the client (whatever); killing". That's when I had the doubt maybe I have installed adb globally. Check this:
which adb
# /usr/bin/adb
# This is a sign that this adb might be globally installed.
# This must be a symlink. Just to make sure, I do the following...
realpath /usr/bin/adb
# /usr/lib/android-sdk/platform-tools
# This is the evidence that it has been installed globally.
So, we use an outdated version of adb, which does not match the target device's adb server.
Solution
So, we need to get rid of this global adb first.
⚠ Warning
If you use adb from terminal, what we are going to do will remove it. You can add your {SDK PATH}/platform-tools where SDK PATH is where you have installed SDK to get it back.
Simply do:
sudo apt remove android-sdk android-sdk-common android-sdk-build-tools android-sdk-build-tools-common android-sdk-platform-tools android-sdk-platform-tools-common
However, doing these actually does not remove adb from the system. It still lays there for some reason, so, for the last step, we do:
# simply backup our symlink
sudo mv /usr/bin/adb /usr/bin/adb.bak
# and backup global android-sdk tools
sudo mv /usr/lib/android-sdk /usr/lib/android-sdk.bak
After these steps, you can restart your editor and try again. If you want to make double sure, you can optionally do (while your editor's closed):
# clean the build artifacts
flutter clean
# reinstall the packages because we have cleared them
flutter pub get
flutter pub get packages
Android 12 requires you to add a piece of code to your main activity
Go to your project folder and open the AndroidManifest.xml file
Add the below code in the activity
android:exported="true"
I was having the same issue with a physical device connected via wifi, then I figured out what was wrong. The battery of my device was below 15%, it worked as expected after charging. So, keep an eye on the battery status if you're working with a physical device via wifi.

Android Emulator 30.4.5 not working on MacOS

System Info
MacOs Version - 11.3 Beta
Android Studio Version - 4.1.2
Android Emulator Version - 30.4.5
Android HAXM Version - 7.5.1
Error Stack
emulator: Android emulator version 30.4.5.0 (build_id 7140946) (CL:N/A)
handleCpuAcceleration: feature check for hvf
cannot add library /Users/rajaparikshit/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed
HVF error: HV_ERROR
qemu-system-x86_64: failed to initialize HVF: Invalid argument
Failed to open the hax module
No accelerator found.
qemu-system-x86_64: failed to initialize HAX: Operation not supported by device
added library /Users/rajaparikshit/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib
cannot add library /Users/rajaparikshit/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libMoltenVK.dylib: failed
added library /Users/rajaparikshit/Library/Android/sdk/emulator/lib64/vulkan/libMoltenVK.dylib
Android emulator version - 30.0.26 was running perfectly as expected. But after 30.4.5.0 update its not working.
I tried to search way to downgrade to 30.0.26 but I couldn't find one i.e. there is no any option in android studio manager also.
I saw this SO post. Google store all the emulators version in repository URL - http://dl.google.com/android/repository/ but I didn't know the build version for 30.0.26 version so couldn't go this way.
Update -
Please follow the accepted answer below and do give upvote.
For newbies or if you get stuck at any point please follow the steps:
If you have uninstalled the latest version of emulator as its not working, then please install it again. (Because if we manually replace the emulator directory Android Studio is not able to recognise it and hence you won't able to create/run AVD from Android Studio)
Download the zip file from the URL mentioned in answer.
Copy(Not Move) the content to your original emulator directory.
Restart the android studio if needed.
Still this is just a workaround, actual issue with this new version is still there.
Below is a temporary fix.
Error:
cannot add library
/Users//Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib:
failed
It seems the dylib file doesn’t exists in the path specified in the error message.
However, the library exists in the path below:
~/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib
Symlink vaulkan lib to the path emulator is trying to load the library from:
ln -s ~/Library/Android/sdk/emulator/lib64 ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64
Error 2:
Then I got an error related to code signing.
HVF error: HV_ERROR
qemu-system-x86_64: failed to initialize HVF: Invalid argument
Fix the code signing error:
Step 1:
Create the app.entitlements file for codesigning and add below content (source: https://www.reddit.com/r/VFIO/comments/kdhgni/qemu_hvf_support_for_mac_os_x_bug_sur_hv_error/):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <dict> <key>com.apple.security.hypervisor</key> <true/> </dict> </plist>
Step 2:
Perform codesign:
codesign -s - --entitlements ~/<path>/<to>/app.entitlements --force ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/qemu-system-x86_64
Launch the emulator:
~/Library/Android/sdk/emulator/emulator -avd Pixel_4_API_30 -gpu auto
Emulator should load without any errors. Hope this helped.
UPDATE: This issue no longer exists in the current version of the emulator. Please refer to #channe's comment to revert the change after upgrading AS/emulator.
Here is the link for the emulator revision 30.0.26 https://dl.google.com/android/repository/emulator-darwin-6885378.zip
(taken from this answer)
Download it and then copy over the installed emulator.
It won't work if you have files quarantine enabled; I did so I needed to remove quarantine recursively from downloaded files
xattr -r -d com.apple.quarantine /path/to/dir
Then I can run the emulator by invoking:
emulator #device_name
It doesn't seem to be detected by AS, but works nonetheless.
I had the same issue on a Mac. I was able to fix it be updating Android Emulator to 30.6.5 from Android Studio -> Sdk Manager -> Android Sdk -> SDK Tools.
Also I had to install Intel x86 Emulator Accelerator (HAXM Installer).
Please update your android build tools to latest version avaialble in the studio, this will update your emulator binary and all libs(.dylibs). This is the correct fix..

Ionic emulate Ios fails to run The session does not open my app

Ionic emulate ios failed on Mac OS Yosemite. Their have some cases were the ios device emulated, but shortly after the terminal console shoots up the error message below.
** BUILD SUCCEEDED **
No target specified for emulator. Deploying to iPhone-6 simulator
An error was encountered processing the command (code=146):
Invalid device state
An error was encountered processing the command (code=146):
Exception encountered connecting to CoreSimulatorBridge: Unable to connect to CoreSimulatorBridge
ENOENT, no such file or directory '/Users/yay/Library/Logs/CoreSimulator/2CAA2C39-7F22-4AF2-BBDE-86609188F37C/system.log'
Error code 1 for command: ios-sim with args: launch,/Users/yay/code/myApp/platforms/ios/build/emulator/myApp.app,--devicetypeid,com.apple.CoreSimulator.SimDeviceType.iPhone-6,--stderr,/Users/yay/code/myApp/platforms/ios/cordova/console.log,--stdout,/Users/yay/code/myApp/platforms/ios/cordova/console.log,--exit
Error: /Users/yay/code/myApp/platforms/ios/cordova/run: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
The issue is because you used sudo to create and/or build the project.
Just input these commands (without the $ of course):
1) Remove with sudo
$ sudo ionic platform remove ios
2) Add iOS back without sudo
$ ionic platform add ios
3) Run iOS emulator
$ ionic emulate ios
Source: https://github.com/driftyco/ionic/issues/4052 (rajkotecha's comment)
Do NOT use sudo when creating or building the project.
Please see https://github.com/driftyco/ionic/issues/4052
I've encountered this issue before, and I believe you messed up with your permission. However, I managed to solve it by reinstall everything from scratch (NOT reformat OS). I suggest you may try to remove all your Xcode, ionic, cordova, and ios-sim content and reinstall again.
Delete your Xcode from your Mac OS.
Remove everything inside:
/usr/local/bin
/usr/local/include
/usr/local/lib/dtrace
/usr/local/share/man/man1
/usr/local/share/systemtap/tapset/
Delete the folder:
/usr/local/lib/node_modules
Once you done the instruction above, kindly use your spotlight to search for keywords such as node, cordova, ionic, etc... to see whether it is still exist or not. Please also ensure yourApp within your Users/username folder is deleted.
You may also try to use your terminal input:
npm -v
cordova -v
ionic -v
It will shows nothing/not found if you've deleted everything completely.
Now you can download and install Xcode from App Store, and wait for Xcode is fully installed in your Mac, then proceed to here to start again your ionic project.
Lastly, once you begin to create an ionic project, by right you no need to use any sudo commands anymore in creating or building this project.
Example:
ionic build ios
Instead of:
sudo ionic build ios
It should be working unless you are not the root user.
Happy coding and have a nice day! :D

Android Emulator disconnects shortly after launching

when i launch an emulator or try to run an android project i get this error -emulator: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed. the emulator is visible for only a few seconds.the sdk and eclipse are correctly installed.
I have also faced this problem & after a lot of trying I found a solution...
this is very simple you need to give permission both emulator & ddms.
they are located in the /tools directory of android-sdk
first go to that directory, then run the following command :
$sudo chmod 755 emulator
$sudo chmod 755 ddms
then :
$emulator -avd <name of avd>
Hope this will work
:)