Cannot make ionic 5 project work using capacitor on simulator/device


ion build --prod and test in browser are ok.
Now I would like to test my capacitor feature (open the camera) on the devices but I am not knowledgeable enough to understand why what’s generated by the frameworks is not working and I am running out of ideas.

In short any good hint to build something that is working on iOS device or Android simulator?

I build as follows:

ionic build
npx cap copy
npx cap open android

ios simulator: ok but cannot test capacitor camera plugin which is only available on real device

on iphone XR: nok the app crashes as soon as started with below error message

dyld: Library not loaded: @rpath/Capacitor.framework/Capacitor
Referenced from: /private/var/containers/Bundle/Application/5CB1FD35-1C30-48BC-B653-5274AC471845/
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/5CB1FD35-1C30-48BC-B653-5274AC471845/ code signature invalid for ‘/private/var/containers/Bundle/Application/5CB1FD35-1C30-48BC-B653-5274AC471845/’

android simulator: nok the project generated cannot be built, error is:

Manifest merger failed : Attribute application@appComponentFactory

If I add the below to - as per stackoverflow
then it enables to build but crashes as soon as started on the simulator

The capacitor code I introduced is the following

import { Component, OnInit, Input } from "@angular/core";
import { Router, ActivatedRoute } from "@angular/router";
import { Plugins, CameraSource, CameraResultType } from "@capacitor/core";
const { Camera } = Plugins;
import { DomSanitizer, SafeResourceUrl } from "@angular/platform-browser";
  selector: "app-tab5",
  templateUrl: "",
  styleUrls: [""],
export class Tab5Page implements OnInit {
  imageTaken: boolean;
  image: SafeResourceUrl;

    private route: ActivatedRoute,
    private router: Router,
    private sanitizer: DomSanitizer
  ) {}

ngOnInit() {}

async takePhoto() {
    const result = await Camera.getPhoto({
      quality: 75,
      allowEditing: true,
      source: CameraSource.Camera,
      resultType: CameraResultType.Uri,
    this.image = this.sanitizer.bypassSecurityTrustUrl(result.webPath);
    this.imageTaken = true;

Thank you,

PS: ionic info


   Ionic CLI                     : 6.6.0 (/Users/me/applications/node-v10.15.3-darwin-x64/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.901.1
   @angular-devkit/schematics    : 9.1.1
   @angular/cli                  : 9.1.1
   @ionic/angular-toolkit        : 2.2.0


   Capacitor CLI   : 1.5.0
   @capacitor/core : 1.5.0


   Cordova CLI       : 9.0.0
   Cordova Platforms : none
   Cordova Plugins   : no whitelisted plugins (0 plugins total)


   cordova-res : 0.12.1
   native-run  : 1.0.0


   Android SDK Tools : 26.1.1 (/Users/me/Library/Android/sdk)
   ios-deploy        : 1.10.0
   ios-sim           : 8.0.2
   NodeJS            : v10.15.3 (/Users/me/applications/node-v10.15.3-darwin-x64/bin/node)
   npm               : 6.14.4
   OS                : macOS Catalina
   Xcode             : Xcode 11.4 Build version 11E146


I build as follows :

ionic build
ionic cap add android
ionic cap open android

Actually i don’t know if it change something but it’s the method on the website:

But i also have a problem with capacitor, when i test in browser the localStorage work, but when it’s on my android device, it’s not working.

Thanks for sharing.

I am following the commands given on capacitor site section Using Capacitor with Ionic

I tried the ones you are running after cleaning my android folder without success unfortunately, I obtained the same result: the android studio project generated is not correct out of the box:

Manifest merger failed : Attribute application@appComponentFactory value=( from [] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.2.0] AndroidManifest.xml:24:18-86 value=(
Suggestion: add ‘tools:replace=“android:appComponentFactory”’ to element at AndroidManifest.xml:5:5-43:19 to override.

Also I checked the versions of the SDK and the simulator PIxel 2 under Pie (API 28) as per Developing with Android and it sounds inline.

Screenshot 2020-04-18 at 3.32.15 AM

sdkmanager --list execution finishes with

ID                                                  | Installed | Available
  -------                                             | -------   | -------  
  extras;intel;Hardware_Accelerated_Execution_Manager | 7.3.2     | 7.5.1    
  platform-tools                                      | 28.0.2    | 29.0.6   
  system-images;android-27;google_apis;x86            | 8         | 9      

Actually reading again at Using Capacitor with Ionic I saw that Capacitor is easily installed directly into any Ionic project (1.0-4.x+).

Therefore as I am using Ionic 5 (my app was migrated from ionic 4 before) I “googled” and stumbled upon this Announcing Capacitor 2.0. Accordingly I

  • upgraded to capacitor 2.0

  • updated my Android studio for Android Q and Pixel 2 simulator with API 29.
    I followed android studio project lengthy adaptation described here From-1-5-1-to-2-0-0

  • aligned my configuration with android-template

but still no luck the app crashes once installed on the simulator, it starts and says “MyApp keeps stopping”

I assume the successive migrations introduced a problem I cannot solve and I will have to scaffold a brand new app and bring back my code in.

As assumed scaffolding from scratch an empty shell and copy pasting the resources did work.

Sounds a cleaner basis for my case, only one external component (ion-selectable) I am using and modals no longer work; also I had to declare modals in module entryComponents

ionic5 & capacitor 2.0 work as expected on android and ios.

Issue closed.