如何从AAR绑定库中扩充UI控件?

时间:2017-04-15 16:18:11

标签: xamarin.android aar

我根据these instructions从.AAR lib创建了一个AAR Bingind库。 它包含一个自定义UI控件。

当我尝试给控件充气时:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:multi="clr-namespace:PL.Openrnd.Multilevellistview;assembly=MultiLevelListAarBinding"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <multi:MultiLevelListView
      android:id="@+id/listView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:alwaysExtended="false"
      app:nestType="multiple">
  </multi:MultiLevelListView >
</LinearLayout> 

我收到此错误:

    04-15 18:09:53.191: E/AndroidRuntime(19635): FATAL EXCEPTION: main
    04-15 18:09:53.191: E/AndroidRuntime(19635): Process: DroidApp1.DroidApp1, PID: 19635
    04-15 18:09:53.191: E/AndroidRuntime(19635): java.lang.RuntimeException: Unable to start activity ComponentInfo{DroidApp1.DroidApp1/md5bb1ba76b602cc549b908ee4ab65f64d1.MainActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class MultiLevelListView
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.os.Handler.dispatchMessage(Handler.java:102)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.os.Looper.loop(Looper.java:148)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.ActivityThread.main(ActivityThread.java:5417)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at java.lang.reflect.Method.invoke(Native Method)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    04-15 18:09:53.191: E/AndroidRuntime(19635): Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class MultiLevelListView
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.Activity.setContentView(Activity.java:2172)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at md5bb1ba76b602cc549b908ee4ab65f64d1.MainActivity.n_onCreate(Native Method)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at md5bb1ba76b602cc549b908ee4ab65f64d1.MainActivity.onCreate(MainActivity.java:29)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.Activity.performCreate(Activity.java:6251)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    ... 9 more
    04-15 18:09:53.191: E/AndroidRuntime(19635): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class MultiLevelListView
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    ... 18 more
    04-15 18:09:53.191: E/AndroidRuntime(19635): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.MultiLevelListView" on path: DexPathList[[zip file "/data/app/DroidApp1.DroidApp1-1/base.apk"],nativeLibraryDirectories=[/data/app/DroidApp1.DroidApp1-1/lib/arm, /data/app/DroidApp1.DroidApp1-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.createView(LayoutInflater.java:583)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:677)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
    04-15 18:09:53.191: E/AndroidRuntime(19635):    ... 22 more
    04-15 18:09:53.191: E/AndroidRuntime(19635):    Suppressed: java.lang.ClassNotFoundException: android.view.MultiLevelListView
    04-15 18:09:53.191: E/AndroidRuntime(19635):        at java.lang.Class.classForName(Native Method)
    04-15 18:09:53.191: E/AndroidRuntime(19635):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    04-15 18:09:53.191: E/AndroidRuntime(19635):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    04-15 18:09:53.191: E/AndroidRuntime(19635):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    04-15 18:09:53.191: E/AndroidRuntime(19635):        ... 28 more
    04-15 18:09:53.191: E/AndroidRuntime(19635):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

我也尝试了完整的命名空间:

  <PL.Openrnd.Multilevellistview.MultiLevelListView...

但这也不起作用。

我错过了什么?有没有其他东西需要引用本机Java控件?

1 个答案:

答案 0 :(得分:0)

事实证明,必须小写名称空间。

 <pl.openrnd.multilevellistview.MultiLevelListView...