阅读 118

组件化时library module在使用databinding遇到的两个崩溃

错误1: Failed resolution of: Landroidx/databinding/DataBinderMapperImpl;

解决:主app也需要把dataBinding开关打开

buildFeatures {
    dataBinding = true
}
复制代码

错误2: java.lang.NullPointerException: inflate(layoutInflater) must not be null

为将壳工程与组件进行代码隔离,在壳工程中使用了runtimeOnly来引用组件,将runtimeOnly修改为implementation后代码正常运行,这里也没找到重新代码隔离的方案

详细日志

错误1详细日志:

2020-08-25 12:13:47.289 13810-13810/cn.idu.iwan E/AndroidRuntime: FATAL EXCEPTION: main
    Process: cn.idu.iwan, PID: 13810
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/databinding/DataBinderMapperImpl;
        at androidx.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:32)
        at androidx.databinding.DataBindingUtil.getDefaultComponent(DataBindingUtil.java:65)
        at io.littledou.iwan.login.databinding.ActivityLoginBinding.inflate(ActivityLoginBinding.java:59)
        at io.littledou.iwan.login.LoginActivity.onCreate(LoginActivity.kt:22)
        at android.app.Activity.performCreate(Activity.java:8022)
        at android.app.Activity.performCreate(Activity.java:8006)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7664)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.databinding.DataBinderMapperImpl" on path: DexPathList[[zip file "/data/app/~~T9Jg1HMVJ7LCo-8AIJjtQg==/cn.idu.iwan-F8sMrBbPV_WYp0ER-hmfFQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~T9Jg1HMVJ7LCo-8AIJjtQg==/cn.idu.iwan-F8sMrBbPV_WYp0ER-hmfFQ==/lib/arm64, /system/lib64, /system_ext/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at androidx.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:32) 
        at androidx.databinding.DataBindingUtil.getDefaultComponent(DataBindingUtil.java:65) 
        at io.littledou.iwan.login.databinding.ActivityLoginBinding.inflate(ActivityLoginBinding.java:59) 
        at io.littledou.iwan.login.LoginActivity.onCreate(LoginActivity.kt:22) 
        at android.app.Activity.performCreate(Activity.java:8022) 
        at android.app.Activity.performCreate(Activity.java:8006) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7664) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
2020-08-25 12:13:47.327 13810-13810/cn.idu.iwan I/Process: Sending signal. PID: 13810 SIG: 9

复制代码

错误2详细日志:

2020-08-25 12:10:47.600 13723-13723/cn.idu.iwan E/AndroidRuntime: FATAL EXCEPTION: main
    Process: cn.idu.iwan, PID: 13723
    java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.idu.iwan/io.littledou.iwan.login.LoginActivity}: java.lang.NullPointerException: inflate(layoutInflater) must not be null
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3431)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7664)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.NullPointerException: inflate(layoutInflater) must not be null
        at io.littledou.iwan.login.LoginActivity.onCreate(LoginActivity.kt:22)
        at android.app.Activity.performCreate(Activity.java:8022)
        at android.app.Activity.performCreate(Activity.java:8006)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7664) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
复制代码
文章分类
Android
文章标签