7 Replies Latest reply on Aug 14, 2015 2:53 PM by Kanagal Raj Ramaswamy

    Using EMDK in Cordova Plugin


      How can I use the emdk api within a cordova plugin?

      I added com.symbol.jar to the lib folder of my plugin:


      <?xml version="1.0" encoding="UTF-8"?> <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"     id="com.dff.cordova.plugins.powermanager"     version="0.0.1">     <name>PowerManager</name>     <description>PowerManager Plugin</description>     <keywords>phonegap,cordova,PowerManager,dff</keywords>       <js-module src="www/powermanager.js" name="powermanager">         <clobbers target="PowerManger" />     </js-module>      <!-- android -->     <platform name="android">         <config-file target="res/xml/config.xml" parent="/*">             <feature name="PowerManager">                 <param name="android-package" value="com.dff.cordova.plugin.powermanager.PowerManagerPlugin"/>                 <!-- param name="onload" value="true" / -->             </feature>         </config-file>                 <config-file target="AndroidManifest.xml" parent="/*">             <uses-permission android:name="android.permission.REBOOT" />             <uses-permission android:name="com.symbol.emdk.permission.EMDK"/>         </config-file>                 <config-file target="AndroidManifest.xml" parent="/manifest/application">             <uses-library android:name="com.symbol.emdk"/>         </config-file>           <!-- framework src="addon-symbol-emdk_v3.1_API-19/libs/com.symbol.emdk.jar" / -->                 <resource-file src="assets/EMDKConfig.xml" target="assets/EMDKConfig.xml" />         <source-file src="lib/com.symbol.emdk.jar" target-dir="libs" />         <source-file src="src/android/com/dff/cordova/plugin/powermanager/PowerManagerPlugin.java" target-dir="src/com/dff/cordova/plugin/powermanager" />              </platform> </plugin>


      Then building an apk works fine. But when the plugin is executed the following error is thrown:


      06-22 16:22:07.639: W/dalvikvm(8575): Class resolved by unexpected DEX: Lcom/dff/cordova/plugin/powermanager/PowerManagerPlugin;(0x419475c0):0x5b666000 ref [Lcom/symbol/emdk/EMDKManager$EMDKListener;] Lcom/symbol/emdk/EMDKManager$EMDKListener;(0x419475c0):0x5b625000 06-22 16:22:07.639: W/dalvikvm(8575): (Lcom/dff/cordova/plugin/powermanager/PowerManagerPlugin; had used a different Lcom/symbol/emdk/EMDKManager$EMDKListener; during pre-verification) 06-22 16:22:07.639: I/dalvikvm(8575): Failed resolving Lcom/dff/cordova/plugin/powermanager/PowerManagerPlugin; interface 706 'Lcom/symbol/emdk/EMDKManager$EMDKListener;' 06-22 16:22:07.639: W/dalvikvm(8575): Link of class 'Lcom/dff/cordova/plugin/powermanager/PowerManagerPlugin;' failed 06-22 16:22:07.639: W/System.err(8575): java.lang.ClassNotFoundException: com.dff.cordova.plugin.powermanager.PowerManagerPlugin 06-22 16:22:07.639: W/System.err(8575): at java.lang.Class.classForName(Native Method) 06-22 16:22:07.649: W/System.err(8575): at java.lang.Class.forName(Class.java:251) 06-22 16:22:07.649: W/System.err(8575): at java.lang.Class.forName(Class.java:216) 06-22 16:22:07.649: W/System.err(8575): at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:487) 06-22 16:22:07.649: W/System.err(8575): at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:167) 06-22 16:22:07.659: W/System.err(8575): at org.apache.cordova.PluginManager.exec(PluginManager.java:120) 06-22 16:22:07.659: W/System.err(8575): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) 06-22 16:22:07.659: W/System.err(8575): at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) 06-22 16:22:07.659: W/System.err(8575): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) 06-22 16:22:07.659: W/System.err(8575): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:24)06-22 16:22:07.659: W/System.err(8575): at android.os.Handler.dispatchMessage(Handler.java:102) 06-22 16:22:07.659: W/System.err(8575): at android.os.Looper.loop(Looper.java:136) 06-22 16:22:07.659: W/System.err(8575): at android.os.HandlerThread.run(HandlerThread.java:61) 06-22 16:22:07.669: W/System.err(8575): Caused by: java.lang.NoClassDefFoundError: com/dff/cordova/plugin/powermanager/PowerManagerPlugin


      Is there a way to include com.symbol.jar for compiling but not for dexing?

        • Re: Using EMDK in Cordova Plugin
          Derek Warren

          Are you using eclipse or Android studio to build your application?

          • Re: Using EMDK in Cordova Plugin
            Pietro Francesco Maggi

            Hi Frank,

            one of the things that you need to keep in mind is that you need to reference the com.symbol.emdk.jar library NOT INCLUDE IT!


            so, for example, using gradle, you can have something like this in your configuration if you put the com.symbol.emdk.jar library in the libs folder:

            dependencies {
                compile fileTree(dir: 'libs', include: ['*.jar'], exclude: ['com.symbol.emdk.jar'])
                compile 'com.android.support:appcompat-v7:21.0.3'
                provided files('./libs/com.symbol.emdk.jar')


            best regards


            1 of 1 people found this helpful
            • Re: Using EMDK in Cordova Plugin
              Kanagal Raj Ramaswamy

              The com.symbol.emdk.jar which gets installed during the EMDK installer can be used only for compiling applications. This stubbed version and does not contain the actual source. So you should never copy the com.symbol.emdk.jar into your applications lib folder.


              Choices are:

              1. If you are using Android Studio or Eclipse and want use Android API 16 or 19, select the EMDK API in the Android or Eclipse to build the application in the build target.


              2. If you are using the Android Studio or Eclipse, but use google API and EMDK together, select on of the add-on in the build target and add the other as external library.


              3. If you are using the Build script to build your project, you can use like

              LOCAL_JAVA_LIBRARIES := com.symbol.emdk

              LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libemdk:com.symbol.emdk/com.symbol.emdk.jar


              4. if you are using the gradle to build your project, then use the com.symbol.emdk.jar in dependencies of your gradle file as below:

              You need to add the below to your gradle file, where EMDKSDK specifies folder where your com.symbol.emdk.jar is located. In this sample I am using the relative path.

              dependencies {
                  compile fileTree(include: ['*.jar'], dir: 'libs')

                  compile fileTree("..\\..\\EMDKSDK\\com.symbol.emdk.jar")


              The overall comment is use com.symbol.emdk.jar for compiling application, never deploy this as part of your application. This way the application does not need to recompile there apps when the EMDK team release news patches and fixes. Installing the EMDK OS update will deploy the corresponding run times on the device and specifying <uses-library android:name="com.symbol.emdk"/>  in your app tells the android to dynamically use the library on device.