capacitor: bug: App Crashes launching Camera Plugin (Capacitor v2.0.0)

Bug Report

Capacitor Version

npx cap doctor output: Latest Dependencies: @capacitor/cli: 2.0.0 @capacitor/core: 2.0.0 @capacitor/android: 2.0.0 @capacitor/electron: 2.0.0 @capacitor/ios: 2.0.0

Installed Dependencies: @capacitor/ios not installed @capacitor/electron not installed @capacitor/cli 2.0.0 @capacitor/core 2.0.0 @capacitor/android 2.0.0 [success] Android looking great! 👌

Affected Platform(s)

  • Android
  • iOS
  • Electron
  • Web

Current Behavior

Going back to a project where the Camera Plugin was working, I upgraded Capacitor to v2. The plugin works correctly on the Browser, but when testing the app on the Android emulator, when launching the Camera, the emulator crashes and closes.

Expected Behavior

The camera should open correctly.

Sample Code or Sample Application Repo

I started an application from 0 (I am using Angular and Capacitor) in case it was related to mismatch of dependencies’ versions. In this new app I only have this and still facing the same behavior as described above:

AppComponent Template

<button (click)="takePicture()">Take Picture</button>
<img [src]="photo" *ngIf="photo">

AppComponent

import { Component } from '@angular/core';

import { Plugins, CameraResultType } from '@capacitor/core';
import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser';
const { Camera } = Plugins;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  photo: SafeResourceUrl;

  constructor(private sanitizer: DomSanitizer) {  }

  async takePicture() {
    const image = await Camera.getPhoto({
      quality: 90,
      allowEditing: true,
      resultType: CameraResultType.DataUrl
    });
    
    this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl));
  }
}

Package.json dependencies

"dependencies": {
    "@angular/animations": "~9.1.0",
    "@angular/common": "~9.1.0",
    "@angular/compiler": "~9.1.0",
    "@angular/core": "~9.1.0",
    "@angular/forms": "~9.1.0",
    "@angular/platform-browser": "~9.1.0",
    "@angular/platform-browser-dynamic": "~9.1.0",
    "@angular/router": "~9.1.0",
    "@capacitor/android": "^2.0.0",
    "@capacitor/cli": "^2.0.0",
    "@capacitor/core": "^2.0.0",
    "@ionic/pwa-elements": "^1.5.1",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.0",
    "@angular/cli": "~9.1.0",
    "@angular/compiler-cli": "~9.1.0",
    "@angular/language-service": "~9.1.0",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.4.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  }

Reproduction Steps

  1. Launch the app
  2. Click on the Take Picture button
  3. Select “Take Picture” on the Bottom Sheet
  4. App Crashes and Emulator Closes

Other Technical Details

npm --version output: 6.14.2

node --version output: v12.13.0

Other Information

–

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

@nereolopez we are seeing this in production as well with Capacitor@1.5.2 on iOS. Have you had any success in resolving?

  1. I’m seeing this: [XPC] Handle connection with error: Connection interrupted in the console logs of Xcode
  2. This also occurs after tapping “Use Photo”, probably more frequently than on launch of Camera plugin.
  3. It seems to occur without any rhyme or reason…sometimes the app recovers, other times it goes full white screen and closes.
  4. It appears too happen more frequently in older devices (iPhone 8 happens about 3x more than iPhone X)
  5. The same issue occurs on Capacitor 2.0.1
  6. This error is throw in XCode. console intermittently on first camera load also:
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x2812c2d00 UIView:0x105073e70.width == - 16   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x2812c2d00 UIView:0x105073e70.width == - 16   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2020-05-09 16:44:04.043033-0400 Notemeal[33746:9027705] [Process] kill() returned unexpected error 1
2020-05-09 16:44:04.043958-0400 Notemeal[33746:9027705] [Process] kill() returned unexpected error 1
2020-05-09 16:44:05.475104-0400 Notemeal[33746:9027705] [Process] kill() returned unexpected error 1
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIViewController setModalPresentationStyle:]
PID: 33746, TID: 9027837, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Capacitor                           0x0000000104c02278 $s9Capacitor15CAPCameraPluginC10showCamerayySo13CAPPluginCallCFySbcfU_ + 1420
5   Capacitor                           0x0000000104bf4d24 $sSbIegy_SbIeyBy_TR + 68
6   TCC                                 0x000000019a5fdb60 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 7008
7   TCC                                 0x000000019a601b28 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 23336
8   libxpc.dylib                        0x0000000193ff6c84 219DEC3C-E62E-395D-8911-FB74F73A5598 + 97412
9   libxpc.dylib                        0x0000000193feaf18 219DEC3C-E62E-395D-8911-FB74F73A5598 + 48920
10  libdispatch.dylib                   0x0000000104e7ac58 _dispatch_client_callout3 + 16
11  libdispatch.dylib                   0x0000000104e9629c _dispatch_mach_msg_async_reply_invoke + 388
12  libdispatch.dylib                   0x0000000104e8d03c _dispatch_kevent_worker_thread + 1376
13  libsystem_pthread.dylib             0x000000019413afc0 _pthread_wqthread + 332
14  libsystem_pthread.dylib             0x000000019413dad4 start_wqthread + 8
2020-05-09 16:44:05.952869-0400 Notemeal[33746:9027837] [reports] Main Thread Checker: UI API called on a background thread: -[UIViewController setModalPresentationStyle:]
PID: 33746, TID: 9027837, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Capacitor                           0x0000000104c02278 $s9Capacitor15CAPCameraPluginC10showCamerayySo13CAPPluginCallCFySbcfU_ + 1420
5   Capacitor                           0x0000000104bf4d24 $sSbIegy_SbIeyBy_TR + 68
6   TCC                                 0x000000019a5fdb60 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 7008
7   TCC                                 0x000000019a601b28 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 23336
8   libxpc.dylib                        0x0000000193ff6c84 219DEC3C-E62E-395D-8911-FB74F73A5598 + 97412
9   libxpc.dylib                        0x0000000193feaf18 219DEC3C-E62E-395D-8911-FB74F73A5598 + 48920
10  libdispatch.dylib                   0x0000000104e7ac58 _dispatch_client_callout3 + 16
11  libdispatch.dylib                   0x0000000104e9629c _dispatch_mach_msg_async_reply_invoke + 388
12  libdispatch.dylib                   0x0000000104e8d03c _dispatch_kevent_worker_thread + 1376
13  libsystem_pthread.dylib             0x000000019413afc0 _pthread_wqthread + 332
14  libsystem_pthread.dylib             0x000000019413dad4 start_wqthread + 8
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIImagePickerController setSourceType:]
PID: 33746, TID: 9027837, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Capacitor                           0x0000000104c02394 $s9Capacitor15CAPCameraPluginC10showCamerayySo13CAPPluginCallCFySbcfU_ + 1704
5   Capacitor                           0x0000000104bf4d24 $sSbIegy_SbIeyBy_TR + 68
6   TCC                                 0x000000019a5fdb60 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 7008
7   TCC                                 0x000000019a601b28 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 23336
8   libxpc.dylib                        0x0000000193ff6c84 219DEC3C-E62E-395D-8911-FB74F73A5598 + 97412
9   libxpc.dylib                        0x0000000193feaf18 219DEC3C-E62E-395D-8911-FB74F73A5598 + 48920
10  libdispatch.dylib                   0x0000000104e7ac58 _dispatch_client_callout3 + 16
11  libdispatch.dylib                   0x0000000104e9629c _dispatch_mach_msg_async_reply_invoke + 388
12  libdispatch.dylib                   0x0000000104e8d03c _dispatch_kevent_worker_thread + 1376
13  libsystem_pthread.dylib             0x000000019413afc0 _pthread_wqthread + 332
14  libsystem_pthread.dylib             0x000000019413dad4 start_wqthread + 8
2020-05-09 16:44:19.758898-0400 Notemeal[33746:9027837] [reports] Main Thread Checker: UI API called on a background thread: -[UIImagePickerController setSourceType:]
PID: 33746, TID: 9027837, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Capacitor                           0x0000000104c02394 $s9Capacitor15CAPCameraPluginC10showCamerayySo13CAPPluginCallCFySbcfU_ + 1704
5   Capacitor                           0x0000000104bf4d24 $sSbIegy_SbIeyBy_TR + 68
6   TCC                                 0x000000019a5fdb60 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 7008
7   TCC                                 0x000000019a601b28 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 23336
8   libxpc.dylib                        0x0000000193ff6c84 219DEC3C-E62E-395D-8911-FB74F73A5598 + 97412
9   libxpc.dylib                        0x0000000193feaf18 219DEC3C-E62E-395D-8911-FB74F73A5598 + 48920
10  libdispatch.dylib                   0x0000000104e7ac58 _dispatch_client_callout3 + 16
11  libdispatch.dylib                   0x0000000104e9629c _dispatch_mach_msg_async_reply_invoke + 388
12  libdispatch.dylib                   0x0000000104e8d03c _dispatch_kevent_worker_thread + 1376
13  libsystem_pthread.dylib             0x000000019413afc0 _pthread_wqthread + 332
14  libsystem_pthread.dylib             0x000000019413dad4 start_wqthread + 8
2020-05-09 16:44:19.852147-0400 Notemeal[33746:9027705] [Process] kill() returned unexpected error 1
2020-05-09 16:44:19.852458-0400 Notemeal[33746:9027705] [Process] kill() returned unexpected error 1
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIImagePickerController setCameraDevice:]
PID: 33746, TID: 9027837, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Capacitor                           0x0000000104c025ec $s9Capacitor15CAPCameraPluginC10showCamerayySo13CAPPluginCallCFySbcfU_ + 2304
5   Capacitor                           0x0000000104bf4d24 $sSbIegy_SbIeyBy_TR + 68
6   TCC                                 0x000000019a5fdb60 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 7008
7   TCC                                 0x000000019a601b28 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 23336
8   libxpc.dylib                        0x0000000193ff6c84 219DEC3C-E62E-395D-8911-FB74F73A5598 + 97412
9   libxpc.dylib                        0x0000000193feaf18 219DEC3C-E62E-395D-8911-FB74F73A5598 + 48920
10  libdispatch.dylib                   0x0000000104e7ac58 _dispatch_client_callout3 + 16
11  libdispatch.dylib                   0x0000000104e9629c _dispatch_mach_msg_async_reply_invoke + 388
12  libdispatch.dylib                   0x0000000104e8d03c _dispatch_kevent_worker_thread + 1376
13  libsystem_pthread.dylib             0x000000019413afc0 _pthread_wqthread + 332
14  libsystem_pthread.dylib             0x000000019413dad4 start_wqthread + 8
2020-05-09 16:44:19.865180-0400 Notemeal[33746:9027837] [reports] Main Thread Checker: UI API called on a background thread: -[UIImagePickerController setCameraDevice:]
PID: 33746, TID: 9027837, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Capacitor                           0x0000000104c025ec $s9Capacitor15CAPCameraPluginC10showCamerayySo13CAPPluginCallCFySbcfU_ + 2304
5   Capacitor                           0x0000000104bf4d24 $sSbIegy_SbIeyBy_TR + 68
6   TCC                                 0x000000019a5fdb60 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 7008
7   TCC                                 0x000000019a601b28 03E8D082-B885-3FA8-A1DA-CCB21D26FE1A + 23336
8   libxpc.dylib                        0x0000000193ff6c84 219DEC3C-E62E-395D-8911-FB74F73A5598 + 97412
9   libxpc.dylib                        0x0000000193feaf18 219DEC3C-E62E-395D-8911-FB74F73A5598 + 48920
10  libdispatch.dylib                   0x0000000104e7ac58 _dispatch_client_callout3 + 16
11  libdispatch.dylib                   0x0000000104e9629c _dispatch_mach_msg_async_reply_invoke + 388
12  libdispatch.dylib                   0x0000000104e8d03c _dispatch_kevent_worker_thread + 1376
13  libsystem_pthread.dylib             0x000000019413afc0 _pthread_wqthread + 332
14  libsystem_pthread.dylib             0x000000019413dad4 start_wqthread + 8