我正在尝试使用 Firebase 创建登录和注册身份验证,但是当我尝试通过USB调试运行该应用程序时,它将无法启动并继续崩溃,就像我的 AndroidManifest xml 。
这是日志运行:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.firebase.loginauth, PID: 19696
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firebase.loginauth/com.firebase.loginauth.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.AppBarLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2747)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.AppBarLayout
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.design.widget.AppBarLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.AppBarLayout" on path: DexPathList[[zip file "/data/app/com.firebase.loginauth-2/base.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.firebase.loginauth-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.firebase.loginauth-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:74)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.firebase.loginauth.MainActivity.onCreate(MainActivity.java:32)
at android.app.Activity.performCreate(Activity.java:6845)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2700)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
I/Process: Sending signal. PID: 19696 SIG: 9
Application terminated.
这是我的 AndroidManifest
的xml<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firebase.loginauth" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</application>
</manifest>
然后这是我的 activity_main.xml
的示例<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimaryDark"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
答案 0 :(得分:0)
在您的日志中显示该代码无法使AppBarLayout类膨胀
# Binary XML file line #11: Error inflating class android.support.design.widget.AppBarLayout
所以它可能是一个依赖性问题,在根CoordinatorLayout元素中,我看到您正在使用AndroidX,因此请尝试对AppBarLayout使用适当的依赖性
尝试使用:
com.google.android.material.appbar.AppBarLayout
代替
android.support.design.widget.AppBarLayout
,并在您的工具栏上使用:
androidx.appcompat.widget.Toolbar
代替
android.support.v7.widget.Toolbar
P.S:您可以在以下链接的官方文档中查看完整指南: https://developer.android.com/jetpack/androidx/migrate#class_mappings
答案 1 :(得分:0)
您需要使用
<com.google.android.material.appbar.AppBarLayout
<androidx.appcompat.widget.Toolbar
代替
<android.support.design.widget.AppBarLayout
<android.support.v7.widget.Toolbar