迁移到androidx后错误放大类

时间:2019-01-23 06:40:14

标签: android androidx

我迁移到Androidx,但迁移后出现以下错误:

 Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
 Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout

我研究了所有资源并迁移到Androidx,但是仍然存在很多问题。 有人能帮我吗? 我将在下面的代码部分中发布。

---------崩溃开始---------

2019-01-23 09:47:34.171 17578-17578/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ir.bijac.com.bijac, PID: 17578
    java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.bijac.com.bijac/ir.bijac.com.bijac.TestActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
     Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:645)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        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 ir.bijac.com.bijac.BaseActivity.onCreate(BaseActivity.java:43)
        at ir.bijac.com.bijac.TestActivity.onCreate(TestActivity.java:22)
        at android.app.Activity.performCreate(Activity.java:6679)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/coreui/R$attr;
        at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:202)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:854) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
        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 ir.bijac.com.bijac.BaseActivity.onCreate(BaseActivity.java:43) 
        at ir.bijac.com.bijac.TestActivity.onCreate(TestActivity.java:22) 
        at android.app.Activity.performCreate(Activity.java:6679) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
2019-01-23 09:47:34.171 17578-17578/? E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.coreui.R$attr" on path: DexPathList[[zip file "/data/app/ir.bijac.com.bijac-2/base.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_dependencies_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_0_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_1_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_2_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_3_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_4_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_5_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_6_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_7_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_8_apk.apk", zip file "/data/app/ir.bijac.com.bijac-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/ir.bijac.com.bijac-2/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 27 more

构建gradle:

apply plugin: 'com.android.application'
repositories {
    mavenCentral()
}

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 28
    defaultConfig {
        applicationId "ir.bijac.com.bijac"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestUtil 'androidx.test:orchestrator:1.1.1'
    configurations.all { resolutionStrategy.force 'com.android.support:support-v4:28.0.0' }
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation "cz.msebera.android:httpclient:4.4.1.2"
    implementation 'org.apache.httpcomponents:httpcore:4.4.10'
    implementation 'com.androidadvance:topsnackbar:1.1.1'
    implementation 'co.ronash.android:pushe-base:1.4.1'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true;
    }

}

--------- 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:openDrawer="start"
    >

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

8 个答案:

答案 0 :(得分:2)

在XML文件中,替换 androidx.appcompat.widget.RecyclerView 与: androidx.recyclerview.widget.RecyclerView

答案 1 :(得分:1)

确保在您的活动和片段中没有在导入部分中引用旧的支持库。确保所有布局也都没有使用ols支持小部件。

答案 2 :(得分:0)

应用似乎正在尝试从支持库(而非androidx库)中充实android.support.design.widget.CoordinatorLayout。尝试执行以下操作,并检查其是否有效。

  • 执行clean and build您的应用。
  • 尝试Invalidate Cache and Restart

还要确保您没有在其他任何地方使用支持库中的协调器布局。

答案 3 :(得分:0)

在gradle.properties文件中添加这两行,以自动将现有项目迁移到Androix。

android.useAndroidX=true
android.enableJetifier=true

更多信息在这里-> https://developer.android.com/jetpack/androidx/migrate

这将自动解决您的问题。

答案 4 :(得分:0)

您可能会在某些xml布局文件中引用android.support.design.widget.CoordinatorLayout。

按[CTRL] + [SHIFT] + [F]或转到编辑/查找/在路径中查找,然后仅搜索“ android.support.design.widget.CoordinatorLayout”并将其替换带有“ androidx.coordinatorlayout.widget.CoordinatorLayout”。

您可以使用[CTRL] + [SHIFT] + [R] 或在路径中编辑/查找/替换来立即替换所有匹配项。

答案 5 :(得分:0)

只需转到XML文件(在`res / layout中)并替换

androidx.appcompat.widget.RecyclerView

具有:

androidx.recyclerview.widget.RecyclerView

答案 6 :(得分:0)

您必须将所有android.support.design类替换为 AndroidX 的新类。这是新旧类之间的对应关系的链接:

更多信息,您可以阅读指南,了解如何迁移到 AndroidX

答案 7 :(得分:0)

编辑->查找->在路径中查找 全部替换以下

  • (.) msum (map return) -> android.support.v7.widget.CardView

  • androidx.cardview.widget.CardView -> android.support.design.widget.TextInputLayout

  • com.google.android.material.textfield.TextInputLayout -> android.support.v4.widget.NestedScrollView

  • androidx.core.widget.NestedScrollView -> android.support.v4.view.ViewPager

  • androidx.viewpager.widget.ViewPager -> androidx.constraintlayout.ConstraintLayout

  • androidx.constraintlayout.widget.ConstraintLayout -> androidx.core.view.ViewPager

  • androidx.viewpager.widget.ViewPager -> androidx.core.widget.SwipeRefreshLayout

  • androidx.swiperefreshlayout.widget.SwipeRefreshLayout -> android.support.design.widget.AppBarLayout

  • com.google.android.material.appbar.AppBarLayout -> android.support.design.widget.CollapsingToolbarLayout

  • com.google.android.material.appbar.CollapsingToolbarLayout -> android.support.v7.widget.Toolbar