在Kotlin中配置dataBinding项目无法运行

E/LoadedApk: Unable to instantiate appComponentFactory
    java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/com.gfk.newbie-ST1BhCAkKBtme6Itbi3SEQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.gfk.newbie-ST1BhCAkKBtme6Itbi3SEQ==/lib/arm, /data/app/com.gfk.newbie-ST1BhCAkKBtme6Itbi3SEQ==/base.apk!/lib/armeabi-v7a, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:739)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:818)
        at android.app.LoadedApk.getResources(LoadedApk.java:1041)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2394)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5948)
        at android.app.ActivityThread.access$1300(ActivityThread.java:207)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1758)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6898)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

最近在项目中要用到dataBinding来进行数据绑定,但只要一配置

 dataBinding {
        enabled = true
    }

就会报这样的错,java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList,试了很多办法都不行,最后发现在Java工程环境下不报错,在Kotlin工程环境下就会有问题,于是加上下面这几行代码就解决了

 //在android闭包里面添加支持 java-8
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding {
        enabled = true
    }

 

你可能感兴趣的:(技术,Android,Kotlin,android,安卓,app)