Topic
17 replies Latest Post - ‏2012-08-09T16:58:11Z by DG1M_Harry_Ho
venkatakrishnarao
venkatakrishnarao
16 Posts
ACCEPTED ANSWER

Pinned topic worklight emulator problem

‏2012-08-08T11:00:10Z |
Hi All,

I created a worklight project with use of http adapter. It is
working fine when I am running this app on the browser.But when I am
running this application as android app in emulator it always calling
the failure funtion in the user js file. I'm specifying code for corresponding js file. can you please resolve this issue.
// Worklight comes with the jQuery framework bundled inside. If you do not want to use it, please comment out the line below.
window.$ = WLJQ;

function wlCommonInit(){
// Common initialization code goes here
}
function add()
{
var n1 = document.getElementById("n1").value;
var n2 = document.getElementById("n2").value;
var invocationData = {
adapter : 'CalculatorAdapter',
procedure : 'addTwoIntegers',
parameters : n1,n2
};
var options = {
onSuccess : onSuccessAdd,
onFailure : onFailure
};
WL.Client.invokeProcedure(invocationData, options);
}

function subtract()
{
var num1 = document.getElementById("n1").value;
var num2 = document.getElementById("n2").value;
var invocationData = {
adapter : 'CalculatorAdapter',
procedure : 'subtractTwoIntegers',
parameters : num1,num2
};
var options =
{
onSuccess : onSuccessSub,
onFailure : onFailure
};
WL.Client.invokeProcedure(invocationData, options);
}

function onSuccessAdd(result)
{
alert("in success");
document.getElementById("res").innerHTML = "Result is:"result.invocationResult.result"



";
}

function onSuccessSub(result)
{
alert("in success");
alert("result"+result.invocationResult.isSuccessful);
document.getElementById("res").innerHTML = "

Result is:"result.invocationResult.result"



";
}

function onFailure(result)
{
alert("Arithmetic operation failed");

alert("result"+result.invocationResult.isSuccessful);
alert("errors"+result.invocationResult.errors);
}
  • DG1M_Harry_Ho
    DG1M_Harry_Ho
    49 Posts
    ACCEPTED ANSWER

    Re: worklight emulator problem

    ‏2012-08-08T13:38:13Z  in response to venkatakrishnarao
    Try to put your parameters in brackets.

    So your

    var invocationData =
    {
    adapter : 'CalculatorAdapter',
    procedure : 'addTwoIntegers',
    parameters : n1,n2
    };

    should be

    var invocationData =
    {
    adapter: 'CalculatorAdapter',
    procedure: 'addTwoIntegers',
    parameters: n1, n2
    };

    I'll keep looking into it as well. What function did you call originially, and did you set up any debugging with the wl logger?
    • venkatakrishnarao
      venkatakrishnarao
      16 Posts
      ACCEPTED ANSWER

      Re: worklight emulator problem

      ‏2012-08-08T13:59:07Z  in response to DG1M_Harry_Ho
      Hi Harry,

      Thanx for your responce.I'l attach entire project in this mail. Just look into it.
    • venkatakrishnarao
      venkatakrishnarao
      16 Posts
      ACCEPTED ANSWER

      Re: worklight emulator problem

      ‏2012-08-08T14:01:27Z  in response to DG1M_Harry_Ho
      Hi Harry,

      Thanx for your responce.I'l attach entire project in this mail. Just look into it.
      • DG1M_Harry_Ho
        DG1M_Harry_Ho
        49 Posts
        ACCEPTED ANSWER

        Re: worklight emulator problem

        ‏2012-08-08T15:13:11Z  in response to venkatakrishnarao
        It isn't connecting to the worklight server. This is actually something I have been having issues with as of late. The emulators seem to have some trouble connecting to the server. I changed to the connectionOnStartup to true and it won't even connect initially.

        You can also see in logcat that it has issues connecting.

        The reason the operation fails is because it isn't even hitting the server to hit the adapter. I am working on a way to get the emulator to do so. I haven't found much help on external forums about it quite yet.

        I'll try to find a solution to cut through it.
        • DG1M_Harry_Ho
          DG1M_Harry_Ho
          49 Posts
          ACCEPTED ANSWER

          Re: worklight emulator problem

          ‏2012-08-08T15:16:33Z  in response to DG1M_Harry_Ho
          Also, in your appDesc the worklight server root is set to local, which actually points to the emulator. Use the ip of your machine-server. This is technically supposed to work, but I am still having issues.
          • venkatakrishnarao
            venkatakrishnarao
            16 Posts
            ACCEPTED ANSWER

            Re: worklight emulator problem

            ‏2012-08-08T15:30:01Z  in response to DG1M_Harry_Ho
            Thank you Harry.

            I tried as you said but still i'm getting the same issue. What to do now for hiiting the request to server and then to the emulator..?
            • venkatakrishnarao
              venkatakrishnarao
              16 Posts
              ACCEPTED ANSWER

              Re: worklight emulator problem

              ‏2012-08-08T16:16:16Z  in response to venkatakrishnarao
              Harry,

              I'm also getting a message in console like "could not get wglGetExtensionsStringARB" when i'm running that application on the emulator.
              • DG1M_Harry_Ho
                DG1M_Harry_Ho
                49 Posts
                ACCEPTED ANSWER

                Re: worklight emulator problem

                ‏2012-08-08T16:36:13Z  in response to venkatakrishnarao
                I tested the app on my phone after the ip address changes, and it works fine. It is definitely an issue with how the emulator is connecting to the server. I have read alot about this issue, but so far I haven't found a fix.
                • venkatakrishnarao
                  venkatakrishnarao
                  16 Posts
                  ACCEPTED ANSWER

                  Re: worklight emulator problem

                  ‏2012-08-08T16:45:27Z  in response to DG1M_Harry_Ho
                  Hi Harry,

                  Thankyou for ur responce. I want some documents and links regarding worklight. Could you please forward some docs and links. If possible your mail id also.
                  • DG1M_Harry_Ho
                    DG1M_Harry_Ho
                    49 Posts
                    ACCEPTED ANSWER

                    Re: worklight emulator problem

                    ‏2012-08-08T18:21:54Z  in response to venkatakrishnarao
                    Some documentation is here:

                    http://www-01.ibm.com/software/mobile-solutions/worklight/library/

                    I was able to get it working by using a 4.1 emulator, changing the IP address to the 10.0.2.2:8080.

                    Running the 4.1 emulator ran it fine. However, I still have issues with 2.3 emus. I was able to do the 4.1 emulator with the app on 2 different machines (1 mac, 1 windows).
                    • venkatakrishnarao
                      venkatakrishnarao
                      16 Posts
                      ACCEPTED ANSWER

                      Re: worklight emulator problem

                      ‏2012-08-09T13:44:29Z  in response to DG1M_Harry_Ho
                      Harry,

                      I'm also using the emulator4.1 only but still its calling failure function only.
                      • DG1M_Harry_Ho
                        DG1M_Harry_Ho
                        49 Posts
                        ACCEPTED ANSWER

                        Re: worklight emulator problem

                        ‏2012-08-09T15:29:37Z  in response to venkatakrishnarao
                        Could you send me an updated version of your project?
                        • venkatakrishnarao
                          venkatakrishnarao
                          16 Posts
                          ACCEPTED ANSWER

                          Re: worklight emulator problem

                          ‏2012-08-09T15:40:38Z  in response to DG1M_Harry_Ho
                          I didn't changed anything except the ip address in app-desc.xml file. download the attached project.
                          • DG1M_Harry_Ho
                            DG1M_Harry_Ho
                            49 Posts
                            ACCEPTED ANSWER

                            Re: worklight emulator problem

                            ‏2012-08-09T16:19:02Z  in response to venkatakrishnarao
                            I isolated an issue and I tried it both ways on both computers. I forgot that I had changed the SDK to a lower version yesterday because I typically run things on my 2.3 emulators. When those weren't working due to the bug issue that Idan was talking about, I used the 4.1 emulate.

                            You have the minimum and target SDK set to 16. Which is pretty much only phones with the newer android OS.

                            Go into your Android folder in the app's folder and navigate to AndroidManifest.xml and project.properties.

                            Change the Minimum and target SDK's to 10 (so they can work on 2.3 devices as well).

                            You can even change the IP address in the app desc to the external one. As long as it isn't pointing locally, it can be the 10.0.2.2 or the ip of your machine with the right port. Hope this works.
                            • venkatakrishnarao
                              venkatakrishnarao
                              16 Posts
                              ACCEPTED ANSWER

                              Re: worklight emulator problem

                              ‏2012-08-09T16:54:30Z  in response to DG1M_Harry_Ho
                              ThanQ Harry. Its working fine. And I've another query regarding android apk file that in which folder the .apk file exists?
                              • DG1M_Harry_Ho
                                DG1M_Harry_Ho
                                49 Posts
                                ACCEPTED ANSWER

                                Re: worklight emulator problem

                                ‏2012-08-09T16:58:11Z  in response to venkatakrishnarao
                                There is no apk file until you export it. There are wlapp files to deploy on your server, but you need to manually export your built android project into one with a designated key. Right click the actual generated android project folder and export. Then you can choose Export Android Application and follow the directions from there.

                                You'll then be able to install that .apk or upload to android market/ibm app store. For iphone, you need a bit more to package out an ipa.

                                Please mark as answered! I am glad it works now!

                                -Harry Ho
                                OpenLogix Corporation
  • IdanAdar
    IdanAdar
    741 Posts
    ACCEPTED ANSWER

    Re: worklight emulator problem

    ‏2012-08-08T18:45:32Z  in response to venkatakrishnarao
    Google has a documented bug in regards to Android 2.3 emulators; it's not going to work.
    You can use VMs using Android 2.1, 2.2, 3, 4.x.

    It will work on an actual device running Android 2.3, though.

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform