Error in android Building

After updating capacitor, I find this error with my company’s app’s firebase dependancy: FirebaseInstallations.getInstance().getToken(false).addOnSuccessListener(getActivity(), instanceIdResult → {
^
class file for androidx.appcompat.app.AppCompatActivity not found

I tried updating some of the dependancies, but I was not able to figure out what could be wrong here.

Try going through these troubleshooting steps - Troubleshooting Android Issues | Capacitor Documentation

Hey, thanks, it told me to update my Android Gradle Plugin, which I did, but now I’m having an issue in the namespace. I’m new to the forums, would it be better for me to post a new topic? I’m currently looking through other posts so that I can better understand how this place works.

This thread is fine since it is a continuation of your issue :slight_smile:

What version of Capacitor are you running? If the latest v6, I would stick with Gradle 8.2.1.

What is the exact error you are getting?

Namespace not specified. Specify a namespace in the module's build file: /Users/User/DevelopmentApp/mobile_app/node_modules/@capacitor/app/android/build.gradle. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

This is the error I’m recieving at the moment. My build.gradle is formatted like this:

android {
    namespace "namespace.program.app"
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "namespace.program.app"
        namespace "namespace.program.app"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 16
        versionName "1.0.6"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        aaptOptions {
             // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
             // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

I am using latest version Capacitor so I could take advantage of the splash screen capabilities, AGP upgraded me to the latest gradle version and I don’t know how to downgrade if that is the problem.

I don’t believe there should be namespace "namespace.program.app" under defaultConfig.

I saw it in one of the fixes I was looking before I turned up here. Doesn’t seem like changing that worked unfortunately.

The error is pointing to @capacitor/app package, not to your app, did you update the @capacitor plugins you use?

2 Likes

Allright, I filled out the namespace in the files where it directed me. However, at android/capacitor-cordova-android-plugins/build.gradle, whenever I try to npx sync it, the namespace is removed, creating an error when I try to build it.

You have to update to at least Capacitor 5 (while 6 is recommended) and all the other @capacitor packages should match the major version.
Then you won’t run into those problems and won’t need to manually change anything.

Turns out that I didn’t migrate when I should have so the errors regarding namespace not being specified is no longer there, the original error is back unfortunately regarding firebase.

error: cannot access AppCompatActivity
        FirebaseInstallations.getInstance().getToken(false).addOnSuccessListener(getActivity(), instanceIdResult -> {

                                                                                            ^
  class file for androidx.appcompat.app.AppCompatActivity not found

Firebase is implemented like this:

public void getToken(final PluginCall call) {
        FirebaseInstallations.getInstance().getToken(false).addOnSuccessListener(getActivity(), instanceIdResult -> {
            JSObject data = new JSObject();
            data.put("token", instanceIdResult.getToken());
            call.resolve(data);
        });
        FirebaseInstallations.getInstance().getId().addOnFailureListener(e -> call.reject("Failed to get instance FirebaseID", e));
    }

In which Capacitor version were you before updating?
You have to update from version to the next major version following each version upgrade guide.

Or you can go directly to latest version but removing ios/android folders and adding them again with npx cap add so the projects have all the required changes (you will lose any manual changes you’ve made to the native projects)

I was at version 3, but I moved to version six, I made sure to update what was needed to be updated when I upgraded the versions, I’ll double check, but I do believe I followed the version guides.