gpt4 book ai didi

android - 迁移到androidx : Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList后

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:29:07 26 4
gpt4 key购买 nike

如问题标题所示,我已经搜索了我的问题的答案,并找到了 Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx ,这与 Migrating to AndroidX 中提供的官方迁移说明一致.我收到的信息要求我将 android.support.constraint.ConstraintLayout 更改为 androidx.constraintlayout.widget.ConstraintLayout,但这对我不起作用。

我还没有找到关于在我的 gradle 文件中放置什么依赖项的任何信息,所以我尝试了这个(这是在黑暗中拍摄的):

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

这是被接受的,但是当我尝试时:

    implementation 'androidx.constraintlayout.widget:constraintlayout:1.1.3'

我收到ERROR: Failed to resolve: androidx.constraintlayout.widget:constraintlayout:1.1.3,所以我使用了之前的实现指令。

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context="com.example.jbiss.petminder.activities.MainActivity">

<!--<android.support.v7.widget.Toolbar-->
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorPrimaryDark"
android:elevation="4dp"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

<TextView
android:id="@+id/tvMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:accessibilityLiveRegion="assertive"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
tools:text="error message goes here"/>

<TextView
android:id="@+id/tvEmVet"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="@string/emergency_vet"
android:textColor="@android:color/holo_red_dark"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="@+id/phoneCallEmVet"
app:layout_constraintTop_toBottomOf="@+id/recyclerview1"
tools:textSize="24sp"/>

<ImageView
android:id="@+id/phoneCallEmVet"
android:layout_width="37dp"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="8dp"
android:onClick="callEmVet"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerview1"
app:srcCompat="@android:drawable/sym_action_call"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview1"
android:layout_width="368dp"
android:layout_height="365dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/pet_name"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/my_toolbar"/>
</androidx.constraintlayout.widget.ConstraintLayout>

运行我的应用程序会产生以下错误:

2019-02-18 19:43:36.031 458-458/com.example.jbiss.petminder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jbiss.petminder, PID: 458
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.jbiss.petminder-i-ubC_oLu_y7-aFpiqALqg==/base.apk", zip file "/data/app/com.example.jbiss

出于某种原因,无法遵循信息。迁移一直很艰难,但我已经解决了很多问题,现在我无法找到发生这种情况的原因,因为我已经完成了预期的工作。

最佳答案

我解决了我的问题。我发现 Androidx 迁移比我最初想象的要复杂一些。知道我已经更新了初始屏幕中使用的 XML 文件中 ConstraintLayout 元素的标签后,我使用 Windows GREP 在整个项目中搜索“android.support.constraint.ConstraintLayout”。瞧,我发现了我错过的实例,所以我将 XML 文件引用更新为“androidx.constraintlayout.widget.ConstraintLayout”。

这使我的项目得以成功构建并在模拟器上启动。但是,在尝试访问另一个屏幕后,我得到了与我最初的帖子中显示的相同的错误,但对于 AppBarLayout。因此,我必须像对待 ConstraintLayout 和其他任何人一样继续处理这个问题。

如果您正在迁移,请准备好比您预期的多一点的工作!

关于android - 迁移到androidx : Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54757911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com