0

I am using this site to build a chatapp, just for learning purposes. https://code.tutsplus.com/tutorials/how-to-create-an-android-chat-app-using-firebase--cms-27397

Unfortunately I always end up getting an error. I found this question how to solve Unable to find explicit activity in firebase AuthUi? but none of the answers solved my issue.

This is the error message:

Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp.user.chatatwork/com.firebase.ui.auth.KickoffActivity}; have you declared this activity in your AndroidManifest.xml?

My AndroidManifest.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapp.user.chatatwork">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme"
    android:supportsRtl="true"
    tools:replace="android:value"
    >


    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>

This is my gradle(app)

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-core:10.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.firebaseui:firebase-ui:1.1.1'
    compile 'com.android.support:design:26.0.0'

}

apply plugin: 'com.google.gms.google-services'

EDIT

This is the KickoffActivity class in Firebase:

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public class KickoffActivity extends HelperActivityBase {
    private static final String TAG = "KickoffActivity";
    private static final String IS_WAITING_FOR_PLAY_SERVICES = "is_waiting_for_play_services";
    private static final int RC_PLAY_SERVICES = 1;

    private boolean mIsWaitingForPlayServices = false;

    public static Intent createIntent(Context context, FlowParameters flowParams) {
        return ActivityHelper.createBaseIntent(context, KickoffActivity.class, flowParams);
    }

    @Override
    protected void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);

        if (savedInstance == null || savedInstance.getBoolean(IS_WAITING_FOR_PLAY_SERVICES)) {
            if (isOffline()) {
                Log.d(TAG, "No network connection");
                finish(ErrorCodes.NO_NETWORK,
                       IdpResponse.getErrorCodeIntent(ErrorCodes.NO_NETWORK));
                return;
            }

            boolean isPlayServicesAvailable = PlayServicesHelper.makePlayServicesAvailable(
                    this,
                    RC_PLAY_SERVICES,
                    new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            finish(ResultCodes.CANCELED,
                                   IdpResponse.getErrorCodeIntent(
                                           ErrorCodes.UNKNOWN_ERROR));
                        }
                    });

            if (isPlayServicesAvailable) {
                SignInDelegate.delegate(this, mActivityHelper.getFlowParams());
            } else {
                mIsWaitingForPlayServices = true;
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        // It doesn't matter what we put here, we just don't want outState to be empty
        outState.putBoolean(ExtraConstants.HAS_EXISTING_INSTANCE, true);
        outState.putBoolean(IS_WAITING_FOR_PLAY_SERVICES, mIsWaitingForPlayServices);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_PLAY_SERVICES) {
            if (resultCode == ResultCodes.OK) {
                SignInDelegate.delegate(this, mActivityHelper.getFlowParams());
            } else {
                finish(ResultCodes.CANCELED,
                       IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
            }
        } else {
            SignInDelegate delegate = SignInDelegate.getInstance(this);
            if (delegate != null) delegate.onActivityResult(requestCode, resultCode, data);
        }
    }

    /**
     * Check if there is an active or soon-to-be-active network connection.
     *
     * @return true if there is no network connection, false otherwise.
     */
    private boolean isOffline() {
        ConnectivityManager manager =
                (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        return !(manager != null
                && manager.getActiveNetworkInfo() != null
                && manager.getActiveNetworkInfo().isConnectedOrConnecting());
    }
}
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Blnpwr
  • 1,793
  • 4
  • 22
  • 43

2 Answers2

1

Change this:

implementation 'com.google.firebase:firebase-core:10.0.1'
compile 'com.firebaseui:firebase-ui:1.1.1'

to the latest version:

implementation 'com.firebaseui:firebase-ui-auth:3.3.0'
implementation 'com.firebaseui:firebase-ui-database:3.3.0'
implementation 'com.google.firebase:firebase-core:12.0.1'
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • did you sync ,clean and rebuild? – Peter Haddad Apr 03 '18 at 10:14
  • yes, i did all of these. nothing worked. it says "manifest merger failed" and in the logs, there is the error which i mentioned above. – Blnpwr Apr 03 '18 at 10:16
  • the `kickoffActivity` is a class in the firebase ui auth package, can be found here: https://github.com/firebase/FirebaseUI-Android/blob/master/auth/src/main/java/com/firebase/ui/auth/KickoffActivity.java. Whenever you add a dependency in the gradle file of your project the activities of that library will be added to a manifest file.(Explained more here: https://developer.android.com/studio/build/manifest-merge.html) that is why adding the library in the project manifest wont work, the best bet is to update everything. – Peter Haddad Apr 03 '18 at 10:40
  • @Blnpwr what do you want to use in firebaseui? (auth or database?) The activity is in the firebaseui auth, if you only want to use database then use this `compile 'com.firebaseui:firebase-ui-database:3.3.0'` instead of `compile 'com.firebaseui:firebase-ui:3.3.0'` and you won't get that error – Peter Haddad Apr 03 '18 at 18:03
  • What do you mean by "update everything". In your answer you have the newest version of firebase. Is there anything more to update? I don't get it. – Blnpwr Apr 04 '18 at 05:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168174/discussion-between-peter-haddad-and-blnpwr). – Peter Haddad Apr 04 '18 at 05:54
1

The following error:

Caused by: android.content.ActivityNotFoundException:
Unable to find explicit activity class {com.myapp.user.chatatwork/com.firebase.ui.auth.KickoffActivity};
have you declared this activity in your AndroidManifest.xml?

Tells you exactly what the problem is. You are using an activity, named KickoffActivity that is not declared in the AndroidManifest.xml file. To solve this, please add the following line of code, right after the </activity> tag.

<activity android:name="com.firebase.ui.auth.KickoffActivity"/>

Updating the Firebase and Firebase-UI dependencies to the last version, as Peter mentioned in his answer, it is very good practice.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Please share an [mcve](https://stackoverflow.com/help/mcve) of your `KickoffActivity` class including the `package` name and the changed `AndroidManifest.xml` file. Please edit your question by adding the necessary code. – Alex Mamo Apr 03 '18 at 10:26
  • As far as I understood, this `KickoffActivity` should be added automatically because I am using Firebase, there are a lot of other classes that are implemented automatically when using Firebase. I don't have any KickoffActivity class. – Blnpwr Apr 03 '18 at 10:30
  • If you are using Firebase it doesn't mean that the `KickoffActivity` activity will be added automatically in the `AndroidManifest.xml` file. Yes you have, either this error would not have appeared. Check your `com.firebase.ui.auth` pakage for a KickoffActivity.java file. Can you share its content and the changed `AndroidManifest.xml` file? – Alex Mamo Apr 03 '18 at 10:35
  • I edited the question with the KickoffActivity class, Alex. – Blnpwr Apr 03 '18 at 10:44
  • Because `class KickoffActivity extends HelperActivityBase` it means that the `KickoffActivity` class is an activity. In order to make it work, you need to declare this activity in your `AndroidManifest.xml` file. Have you added this line `` inside the `AndroidManifest.xml` file? Also can you conform that `"com.firebase.ui.auth"` is the right package for the `KickoffActivity.java` file? – Alex Mamo Apr 03 '18 at 10:47
  • Is there everything alright? Have you solved the issue? – Alex Mamo Apr 04 '18 at 07:32
  • Cheers @Blnpwr! – Alex Mamo Apr 04 '18 at 08:12