简体   繁体   English

在 aar 库文件中的布局中获取 inflateException

[英]Getting inflateException at layout inside aar library file

I converted my project into library having included some java, layout, string, resources and menifest file.我将我的项目转换为包含一些 java、布局、字符串、资源和清单文件的库。 Now i want to use that aar file in another project.现在我想在另一个项目中使用该 aar 文件。 After export when i am trying to call activity from aar library I am getting error of Binary XML file line #: Error inflating class.导出后,当我尝试从 aar 库调用活动时,出现二进制 XML 文件行 #: 错误膨胀类的错误。 I used MovableFloatingActionButton custom class and created button in layout inside aar library only.我使用了 MovableFloatingActionButton 自定义类并仅在 aar 库中的布局中创建了按钮。

errors are like错误就像

> Caused by: android.view.InflateException: Binary XML file line #86:
> Error inflating class com.***.****.MovableFloatingActionButton
> 
> Caused by: java.lang.ClassNotFoundException:
> com.***.****.MovableFloatingActionButton
> 
> Caused by: java.lang.NoClassDefFoundError: Failed resolution of:
> Lcom/google/android/material/floatingactionbutton/FloatingActionButton;
> 
> Caused by: java.lang.ClassNotFoundException: Didn't find class
> "com.google.android.material.floatingactionbutton.FloatingActionButton"
> on path: DexPathList[[zip file
> "/data/app/com.***.****-1/base.apk"],nativeLibraryDirectories=[/data/app/com.*****.****-1/lib/arm64,
> /system/lib64, /vendor/lib64]]

It looks like that the classloader didnt find class for to inflate complex view which that class is instantiaded in. The possible problems are:看起来类加载器没有找到用于膨胀该类实例化的复杂视图的类。可能的问题是:

-1- If Your proguard is enabled, try to disable it, and test if the view or layout is inflated. -1- 如果您的 proguard 已启用,请尝试禁用它,并测试视图或布局是否膨胀。 If it works, You need to configure proguard files for.如果有效,您需要为其配置 proguard 文件。

-2- Doublecheck typo mistake and package for inflated class, by clicking on its last part, the simple class name in layout xml file, in you case it should be com.google.android.material.floatingactionbutton. -2- 仔细检查打字错误和膨胀类的包,通过点击它的最后一部分,布局xml文件中的简单类名,在你的情况下它应该是com.google.android.material.floatingactionbutton。 FloatingActionbutton , (hold CTRL key on keyboard and click to bordered part of xml tag) if it opens source file, than it is ok, otherwise class really does not exists and you need to write right class path to instantiate it. FloatingActionbutton ,(按住键盘上的CTRL键并点击xml标签的边框部分)如果它打开源文件,则可以,否则类确实不存在,您需要编写正确的类路径来实例化它。

-3- If You are using multidex, or You want to support pre-art devices, which still use dex and not art (mainly pre-lollipop device) then does not forget to override Application class and use MultidexApplication or include the attachBaseContext() to have the Multidex.install(this) inside body. -3- 如果您正在使用 multidex,或者您想支持仍然使用 dex 而不是艺术的 pre-art 设备(主要是 pre-lollipop 设备),那么不要忘记覆盖 Application 类并使用 MultidexApplication 或包含 attachBaseContext()将 Multidex.install(this) 放入体内。 And do not forget to put the correct path of this class inside your manifest application tag.并且不要忘记将此类的正确路径放在您的清单应用程序标签中。

example:例子:

class MyApplication : Application() {
    /**
     * multidex support, do not remove to backward compatibility before ART (DEX need it)
     * */
    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)

        MultiDex.install(this)
    }
    ...
}

and:和:

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:hardwareAccelerated="true" ... >

One of this should solve Your problem.其中之一应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM