Search code examples
androidcordovaionic-frameworkcapacitor

Capacitor 3 and Ionic 6 Android build hitting "uses-sdk:minSdkVersion 1 cannot be smaller than version 21 declared in library [:capacitor-app]"


I'm quite stuck here despite having found a few quite similar Stack Overflow questions.

My specific case is trying to get an app to build on Android which I recently updated to Ionic 6 and most notably added Capacitor – while still using Cordova for a couple of plugins, but no longer for builds.

The work in progress is public on this branch.

The build error I get is:

Manifest merger failed : uses-sdk:minSdkVersion 1 cannot be smaller than version 21 declared in library [:capacitor-app] /Users/noel/files/Dev/PasswordMaker/node_modules/@capacitor/app/android/build/intermediates/merged_manifest/release/AndroidManifest.xml as the library might be using APIs not available in 1
    Suggestion: use a compatible library with a minSdk of at most 1,
        or increase this project's minSdk version to at least 21,
        or use tools:overrideLibrary="com.capacitorjs.plugins.app" to force usage (may lead to runtime failures)

As you can see, I've already:

I also tried some hail mary options like hard-coding a uses-sdk minimum version in the AndroidManifest.xml of every single module that shows up in Android Studio, but to no avail.

Any ideas would be much appreciated. Ideally I just want to build the project with minimum SDK 21, and target 30, without it falling over! The iOS build seems to be working fine and npx cap doctor reports no issues.

npx cap doctor
💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 3.3.3
  @capacitor/core: 3.3.3
  @capacitor/android: 3.3.3
  @capacitor/ios: 3.3.3

Installed Dependencies:

  @capacitor/android: 3.3.3
  @capacitor/ios: 3.3.3
  @capacitor/cli: 3.3.3
  @capacitor/core: 3.3.3

[success] iOS looking great! 👌
[success] Android looking great! 👌

Solution

  • First Solution

    In Android Studio, Select File > Project Structure.

    enter image description here

    In that window, on the left side, select the app module. Once selected, click on the Flavors tab on the top of the window pane. Set your minimum SDK version to 21.

    enter image description here

    Explanation: As Android updates to new versions, tools that developers use for Android change (& update or deprecate). Because of this, you cannot use new tools on an old version. Version 1 is the very first Android SDK (and we definitely don't want to be using that!). Capacitor requires the SDK be at least version 21.

    Second Solution

    If that doesn't work, we can always try rebuilding the android app all together. (Note: By doing this, you will lose any custom changes in the AndroidManifest.xml, a custom app icon, etc. If you haven't touched any of these things, then great!).

    1. Delete android folder from the Ionic Project's root folder.
    2. run command ionic capacitor add android
    3. run command ionic capacitor build android
    4. Build & run!