web-dev-qa-db-ja.com

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

ビルドグラドル:

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>
4
hassan abbasi

アクティビティとフラグメントで、インポートセクションの古いサポートライブラリへの参照がないことを確認してください。すべてのレイアウトがolsサポートウィジェットも使用していないことを確認してください。

1
GotaloveCode

アプリがandroidxライブラリではなくサポートライブラリからAndroid.support.design.widget.CoordinatorLayoutを拡張しようとしているようです。以下のことを試して、それが機能するかどうかを確認してください。

  • アプリをclean and buildしてください。
  • Invalidate Cache and Restartをお試しください。

また、サポートライブラリのコーディネーターレイアウトを他の場所で使用していないことを確認してください。

1
karan

すべてを置き換える必要がありますAndroid.support.designAndroidXの新しいクラスを持つクラス。古いクラスと新しいクラスの対応のリンクは次のとおりです。

さらに詳しくAndroidXへの移行方法のガイドを読むことができます:

0
Eraldo

これらの2行をgradle.propertiesファイルに追加して、既存のプロジェクトをAndroixに自動的に移行します。

Android.useAndroidX=true
Android.enableJetifier=true

詳細はこちら-> https://developer.Android.com/jetpack/androidx/migrate

これは自動的にあなたの問題を解決します。

0
Jay Dangar

単にXMLファイル( `res/layout)に移動して、

androidx.appcompat.widget.RecyclerView

と:

androidx.recyclerview.widget.RecyclerView
0
Muhammad Nauman