Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Trouble with xamarin android compilation

$
0
0
public class WebviewRendererEX : WebViewRenderer
    {

        Context _context;

        public WebviewRendererEX(Context context) : base(context)
        {
            _context = context;
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                CookieManager cm = CookieManager.Instance;
                cm.SetAcceptCookie(true);
                cm.SetAcceptThirdPartyCookies(Control, true);
                Control.Settings.JavaScriptEnabled = true;
                Control.Settings.DomStorageEnabled = true;
                Control.AddJavascriptInterface(this, "Android");
                Device.BeginInvokeOnMainThread(() =>
                {
                    Control.EvaluateJavascript("function someNavigate(dict){Android.navigateTo(dict);}", null);
                });    
            }
        }
    }
  public class WebViewJavaScriptInterface : Java.Lang.Object
    {

        private Context context;

        /*
         * Need a reference to the context in order to sent a post message
         */
        public WebViewJavaScriptInterface(Context context)
        {
            this.context = context;
        }

        /* 
         * This method can be called from Android. @JavascriptInterface 
         * required after SDK version 17. 
         */

        [Java.Interop.Export("navigateTo")]
        [JavascriptInterface]
        public void NavigateTo(Dictionary<string, object> dict)
        {

            Console.WriteLine(dict);

        }

    }

I have written the above code in webivew

On build, the compiler is throwing the following error:

Error       Failed to create JavaTypeInfo for class: App.Droid.Controls.WebViewJavaScriptInterface due to System.NullReferenceException: Object reference not set to an instance of an object.
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator.Signature..ctor(String name, String signature, String connector, String managedParameters, String outerType, String superCall)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator.Signature..ctor(MethodDefinition method, ExportAttribute export)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator.AddMethod(MethodDefinition registeredMethod, MethodDefinition implementedMethod)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator..ctor(TypeDefinition type, String outerType, Action`2 log)
   at Java.Interop.Tools.JavaCallableWrappers.JavaCallableWrapperGenerator..ctor(TypeDefinition type, Action`2 log)
   at Xamarin.Android.Tasks.Generator.GenerateJavaSource(TaskLoggingHelper log, TypeDefinition t, String outputPath, String applicationJavaClass, Boolean useSharedRuntime, Boolean generateOnCreateOverrides, Boolean hasExportReference)  MGM.Droid           

Obviously I am doing something wrong, but I'm not really clear on what.. Any thoughts?

Thanks In Advance.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>