Forum Xamarin.Android

Struggling to get a Binding to a Jar working

Hi all,
I am just getting started with Xamarin, so I am doing a test project. Our work requires doing binding on Android and iOS. I made a very simple jar file to bind. It contains one simple class:

package com.dshaw;
import java.util.Date;

class TimeTest
{

    public static String getTimeStatic()
    {
        return new Date().toString();
    }

    public String getTime()
    {
        return new Date().toString();
    }


    public static void main(String[] args)
    {
        TimeTest t = new TimeTest();
        System.out.println(t.getTime());
    }
}

The binding appears to work. There are some DLLs output when I build:

./TimeTestAndroidBinding/Droid/bin/Debug/TimeTestAndroidBinding.dll
./TimeTestAndroidBinding/Droid/obj/Debug/assemblies/TimeTestAndroidBinding.dll
./TimeTestAndroidBinding/TimeTestAndroidBinding/bin/Debug/TimeTestAndroidBinding.dll
./TimeTestAndroidBinding/TimeTestAndroidBinding/obj/Debug/TimeTestAndroidBinding.dll

With that said, when I try to use this inside the MainActivity.cs file it fails. The code on Android is:

using Android.App;
using Android.Widget;
using Android.OS;
using System.Collections;
using System.Collections.Generic;
using Com.Dshaw;

namespace ConsumeTimeTest.Droid
{
    [Activity (Label = "ConsumeTimeTest", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity
    {
        int count = 1;

        protected override void OnCreate (Bundle savedInstanceState)
        {
            Xamarin.Insights.Initialize (XamarinInsights.ApiKey, this);
            base.OnCreate (savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);
            // this isn't working, package not resolving
            TimeTest tt = TimeTest ();

        }
    }
}

The error is: The type or namespace name 'Com' could not be found. Are you missing an assembly reference?

Any help is appreciated!

Tagged:

Best Answer

Answers

Sign In or Register to comment.