如何解决 Unable to find explicit activity in firebase AuthUi?

how to solve Unable to find explicit activity in firebase AuthUi?

在使用 firebase 时 UI 我无法找到明确的 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);
            }
        }
    };
}

完整的错误信息

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

添加了对 app/.gradle 文件

的依赖
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'

还在构建中添加了插件gradle

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

我终于在我的 firebase 控制台项目中添加了 SHA1 指纹。

我需要在清单文件中添加 auth.kickOff activity

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

您需要在 AndroidManifest.xml

中声明 activity

打开清单文件并添加 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>

另外,我不确定你在这里有两次初始 FirebaseApp ..

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

通常在应用中只初始化一次class, 在 onCreate() 方法中。

创建新应用程序class..

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

并在清单中添加相同的内容,

<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>

确保您已在 AndroidManifest.xml 中正确声明 KickoffActivity 作为

    <?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>

特别检查名称属性,如果包中有 activity 则说 "test" 你必须改变 名称属性为

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

如果 AndroidManifest.xml 一切正常, 我建议按照 deividas.

所述更新您的库

您可以在此处查看 FirebaseUI 发行说明https://github.com/firebase/FirebaseUI-Android/releases

还将其他 firebase 库更新为

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

最后我完全重新安装了 android studio 到最新版本,更新了所有内容,包括

  • Google 播放服务
  • firebase 库
  • gradle版本
  • google 存储库

而且我从头开始了新项目并且没有出错。 添加 AUTHUI 依赖项时会自动添加许多活动。 这些 activity 包括 kickoffactivity、recoverpasswordactivity、registerEmailActivity 等 我可以通过转到 path

来验证是否
/project/module/build/intermediates/manifests/full/debug/And‌​roidManifest.xml.

以前我在这个清单文件中没有 kickoffactivity,我不知道原因,但现在我有 it.I 不要考虑在应用程序的清单文件中手动添加它会工作。

手动将 KickoffActivity activity 添加到清单中不是正确的解决方案。它应该为你完成。 如果您手动添加 KickoffActivity,则必须添加另一个 activity 和另一个等等。 我碰巧有:

tools:node="replace">

在我的清单中。这可以防止任何明显的合并。 将其删除后运行良好。

之后您可能会遇到一些其他合并错误,例如重复标签等。 但是错误会有所不同,它会告诉你现在该怎么做。我有一个标签在我的和合并的清单中使用了两次的情况,所以我被告知添加:

tools:replace="android:label"

也解决了这个问题。

在清单文件中添加以下内容:

< activity android :name=" *name of the activity* ">
            < /activity>

以上是清单中默认添加的,但如果没有,请添加。