Topic
13 replies Latest Post - ‏2013-02-01T15:08:21Z by IdanAdar
SystemAdmin
SystemAdmin
2327 Posts
ACCEPTED ANSWER

Pinned topic unable to generate .apk

‏2013-01-22T10:14:13Z |
Hi,

We have developed application using jquery mobile in worklight.When we are trying to generate .apk file we face problems.For testing we created a simple application without any websercice so that application dont need to be connect to the worklight server.
For this we deleted the "<worklightServerRootURL>" from application-descriptor.xml.
Now when compiled and generated the .apk file and installed it in mobile we get the error "The Application Failed connecting to the service".For testing In "initOptions.js" file we also make " connectOnStartup : false" so that it could'nt connect to server.But all efforts went fruiltless.Kindly guilde us how to solve this issue.And also tell us the right way to generate .apk ,ipa etc files because yet we are unaware what are the necessary steps to create setups.
  • IdanAdar
    IdanAdar
    741 Posts
    ACCEPTED ANSWER

    Re: unable to generate .apk

    ‏2013-01-22T12:06:21Z  in response to SystemAdmin
    Hi,

    There is absolutely no need to remove the worklightServerRootURL element; if in fact I would recommend keeping it there.
    In order to properly set your application to NOT connect to the Worklight Server (work 'offline'), make sure that in yourProject\yourApp\common\js\initOptions.js, connectOnStartup is set to false.

    Next, in order for an .apk file to be generated you must have the Google ADT plug-in; in Eclipse, go to Help >> Marketplace and search for 'adt', install it.
    Once you have the plug-in installed, choose Run As >> Build all and deploy. This will generate the Android project.

    To install the .apk on your device or simulator, you have two choices (when testing):
    • right-click the generated Android project and choose: Run As >> Android application, or
    • in your file explorer, navigate to the bin folder of the generated Android project, you will find <yourApp>.apk there

    To learn more about how to produce .apk, .ipa, please read our Getting Started material: https://www.ibm.com/developerworks/mobile/worklight/getting-started/

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform
    • SystemAdmin
      SystemAdmin
      2327 Posts
      ACCEPTED ANSWER

      Re: unable to generate .apk

      ‏2013-01-22T13:10:11Z  in response to IdanAdar
      Idan,

      Thanks for reply.
      "There is absolutely no need to remove the worklightServerRootURL element; if in fact I would recommend keeping it there.
      In order to properly set your application to NOT connect to the Worklight Server (work 'offline'), make sure that in yourProject\yourApp\common\js\initOptions.js, connectOnStartup is set to false."
      These settings we have done and check but no result. As far as " Google ADT plug-in" concerned Google APIs is installed in eclipse but for rechecking i'm deleting and again downloading it.If its work then i tell you.
      Thanks
      • SystemAdmin
        SystemAdmin
        2327 Posts
        ACCEPTED ANSWER

        Re: unable to generate .apk

        ‏2013-01-24T13:19:31Z  in response to SystemAdmin
        Application working fine in android emulator.But when i install this application in device and run i get the error
        "Application Failed connecting to the service" and when check its detail there written service url="http://10.0.2.2:8080/apps/services/api/index/android "
        we have developed application on developer edition and testing on it.But we have also bought the Enterprise edition.

        Application-descriptr.xml is bellow:

        <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <!-- Licensed Materials - Property of IBM
        5725-G92 (C) Copyright IBM Corp. 2006, 2012. All Rights Reserved.
        US Government Users Restricted Rights - Use, duplication or
        disclosure restricted by GSA ADP Schedule Contract with IBM Corp. -->
        <!-- Attribute "id" must be identical to application folder name -->
        <application xmlns="http://www.worklight.com/application-descriptor" id="index" platformVersion="5.0">
        <displayName>MobiBank</displayName>
        <description>MobiBank</description>
        <author>
        <name>Kashif Amin Makhdoom</name>
        <email>kashif.makhdoom@ubl.com.pk</email>
        <homepage>http://ubldirect.com</homepage>
        <copyright>Copyright, United Bank Limited</copyright>
        </author>
        <height>460</height>
        <width>320</width>
        <mainFile>index.html</mainFile>
        <thumbnailImage>common/images/thumbnail.png</thumbnailImage>

        <android version="1.0">
        <worklightSettings include="true"/>
        <security>

        <encryptWebResources enabled="false"/>
        <testWebResourcesChecksum enabled="false" ignoreFileExtensions="png, jpg, jpeg, gif, mp4, mp3"/>
        <publicSigningKey>Replace this text with the public key of the certificate with which you sign the APK. For details see the Worklight Developer's Reference Guide.</publicSigningKey>
        </security>
        </android>
        <mobileWebApp version="1.0"/>
        <worklightServerRootURL>http://10.0.2.2:8080</worklightServerRootURL>
        </application>

        AndroidMenifest.xml is below :

        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.index"
        android:versionCode="1"
        android:versionName="1.0">

        <supports-screens
        android:smallScreens="false"
        android:normalScreens="true"
        android:largeScreens="false"
        android:resizeable="false"
        android:anyDensity="false"
        />

        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

        <!-- Push permissions -->
        <permission android:name="com.index.permission.C2D_MESSAGE" android:protectionLevel="signature" />
        <uses-permission android:name="com.index.permission.C2D_MESSAGE" />
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
        <uses-permission android:name="android.permission.USE_CREDENTIALS" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

        <application
        android:label="@string/app_name"
        android:debuggable="true"
        android:icon="@drawable/icon" >
        <activity android:name=".index"
        android:label="@string/app_name"
        android:configChanges="orientation|keyboardHidden"
        android:launchMode="singleTask">
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
        <action android:name="com.index.index.NOTIFICATION" />
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </activity>

        <!-- Preference Activity -->
        <activity
        android:name="com.worklight.common.WLPreferences"
        android:label="Worklight Settings">
        </activity>
        <!-- Push service -->
        <!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver
        It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. -->
        <service android:name=".GCMIntentService" />

        <!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it -->
        <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
        <!-- Receive the actual message -->
        <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="com.index" />
        </intent-filter>
        <!-- Receive the registration id -->
        <intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="com.index" />
        </intent-filter>
        </receiver>
        </application>
        <uses-sdk android:minSdkVersion="15"
        android:targetSdkVersion="16" />
        </manifest>
        initOtions.js is below:

        var wlInitOptions = {
        connectOnStartup : false
        };

        WLJSX.bind(window, "load", function() {
        WL.Client.init(wlInitOptions);
        });

        index.java is below:

        package com.index;

        import android.os.Bundle;

        import com.worklight.androidgap.WLDroidGap;

        public class index extends WLDroidGap {
        @Override
        public void onCreate(Bundle savedInstanceState) {
        super.setIntegerProperty("loadUrlTimeoutValue", 70000);
        super.onCreate(savedInstanceState);
        //this.appView.getSettings().setAllowUniversalAccessFromFileURLs (true);
        //DeviceAuthManager.getInstance().setProvisioningDelegate(<Use default ProvisioningDelegateImpl class or replace with your IProvisioningDelegate implementation>);
        //super.loadUrl(getWebMainFilePath());
        super.loadUrl("file:///android_asset/www/default/index.html");
        }
        }


        wlclient.properties is below:

        wlServerProtocol = http
        wlServerHost = 10.0.2.2
        wlServerPort = 8080
        wlServerContext = /
        wlAppId = index
        wlAppVersion = 1.0
        GcmSenderId =
        enableSettings = true
        testWebResourcesChecksum = false
        ignoredFileExtensions =
        Now please check this code and guide me me what i am doing wrong.
      • SystemAdmin
        SystemAdmin
        2327 Posts
        ACCEPTED ANSWER

        Re: unable to generate .apk

        ‏2013-01-24T13:24:14Z  in response to SystemAdmin
        In detail also the Error message is: ""Connection to the service is not available"
  • IdanAdar
    IdanAdar
    741 Posts
    ACCEPTED ANSWER

    Re: unable to generate .apk

    ‏2013-01-24T13:33:32Z  in response to SystemAdmin
    Hi,

    At first glance it looks to be like the IP address you have put for worklightServerRootURL is not the correct one to use.
    Try using the IPv4 address provided to the computer running Eclipse (with the developer edition), for example 9.148.23.85 ...

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform
    • SystemAdmin
      SystemAdmin
      2327 Posts
      ACCEPTED ANSWER

      Re: unable to generate .apk

      ‏2013-01-24T14:13:05Z  in response to IdanAdar
      But my application not using any adapter so still i need to connect worklight server.?.Its a test application so called offline application.
      • SystemAdmin
        SystemAdmin
        2327 Posts
        ACCEPTED ANSWER

        Re: unable to generate .apk

        ‏2013-01-24T15:01:34Z  in response to SystemAdmin
        In which initOptions.js did you set connectOnStartup to false and did you build all and deploy again after doing so?
        • SystemAdmin
          SystemAdmin
          2327 Posts
          ACCEPTED ANSWER

          Re: unable to generate .apk

          ‏2013-01-24T21:14:58Z  in response to SystemAdmin
          IniOption.js file available under common->js.. I edited it's value to false so it couldn't connect to server.but when I build the project and instaled the generated .apk in mobile it throws the error "the application failed connecting to service".this error is totally not understandable.what does it mean. And as I mentioned in previous post when I check the detail of error there written service url="http://10.0.2.2:8080/apps/services/api/index/android " ,error message=unable to connect the service.
  • IdanAdar
    IdanAdar
    741 Posts
    ACCEPTED ANSWER

    Re: unable to generate .apk

    ‏2013-01-27T07:13:10Z  in response to SystemAdmin
    I can't say this is happening here unfortunately. :/

    What is the Android device you are testing with? What is the Android OS version? What is your Android SDK version?
    This all sounds though not related, and you do seem to have followed the right steps.

    Just to make sure things are indeed OK, could you please:
    1. Create a new project, new application, add android environment
    2. Build all and deploy
    3. Install on device

    See if it happens still or not...
    If it does not happen, we need to investigate what is different in your application.

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform
    • SystemAdmin
      SystemAdmin
      2327 Posts
      ACCEPTED ANSWER

      Re: unable to generate .apk

      ‏2013-01-30T13:29:40Z  in response to IdanAdar
      Dear IdanAdar ,

      When i used error handling using onConnectionFailure in
      "<body onload="WL.Client.init({timeout:2000 , onConnectionFailure: doConnectionFailure})" id="content" style="display: none">"
      I found my app is not connecting to to worklight server.

      in application-descripter.xml i gave the IP of Worklight Server(Enterprise Edition).But "doConnectionFailure" shows app not gona connect to server.
      I used:
      <worklightServerRootURL>http://My_WorklightServer_Live:9080/worklight</worklightServerRootURL>
      but still application is unable to connect to server.
  • IdanAdar
    IdanAdar
    741 Posts
    ACCEPTED ANSWER

    Re: unable to generate .apk

    ‏2013-01-30T13:44:07Z  in response to SystemAdmin
    Hi,

    Are you using the latest version of Worklight?
    I see this onLoad function in the BODY element, and this is no longer the case since 5.0.0.3.

    Have you added this yourself?

    I think that before you try moving to an application sever (Tomcat/WAS/Liberty) with your project, you should try a simple application on the Developer Edition, and continue onwards from there.

    Please have a fresh Eclipse, and install on it Worklight 5.0.5.1 from the Eclipse Marketplace (Eclipse >> Help >> Eclipse Marketplace, search for "worklight").
    Repeat this step, but this time search for "adt" in order to install the Google Android developer tools.

    Next,
    1. Create a new Worklight project and application
    2. Add the Android environment
    3. Build and deploy
    4. Run in Simulator or Device

    See that the application successfully launches and does not try to connect to the Worklight Server (does not display any error message).

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform
    • SystemAdmin
      SystemAdmin
      2327 Posts
      ACCEPTED ANSWER

      Re: unable to generate .apk

      ‏2013-01-31T14:33:22Z  in response to IdanAdar
      Dear IdanAdar,

      I'm feeling glad to tell you that atlast i resolved the issue and application is working fine in android mobile and connecting to the server as well.Issue were due to the main file loading in helloworld.java. "super.loadUrl(getWebMainFilePath());" were picking the wrong file to load.also the wlaap file we upload to Live worklight server.
      Thank you so much for your great support.

      Anees.
  • IdanAdar
    IdanAdar
    741 Posts
    ACCEPTED ANSWER

    Re: unable to generate .apk

    ‏2013-02-01T15:08:21Z  in response to SystemAdmin
    Hi - sorry, but while trying to separate your BlackBerry question to its own thread, I actually deleted it(!).
    Please open a new thread with your question (lets not mix subjects). Thanks.

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform