how to solve Unable to find explicit activity in f

2019-04-24 02:03发布

问题:

While working with firebase UI I am getting Unable to find explicit activity class com.firebase.ui.auth.KickoffActivity

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FirebaseApp.initializeApp(this);
    setContentView(R.layout.activity_main);
    FirebaseApp.initializeApp(this);
    mAuth=FirebaseAuth.getInstance();
    mAuthListner=new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user=firebaseAuth.getCurrentUser();
            if(user!=null){
                Toast.makeText(getApplicationContext(),"Sign in success",Toast.LENGTH_SHORT).show();

            }
            else {
                startActivityForResult(AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setIsSmartLockEnabled(false)
                        .setProviders(AuthUI.EMAIL_PROVIDER,AuthUI.GOOGLE_PROVIDER).build(),
                        RC_SIGN_IN);
            }
        }
    };
}

Full error message

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flamanco.trackme/com.firebase.ui.auth.KickoffActivity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult

Added dependencies on app/.gradle file

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.firebaseui:firebase-ui-auth:1.1.1'
}

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

also added plugin in build gradle

classpath 'com.google.gms:google-services:3.0.0'

Finally I did added SHA1 fingerprint in my firebase console project.

Do I need to add auth.kickOff activity in manifest file

回答1:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flamanco.trackme/com.firebase.ui.auth.KickoffActivity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult

You need to declare the activity in the AndroidManifest.xml

Open your manifest file and add the KicoffActivity.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="auto">
<activity
            android:name="KickoffActivity"/>
</manifest>

Also, I am not sure you have initial FirebaseApp twice here..

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FirebaseApp.initializeApp(this);
    setContentView(R.layout.activity_main);
    FirebaseApp.initializeApp(this);
}

Usually it should be initialized only once in the application class, in onCreate() method.

Create a new application class..

public class YourApplicationClass extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseApp.initializeApp(this);
    }
}

And add the same in the manifest,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:installLocation="auto">
<application
        android:name="YourApplicationClass"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/MyMaterialTheme.Base">
       <activity
        android:name="KickoffActivity"/>
</application>
</manifest>


回答2:

Manually adding the KickoffActivity activity to the manifest is not the right solution. It should be done for you. If you manually add the KickoffActivity, you will then have to add another activity and another one and so on. I happened to have:

tools:node="replace">

In my manifest. Which prevents any manifest merging. Removed it and it worked fine since.

After that you might get some other merging errors like duplicate tags etc.. But the error will be different and will tell you what to do now. I had a case of a tag used twice in my and in a merged manifest so I was told to add:

tools:replace="android:label"

Which fixed that too.



回答3:

Make sure your have declared your KickoffActivity properly in AndroidManifest.xml as

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.xxx.xxx">
<application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity android:name=".KickoffActivity">
        </activity>
    </application>

</manifest>

Especially check the name attribute, if you have activity in package say "test" then you'll have to change the name attribute as

<activity android:name=".test.KickoffActivity">
            </activity>

If everything fine with AndroidManifest.xml, I would suggest to update your libraries as mentioned by deividas.

You can check the FirebaseUI release notes here https://github.com/firebase/FirebaseUI-Android/releases

Also update other firebase libraries to

 compile 'com.google.firebase:firebase-core:11.0.4' 
 compile 'com.google.firebase:firebase-auth:11.0.4'


回答4:

Finally I have completely reinstall android studio to latest version, updated everything including

  • Google play service
  • firebase libraries
  • gradle version
  • google repositoris

And I started new project from begining and worked with no error. there are many activities that are added automatically on adding AUTHUI dependencies. these activity includes kickoffactivity,recoverpasswordactivity,registerEmailActivity,etc I can verify if by going to path

/project/module/build/intermediates/manifests/full/debug/And‌​roidManifest.xml.

previously i don't have kickoffactivity in this manifest file, I don't know the reason,but now i have it.I don't think adding it manually on app's manifest file will work.