Forum Xamarin.Android

No success binding android-filechooser library

Hi,
I would like to integrate a file chooser in my Xamarin.Android app. I have added some bindings to other libraries in the past, but this time I haven't been successful yet. Maybe someone can help?

The android-filechooser library requires the android-support-v7-appcompat library which seems to cause the trouble I'm experiencing.

This is what I have done:
(you can download the results from https://github.com/PhilippC/MonoFileChooser)

  • downloaded android-filechooser from https://code.google.com/p/android-filechooser/
  • imported and built app-compat-v7 project from Android SDK to Eclipse
  • added app-compat-v7 as reference to android-filechooser library
  • added a simple class Kp2aFileChooserBridge (file attached to this post) to android-filechooser: If possible, I only want to have bindings for this class (to reduce apk size)
  • created an application project in Eclipse to verify everything's working
  • created project.zip files from both the android-filechooser library and the app-compat-v7 library
  • created a Xamarin.Android project in VS2012
  • added a Java Library project with the project.zip for android-filechooser
  • when building, received NoClassDefFound errors for classes from the app-compat-v7
  • -> added android-support-v7-appcompat.jar and android-support-v4.jar as ReferenceJar to the bindings library
  • when building, the following errors occured:
    1>\repo\MonoFileChooser\AndroidFileChooserBinding\obj\Debug\generated\src\Group.Pals.Android.Lib.UI.Filechooser.Providers.Localfile.FileObserverEx.cs(69,24,69,31): error CS0115: 'Group.Pals.Android.Lib.UI.Filechooser.Providers.Localfile.FileObserverEx.OnEvent(int, string)': Es wurde keine passende Methode zum Überschreiben gefunden. (Translation: No matching method for overriding was found)
    1>\repo\MonoFileChooser\AndroidFileChooserBinding\obj\Debug\generated\src\Group.Pals.Android.Lib.UI.Filechooser.Providers.Localfile.FileObserverEx.cs(9,23,9,37): error CS0534: 'Group.Pals.Android.Lib.UI.Filechooser.Providers.Localfile.FileObserverEx' implementiert den geerbten abstrakten Member 'Android.OS.FileObserver.OnEvent(Android.OS.FileObserverEvents, string)' nicht. (Translation: FileObserveEx doesn't implement inherited abstract member OnEvent())

  • as I don't need bindings for this class, added

    to Metedata.xml

  • building is now succesful, but with the following warnings:
    1>BINDINGSGENERATOR : warning BG8604: top ancestor FileObserverEx not found for nested type Group.Pals.Android.Lib.UI.Filechooser.Providers.Localfile.FileObserverEx.1
    1>BINDINGSGENERATOR : warning BG8102: Class Group.Pals.Android.Lib.UI.Filechooser.BaseFileAdapter has unknown base type android.support.v4.widget.ResourceCursorAdapter
    1>BINDINGSGENERATOR : warning BG8102: Class Group.Pals.Android.Lib.UI.Filechooser.FileChooserActivity has unknown base type android.support.v4.app.FragmentActivity
    1>BINDINGSGENERATOR : warning BG8102: Class Group.Pals.Android.Lib.UI.Filechooser.FileChooserActivity_v7 has unknown base type android.support.v7.app.ActionBarActivity
    1>BINDINGSGENERATOR : warning BG8102: Class Group.Pals.Android.Lib.UI.Filechooser.FragmentFiles has unknown base type android.support.v4.app.Fragment
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.prefs.Prefs: FxDG naming violation: Type name 'Prefs' matches namespace part 'Prefs'.
    1>BINDINGSGENERATOR : warning BG8700: Unknown return type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8700: Unknown return type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8700: Unknown return type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8700: Unknown return type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8700: Unknown return type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8700: Unknown return type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8700: Unknown return type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Xml.XmlReader
    1>BINDINGSGENERATOR : warning BG8701: Invalid return type group.pals.android.lib.ui.filechooser.FileChooserActivity.ViewType
    1>BINDINGSGENERATOR : warning BG8801: Invalid parameter type group.pals.android.lib.ui.filechooser.FileChooserActivity.ViewType
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.utils.Utils: FxDG naming violation: Type name 'Utils' matches namespace part 'Utils'.
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.utils.history.History: FxDG naming violation: Type name 'History' matches namespace part 'History'.
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.utils.ui.Ui: FxDG naming violation: Type name 'Ui' matches namespace part 'UI'.
    1>BINDINGSGENERATOR : warning BG8102: Class Group.Pals.Android.Lib.UI.Filechooser.Utils.UI.Bookmark.BookmarkFragment has unknown base type android.support.v4.app.DialogFragment
    1>BINDINGSGENERATOR : warning BG8102: Class Group.Pals.Android.Lib.UI.Filechooser.Utils.UI.History.HistoryFragment has unknown base type android.support.v4.app.DialogFragment
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.prefs.Prefs: FxDG naming violation: Type name 'Prefs' matches namespace part 'Prefs'.
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.utils.Utils: FxDG naming violation: Type name 'Utils' matches namespace part 'Utils'.
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.utils.history.History: FxDG naming violation: Type name 'History' matches namespace part 'History'.
    1>BINDINGSGENERATOR : warning BG8900: Type group.pals.android.lib.ui.filechooser.utils.ui.Ui: FxDG naming violation: Type name 'Ui' matches namespace part 'UI'.

  • I'm not sure how to interpret these warnings and try to proceed

  • added a Java Bindings Library for the app-compat-v7 project
  • built the Java Bindings Library resulting in
    1>BINDINGSGENERATOR : warning BG8601: No packages found.

  • created Mono for Android App

  • added reference to v4-support-lib
  • changed "Compile with" and "Target" SDK Versions from 8 to 14
  • app builds without warnings or errors
  • added





    to Properties\AndroidManifest.xml

  • in the Activity1 button.Click handler, added
    Intent i = Keepass2android.Kp2afilechooser.Kp2aFileChooserBridge.GetLaunchFileChooserIntent(this);
    StartActivityForResult(i, 0);

  • deployed app to device

  • clicking the button crashes the app with
    09-22 06:44:52.015 W/dalvikvm( 2936): Unable to resolve superclass of Lgroup/pals/android/lib/ui/filechooser/FileChooserActivity_v7; (594)
    09-22 06:44:52.015 W/dalvikvm( 2936): Link of class 'Lgroup/pals/android/lib/ui/filechooser/FileChooserActivity_v7;' failed
    09-22 06:44:52.015 E/dalvikvm( 2936): Could not find class 'group.pals.android.lib.ui.filechooser.FileChooserActivity_v7', referenced from method keepass2android.kp2afilechooser.Kp2aFileChooserBridge.getLaunchFileChooserIntent
    09-22 06:44:52.015 W/dalvikvm( 2936): VFY: unable to resolve const-class 806 (Lgroup/pals/android/lib/ui/filechooser/FileChooserActivity_v7;) in Lkeepass2android/kp2afilechooser/Kp2aFileChooserBridge;
    09-22 06:44:52.015 D/dalvikvm( 2936): VFY: replacing opcode 0x1c at 0x0028

  • changed BuildType of android-support-v7-appcompat.jar to EmbeddedReferenceJar

  • rebuild, redeployed, same effect

Of course my main question is: what can I do to make this work on runtime?
If that's solved, I'd also be interested in reducing apk size by generating less bindings. What's a good way to do this?

Thanks for any assistance!

Philipp

Posts

  • attaching the file didn't work. Here is its content:

    package keepass2android.kp2afilechooser;

    import group.pals.android.lib.ui.filechooser.FileChooserActivity;
    import group.pals.android.lib.ui.filechooser.FileChooserActivity_v7;
    import group.pals.android.lib.ui.filechooser.providers.basefile.BaseFileContract.BaseFile;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Build;

    public class Kp2aFileChooserBridge {
    public static Intent getLaunchFileChooserIntent(Context ctx)
    {
    Class<?> cls;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ECLAIR_MR1)
    cls = FileChooserActivity.class;
    else
    cls = FileChooserActivity_v7.class;
    Intent intent = new Intent(ctx, cls);
    /*
    * By default, if not specified, default rootpath is SD card,
    * if SD card is not available, "/" will be used.
    */
    intent.putExtra(FileChooserActivity.EXTRA_ROOTPATH,
    BaseFile.genContentIdUriBase(Kp2aFileProvider.getAuthority(ctx))
    .buildUpon()
    .appendPath("file://test/")
    .build());
    return intent;
    }
    }

Sign In or Register to comment.