Search code examples
reactjsionic-frameworkionic2capacitorcapacitor-plugin

Capacitor App Plugin dont let android studio build the apk


I am following the tutorial here: https://capacitorjs.com/docs/apis/app I did the following steps:

  • pnpm install @capacitor/app
  • npx cap sync
  • added the code below inside the activity section of the AndroidManifest.xml
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="@string/custom_url_scheme" />
    
  • pnpm react-scripts build && npx cap sync android && npx cap copy android && npx cap open android

I always did it that way, and it always build the apk normally, but just when I add the Capacitor APP plugin, the android studio gives an error

android studio bug

I didn't even change the code, I just added the plugin by pnpm install @capacitor/app and npx cap sync

Has anyone ever experienced this? Do you have any ideas on how to proceed?

solutions I tried:

  • install java sdk 17
  • delete the android folder and do npx cap add android && npx cap sync pnpm react-scripts build && npx cap sync android && npx cap copy android && npx cap open android

I expected to compile the app/apk normally, I'm trying to use the backButton event


Solution

  • As I am using pnpm, it downloaded version 5 of @capacitor/app, and my capacitor was on version 4.7.1, they are incompatible, I downgraded @capacitor/app to 4.1.1 and everything was resolved.

    Another thing, in the official tutorial it says to add those 4 lines, but when installing the app, there's no way to open it and it doesn't appear in the list of apps on the phone, so I had to remove the 4 lines