Android build fails string/activity_name not found

My Ionic5 + Capacitor build is failing on android with the error below. If I google I find similar errors that are related to fb_app settings. I think the android project is misconfigured.
Is it this line in the config below:

android:label="@string/activity_name"

What shall I look for to debug this?

android/capacitor-cordova-android-plugins/build/intermediates/library_manifest/debug/AndroidManifest.xml:50:9-56:58: AAPT: error: resource string/activity_name (aka APP_NAME:string/activity_name) not found.

Here is named file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:amazon="http://schemas.amazon.com/apk/res/android"
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="capacitor.android.plugins"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="29" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature android:name="android.hardware.location.gps" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <application>
        <meta-data
            android:name="firebase_analytics_collection_enabled"
            android:value="$ANALYTICS_COLLECTION_ENABLED" />
        <meta-data
            android:name="google_analytics_automatic_screen_reporting_enabled"
            android:value="$AUTOMATIC_SCREEN_REPORTING_ENABLED" />

        <receiver
            android:name="nl.xservices.plugins.ShareChooserPendingIntent"
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
            </intent-filter>
        </receiver>

        <provider
            android:name="nl.xservices.plugins.FileProvider"
            android:authorities="${applicationId}.sharing.provider"
            android:exported="false"
            android:grantUriPermissions="true" >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/sharing_paths" />
        </provider>

        <activity
            android:name="com.keyes.youtube.OpenYouTubePlayerActivity"
            android:screenOrientation="landscape" />
        <activity
            android:name="com.bunkerpalace.cordova.YouTubeActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
            android:label="@string/activity_name"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.Black.NoTitleBar"
            android:windowSoftInputMode="adjustResize" />
    </application>

</manifest>

all works well for iOS btw.

1 Like

Figured it out here after excessive googling…

Your Stack Overflow answer seems to work, but you’re modifying a file that is automatically generated… Subsequent builds and syncs with Capacitor will just revert “app_name” back to “activity_name”. Did you find a solution that doesn’t require manually updating the file after every build?

You should only be running npx cap sync android instead of npx cap add android. Sync will copy your web code over and update any native dependencies. It will not modify your AndroidManifest.xml.

I am running ionic cap sync. One thing to clarify is that the AndroidManifest.xml file that @elduderino15 is referencing is the one located in the capacitor-cordova-android-plugins folder, not the main source folder of the app.

Ah, my mistake. You can use the capacitor sync hooks to fix this then. Make an “after sync” hook to change that value in the AndroidManifest file so everytime after you sync you can automatically rename it. Bit of a weird fix, but it’s due to how our Cordova compatibility layer works and should unblock you immediately :+1:

1 Like

Hi Thomas, what you described saying “after sync” didn’t really make much sense to me. However, after some digging, I found out what you meant.

If it helps anyone else, have a look here for the hooks documentation here. Capacitor - build cross platform apps with the web

But, this recent post helped me to figure out more about how to solve the problem.

I’ve also published my ‘npx cap sync’ after file too.

Cheers.