# Android Build fail with Foreign Code

**URL:** <https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308>\
**Category:** How-to Discussions\
**Created:** [March 26, 2016, 8:02pm UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308 "2016-03-26T20:02:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyawlay.it](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kyawlay.it](https://forums.fusetools.com/u/kyawlay.it)\
**Post date:** [March 26, 2016, 8:02pm UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308/1 "2016-03-26T20:02:50Z")

</div>

I created a uno class with foreign code to call phone. I know that Phone.call(PHONE) method can call but it cannot be chosen SIM in dual SIM handsets. so I made my own Phone call class as follow. My problem is I cannot build app for android. I have no idea where is wrong. Please Help me.

```auto
    using Uno;
    using Uno.Collections;
    using Fuse;
    using Fuse.Scripting;
    using Uno.Compiler.ExportTargetInterop;
    using Android.android.app;

    public class InstantCaller : NativeModule
    {
        public InstantCaller()
        {

        AddMember(new NativeFunction("call",
        (NativeCallback)call));
    }
string phNumber;
object call(Context c, object[] args)
{
    //debug_log(args[0].ToString());
    phNumber=args[0] as string;
    debug_log("phone to be called ");
    debug_log(phNumber);
    if(defined(Android)){
       UpdateManager.PostAction(callAndroid);
    }
    else if(defined(IOS)){
        UpdateManager.PostAction(callIOS);
    }
    return null;
}

[Foreign(Language.Java)]
public extern(Android) void callAndroid()
@{
    var ctx = Android.android.app.Activity.GetAppActivity();
    Android.java.lang.String a_ph = phNumber;
    android.content.Intent intent = new android.content.Intent(android.content.Intent.ACTION_CALL, android.net.Uri.parse("tel:"+ android.net.Uri.encode(a_ph)));
    ctx.startActivity(intent);
@}

[Foreign(Language.ObjC)]
public extern(iOS) void callIOS()
@{
   // not implemented yet
@}
}

```

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [March 28, 2016, 10:37pm UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308/2 "2016-03-28T22:37:43Z")

</div>

Hi!

It would be quicker to help if you can provide the error messages you are getting.

---

<div class="post-metadata">

**Author:** ![kyawlay.it](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kyawlay.it](https://forums.fusetools.com/u/kyawlay.it)\
**Post date:** [March 29, 2016, 1:25pm UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308/3 "2016-03-29T13:25:36Z")

</div>

Yes I found that phNumber cannot be accessed from foreign scope ![file](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/sRWNoL4gBu4L-legacy-files-X2vpeAZYUF3Kxily--CvH4jeC1q7HpDk5bTm8ydRU.PNG)

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [April 1, 2016, 9:58am UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308/4 "2016-04-01T09:58:58Z")

</div>

That’s right, you need to pass in all variables you need as arguments

---

<div class="post-metadata">

**Author:** ![kyawlay.it](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kyawlay.it](https://forums.fusetools.com/u/kyawlay.it)\
**Post date:** [April 2, 2016, 9:57pm UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308/5 "2016-04-02T21:57:20Z")

</div>

I’ve read Foreign code tutorials, But I don’t understand what you say. Please let me know how to pass in all variables to foreign code.

---

<div class="post-metadata">

**Author:** ![Baggers](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/baggers/32/665_2.png) [@Baggers](https://forums.fusetools.com/u/Baggers)\
**Post date:** [April 12, 2016, 12:01pm UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308/6 "2016-04-12T12:01:28Z")

</div>

Hi kyawlay,

Sorry for the confusion, fields can be accessed by using the following

```auto
public class NativeTest
{
    public NativeTest()
    {
        DoFieldStuff();
    }

    // static fields
    static int _someField0;
    static Java.Object _someField1;

    // instance fields
    int _someField2;
    Java.Object _someField3;
    Java.Object _someProperty { get; set; }

    [Foreign(Language.Java)]
    public extern(android) void DoFieldStuff()
    @{
        debug_log("--------\nbunch of field accessing\n\n");
        debug_log(@{_someField0});
        debug_log(@{_someField0:Get()});

        debug_log(@{_someField1});
        debug_log(@{_someField1:Get()});

        debug_log(@{NativeTest:Of(_this)._someField2});
        debug_log(@{NativeTest:Of(_this)._someField2:Get()});

        debug_log(@{NativeTest:Of(_this)._someField3});
        debug_log(@{NativeTest:Of(_this)._someField3:Get()});

        debug_log(@{NativeTest:Of(_this)._someProperty:Get()});
        debug_log("---------");
    @}
}

```

Of course it may just be easier to pass them as arguments like this:

```auto
public class NativeTest
{
    public NativeTest()
    {
        DoFieldStuff(_someField0, _someField1);
        DoFieldStuff(_someField2, _someField3);
    }

    // static fields
    static int _someField0;
    static Java.Object _someField1;

    // instance fields
    int _someField2;
    Java.Object _someField3;

    [Foreign(Language.Java)]
    public extern(android) void DoFieldStuff(int a, Java.Object b)
    @{
        debug_log("--------");
        debug_log(a);
        debug_log(b);
        debug_log("---------");
    @}
}

```

---

<div class="post-metadata">

**Author:** ![kyawlay.it](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kyawlay.it](https://forums.fusetools.com/u/kyawlay.it)\
**Post date:** [April 22, 2016, 7:20pm UTC](https://forums.fusetools.com/t/android-build-fail-with-foreign-code/3308/7 "2016-04-22T19:20:49Z")

</div>

Thank you very much for detail explanation
