Capacitor Migration 5.0.0 Failing on Android

I am currently on Capacitor v4.0.0

When I upgrade using the official migration guide, I run into issues on Android.

When I run npx cap migrate, my console shows this:

[error] npm install failed. Try deleting node_modules folder and running npm install --force manually.
✔ Update App Icon to only 1024 x 1024 in 2.50ms
✔ Remove Podfile.lock from iOS .gitignore in 1.46ms
[info] Set com.android.tools.build:gradle = 8.0.0.
[info] Set com.google.gms:google-services = 4.3.15.
✔ Migrating build.gradle file. in 22.38ms
✔ Remove android.enableJetifier=true from gradle.properties in 1.44ms
[error] Unable to update Android Manifest. Missing <activity> tag
✔ Migrating package from Manifest to build.gradle in 2.75ms
✔ Migrating gradle-wrapper.properties by updating gradle version to 8.0.2. in 326.42μs
✔ Migrating variables.gradle file. in 3.55ms
✔ Running cap sync. in 8.55s
✖ Upgrading gradle wrapper files - failed!
[error] gradle wrapper files were not updated
[info] IMPORTANT: Review https://capacitorjs.com/docs/next/updating/5-0#plugins for breaking changes in these plugins
       that you use: @capacitor/camera, @capacitor/local-notifications.
✔ Writing breaking changes. in 2.53ms
[success] Migration to Capacitor 5.0.0 is complete. Run and test your app!

iOS builds ok, but when I open Android Studio I am greeted with this error:

Namespace not specified. Please specify a namespace in the module's build.gradle file like so:

android {
    namespace 'com.example.namespace'
}

If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.

I have tried updating the namespace in the build.gradle with no luck. What am I doing wrong?

please don’t cross-post.

My answer here:

can you share your AndroidManifest.xml?

Here is my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8" ?>
<manifest
  xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.encoded.mogastaxback"
>
    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
  >
        <activity
      android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
      android:name="com.encoded.mogastaxback.MainActivity"
      android:label="@string/title_activity_main"
      android:theme="@style/AppTheme.NoActionBarLaunch"
      android:launchMode="singleTask"
      android:exported="true"
    >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <provider
      android:name="androidx.core.content.FileProvider"
      android:authorities="${applicationId}.fileprovider"
      android:exported="false"
      android:grantUriPermissions="true"
    >
            <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths"
      />
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
</manifest>

This is a bug in the migration command that doesn’t find the package if it’s in a different like than the manifest.

Have you tried using AGP Upgrade Assistant as the error is telling you?

Yes, when I use AGP the namespace error occurs with the build.gradle. I can’t get past that part

That error will also appear if any of your plugins haven’t moved the package to the build.gradle yet.

Is there any fix for that?

Well I am completely stuck. I upgraded Android studio like the migration suggested, now my previous build won’t work, and I can’t upgrade to Capacitor v5. Would anyone be able to hop on a quick call with me?

I have the same same problem.

Capacitor CLI 5.0.2, released yesterday, will patch any plugin that has not done the package migration from AndroidManifest.xml to build.gradle so you don’t need to wait for plugin maintainers to update their plugins.

5 Likes

Great after few file/directory permissions fixing i was able to build

Im on Capacitor 5.0.3 and Capacitor CLI 5.0.3 and gradle 8.0.1. Everything is updated. I’ve removed the build folder. I’m still getting the “Namespace not specified” error. What to do or double check?

Hard to tell without a sample app, @capacitor/cli 5.0.3 should patch any plugin that has not moved their package to the build.gradle, but maybe it’s not a Capacitor plugin what’s causing your issue.
Can you provide your package.json?
Would be better if you create your own forum question

Same setup here. Any advice for getting rid of the “Namespace not specified” error would be appreciated.

Same thing here. Upgraded CLI, built and synced, still not working on Android. It gives the same error.

I have exact same problem, in my case when I update @capacitor/cli to the latest version(don’t know why but it still remained as old version in package.json) and sync gradle => then it resolved.

I had the same issue. This is what I did to solve it:

  1. In my package.json I changed from the dependencies all @capacitor/XXX to the latest version which for now is 5.XX and on devDependencies I changed the @capacitor/cli to the latest version which is 5.5.0 right now.

  2. deleted the android folder

  3. npx cap add android

  4. npx cap open android

gradle build was fine and I can run my app on an android device.

hope this helps

1 Like