11 Replies Latest reply on Feb 15, 2016 6:51 AM by Dave DiGregorio

    Android Studio java.lang.RuntimeException: stub

    Bert Wijnants

      Hi,

       

      I am trying to get the EMDK up and running with Android Studio 1.1.0 on mac os x.

       

      I've been following this guide:

      Developing EMDK Apps With Android Studio 1.0.x

       

      I managed to get the addon-symbol-emdk_v3.0_API-16 (and 19) folders out of the windows installers for ADT.

       

      In Android Studio i include the com.symbol.emdk.jar in my libs folder.

      I also tried it another way by using the EMDK sdk as target sdk: "Symbol Technologies, Inc.:EMDK 3.0 (API 16):16"

       

      Both give the same result:

      java.lang.RuntimeException: stub when i access a method from the EMDK.

       

      On the MC40 that i am testing on, the EmdkOSUpdateApp_v3.0.4.apk installer was run. In the filebrowser i can see /system/framework/com.symbol.emdk.jar

       

      Any ideas on how to get the EMDK working?

       

      Thanks

      Bert

        • Re: Android Studio java.lang.RuntimeException: stub
          Derek Warren

          You don't want the com.symbol.emdk.jar file exported with your application, I'm not too sure how to do it in Android Studio but in Eclipse under Java Build Path it would be a reference library but not exported with the application (Project Properties -> Java Build Path -> Order and Export -> EMDK is unchecked). By not exporting the .jar you'll reference the .jar you've installed previously on the device that you referenced at /system/framework.

          • Re: Android Studio java.lang.RuntimeException: stub
            Pietro Maggi

            Hi Bert,

            what I usually do is to copy the com.symbol.emdk.jar into the lib folder and update the app.gradle file so that the jar package is seen by the tools but not included in the build:

             

            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')
            }
            

             

            Usually this works for me, is not currently supported.

            We're working to release official support for OS X Android Studio shortly.

             

            ~Pietro

            • Re: Android Studio java.lang.RuntimeException: stub
              Bert Wijnants

              Using "provided" in the dependencies did the trick.

              On the other hand, i also needed to add some permissions and libraries in the manifest:

               

                  <uses-permission android:name="com.symbol.emdk.permission.EMDK" />

                  <uses-permission android:name="android.permission.CAMERA" />

                  <uses-permission android:name="android.permission.VIBRATE" />

                  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

               

              and in your <application>

               

                      <uses-library android:name="com.symbol.emdk" />

                      <uses-library android:name="com.motorolasolutions.scanner" />

                      <uses-library android:name="com.motorolasolutions.adc.usbscanner" android:required="false" />

                • Re: Android Studio java.lang.RuntimeException: stub
                  Pietro Maggi

                  Sure,

                  the usual EMDK application requirements are still there, doesn't matter if you're using Android Studio or Ecliplse+ADT.

                   

                  You can use the tutorials in the EMDK section of Launchpad to see how to build an app:

                  EMDK

                   

                  ~Pietro

                    • Re: Android Studio java.lang.RuntimeException: stub
                      Dave DiGregorio

                      I am having same/similiar issue. Any help is appreciated. My error is ...

                       

                      02-12 16:06:02.195 5794-5794/com.sap.johnshopkins.sapparinventory E/AndroidRuntime: FATAL EXCEPTION: main

                                                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sap.johnshopkins.sapparinventory/com.sap.johnshopkins.sapparinventory.CountTemplateActivity}: java.lang.RuntimeException: stub

                                                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102)

                                                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2127)

                                                                                                              at android.app.ActivityThread.access$600(ActivityThread.java:136)

                                                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)

                                                                                                              at android.os.Handler.dispatchMessage(Handler.java:99)

                                                                                                              at android.os.Looper.loop(Looper.java:137)

                                                                                                              at android.app.ActivityThread.main(ActivityThread.java:4812)

                                                                                                              at java.lang.reflect.Method.invokeNative(Native Method)

                                                                                                              at java.lang.reflect.Method.invoke(Method.java:511)

                                                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

                                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

                                                                                                              at dalvik.system.NativeStart.main(Native Method)

                                                                                                           Caused by: java.lang.RuntimeException: stub

                                                                                                              at com.symbol.emdk.EMDKManager.getEMDKManager(Unknown Source)

                                                                                                              at com.sap.johnshopkins.sapparinventory.CountTemplateActivity.onCreate(CountTemplateActivity.java:193)

                                                                                                              at android.app.Activity.performCreate(Activity.java:5042)

                                                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)

                                                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2066)

                                                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2127)

                                                                                                              at android.app.ActivityThread.access$600(ActivityThread.java:136)

                                                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)

                                                                                                              at android.os.Handler.dispatchMessage(Handler.java:99)

                                                                                                              at android.os.Looper.loop(Looper.java:137)

                                                                                                              at android.app.ActivityThread.main(ActivityThread.java:4812)

                                                                                                              at java.lang.reflect.Method.invokeNative(Native Method)

                                                                                                              at java.lang.reflect.Method.invoke(Method.java:511)

                                                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

                                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

                                                                                                              at dalvik.system.NativeStart.main(Native Method)

                       

                      My environment is ...

                      MC40 4.1.1

                      Android Studio 1.5.1

                      EMDK 4.0

                       

                      Below is my build.gradle....

                       

                      apply plugin: 'com.android.application'

                      android {

                        compileSdkVersion 'Symbol Technologies LLC:EMDK 4.0 (API 19):19'
                         buildToolsVersion '22.0.1'
                         defaultConfig {

                        applicationId "com.sap.johnshopkins.sapparinventory"
                         minSdkVersion 16
                         targetSdkVersion 19
                         versionCode 1
                         versionName "1.0"
                         }

                        compileOptions {

                        sourceCompatibility JavaVersion.VERSION_1_7
                         targetCompatibility JavaVersion.VERSION_1_7
                         }

                        buildTypes {

                        release {

                        minifyEnabled false
                         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                         }

                        }

                        productFlavors {

                        }

                      }

                       

                      dependencies {

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

                        testCompile 'junit:junit:4.12'
                         compile 'com.android.support:appcompat-v7:19.+'
                         compile files('libs/ksoap2-android-assembly-3.4.0-jar-with-dependencies(1).jar')

                        provided files('libs/com.symbol.emdk.jar')

                      }

                       

                       

                      And here is portion of my AndroidManifest.xml......

                       

                      <?xml version="1.0" encoding="utf-8"?>
                      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                         package="com.sap.johnshopkins.sapparinventory" >

                       

                        <uses-sdk
                         android:minSdkVersion="16"
                         android:targetSdkVersion="19" />

                       

                        <android:uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

                        <android:uses-permission android:name="android.permission.READ_PHONE_STATE" />

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

                        <android:uses-permission android:name="com.symbol.emdk.permission.EMDK" />

                        <android:uses-permission
                         android:name="android.permission.READ_EXTERNAL_STORAGE"
                         android:maxSdkVersion="18" />

                       

                        <application
                         android:allowBackup="true"
                         android:icon="@mipmap/ic_launcher"
                         android:label="@string/app_name"
                         android:theme="@style/AppTheme" >

                        <activity
                         android:name=".MainActivity"
                         android:label="@string/app_name" >

                        <intent-filter>

                        <action android:name="android.intent.action.MAIN" />

                        <category android:name="android.intent.category.LAUNCHER" />

                        </intent-filter>

                        </activity>

                        <activity
                         android:name=".CountTemplateActivity"
                         android:label="@string/title_activity_count_template" >

                        <uses-library android:name="com.symbol.emdk" android:required="true"/>

                        </activity>

                        • Re: Android Studio java.lang.RuntimeException: stub
                          Bill Hecox

                          Dave, It looks like you have uses-library in the wrong place in your manifest. Move it up out of the activity declaration, into the application node.

                           

                            <application
                             android:allowBackup="true"
                             android:icon="@mipmap/ic_launcher"
                             android:label="@string/app_name"
                             android:theme="@style/AppTheme" >

                           

                          <uses-library android:name="com.symbol.emdk" android:required="true"/>

                           

                            <activity
                             android:name=".MainActivity"
                             android:label="@string/app_name" >

                            <intent-filter>

                            <action android:name="android.intent.action.MAIN" />

                            <category android:name="android.intent.category.LAUNCHER" />

                            </intent-filter>

                            </activity>

                            <activity
                             android:name=".CountTemplateActivity"
                             android:label="@string/title_activity_count_template" >

                            </activity>

                            • Re: Android Studio java.lang.RuntimeException: stub
                              Dave DiGregorio

                              Thanks Bill. I made the change and receive a different error ....

                               

                              02-12 17:17:41.765 10879-10879/com.sap.johnshopkins.sapparinventory E/AndroidRuntime: FATAL EXCEPTION: main

                                                                                                                    java.lang.NoClassDefFoundError: com/sap/johnshopkins/sapparinventory/CountTemplateActivity

                                                                                                                        at com.sap.johnshopkins.sapparinventory.ChooseTemplateMenuActivity$1.onClick(ChooseTemplateMenuActivity.java:61)

                                                                                                                        at android.view.View.performClick(View.java:4084)

                                                                                                                        at android.view.View$PerformClick.run(View.java:16966)

                                                                                                                        at android.os.Handler.handleCallback(Handler.java:615)

                                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:92)

                                                                                                                        at android.os.Looper.loop(Looper.java:137)

                                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:4812)

                                                                                                                        at java.lang.reflect.Method.invokeNative(Native Method)

                                                                                                                        at java.lang.reflect.Method.invoke(Method.java:511)

                                                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

                                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

                                                                                                                        at dalvik.system.NativeStart.main(Native Method)

                                                                                                                     Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

                                                                                                                        at dalvik.system.DexFile.defineClass(Native Method)

                                                                                                                        at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:211)

                                                                                                                        at dalvik.system.DexPathList.findClass(DexPathList.java:315)

                                                                                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:58)

                                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)

                                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)

                                                                                                                        at com.sap.johnshopkins.sapparinventory.ChooseTemplateMenuActivity$1.onClick(ChooseTemplateMenuActivity.java:61)

                                                                                                                        at android.view.View.performClick(View.java:4084)

                                                                                                                        at android.view.View$PerformClick.run(View.java:16966)

                                                                                                                        at android.os.Handler.handleCallback(Handler.java:615)

                                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:92)

                                                                                                                        at android.os.Looper.loop(Looper.java:137)

                                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:4812)

                                                                                                                        at java.lang.reflect.Method.invokeNative(Native Method)

                                                                                                                        at java.lang.reflect.Method.invoke(Method.java:511)

                               

                              My ChooseTemplateMenuActivity has a button that starts the CountTemplateActivity. The CountTemplateActivity is where the use of EMDK and scanning will occur. EMDK is not referenced in ChooseTemplateMenuActivity. The EMDKResults results = EMDKManager.getEMDKManager is no longer the issue. I get same error when I comment the line out. Below is the activity start code from ChooseTemplateMenuActivity.......

                               

                              btnCount.setOnClickListener(new View.OnClickListener() {

                                 public void onClick(View arg0) {


                                 Intent myIntent = new Intent(ChooseTemplateMenuActivity.this,

                                CountTemplateActivity.class);

                               

                                myIntent.putExtra("templateSelected", templateSelected);

                                startActivity(myIntent);

                               

                                }

                              });

                               

                              Beginning of my CountTemplateActivity code looks like below.  .....

                               

                              import com.symbol.emdk.EMDKManager;

                              import com.symbol.emdk.EMDKManager.EMDKListener;

                              import com.symbol.emdk.barcode.ScanDataCollection;

                              import com.symbol.emdk.barcode.Scanner.DataListener;

                              import com.symbol.emdk.barcode.Scanner.StatusListener;

                              import com.symbol.emdk.barcode.StatusData;

                              import com.symbol.emdk.barcode.BarcodeManager;

                              import com.symbol.emdk.barcode.BarcodeManager.DeviceIdentifier;

                              import com.symbol.emdk.EMDKManager.FEATURE_TYPE;

                              import com.symbol.emdk.EMDKResults;

                              import com.symbol.emdk.barcode.ScanDataCollection.LabelType;

                              import com.symbol.emdk.barcode.ScanDataCollection.ScanData;

                              import com.symbol.emdk.barcode.Scanner;

                              import com.symbol.emdk.barcode.ScannerConfig;

                              import com.symbol.emdk.barcode.Scanner.TriggerType;

                              import com.symbol.emdk.barcode.ScannerException;

                              import com.symbol.emdk.barcode.ScannerResults;

                              import com.symbol.emdk.barcode.StatusData.ScannerStates;

                               

                              public class CountTemplateActivity extends Activity

                                 implements

                                 EMDKListener, StatusListener, DataListener

                              {

                               

                                 // Declare a variable to store EMDKManager object
                                 private EMDKManager emdkManager = null;

                               

                                 // Declare a variable to store Barcode Manager object
                                 private BarcodeManager barcodeManager = null;

                               

                                 // Declare a variable to hold scanner device to scan
                                 private Scanner scanner = null;


                              boolean isScanning = false;


                                 @Override
                                 protected void onCreate(Bundle savedInstanceState) {

                                 super.onCreate(savedInstanceState);

                                setContentView(R.layout.activity_count_template);

                                Intent intent = getIntent();

                               

                              .

                              .

                              .

                              .

                               

                              // The EMDKManager object will be created and returned in the callback.
                                 EMDKResults results = EMDKManager.getEMDKManager(

                                getApplicationContext(), this);

                              // Check the return status of getEMDKManager and update the status Text
                              // View accordingly
                                 if (results.statusCode != EMDKResults.STATUS_CODE.SUCCESS) {

                                 lbl_status_area.setText("EMDKManager Request Failed");

                                }

                                • Re: Android Studio java.lang.RuntimeException: stub
                                  Dave DiGregorio

                                  Should have included the new manifest....

                                   

                                  <?xml version="1.0" encoding="utf-8"?>
                                  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                                     package="com.sap.johnshopkins.sapparinventory" >

                                   

                                    <uses-sdk
                                     android:minSdkVersion="16"
                                     android:targetSdkVersion="19" />

                                   

                                    <android:uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

                                    <android:uses-permission android:name="android.permission.READ_PHONE_STATE" />

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

                                    <android:uses-permission android:name="com.symbol.emdk.permission.EMDK" />

                                    <android:uses-permission
                                     android:name="android.permission.READ_EXTERNAL_STORAGE"
                                     android:maxSdkVersion="18" />

                                   

                                    <application
                                     android:allowBackup="true"
                                     android:icon="@mipmap/ic_launcher"
                                     android:label="@string/app_name"
                                     android:theme="@style/AppTheme" >

                                    <uses-library android:name="com.symbol.emdk" android:required="true"/>

                                    <activity
                                     android:name=".MainActivity"
                                     android:label="@string/app_name" >

                                    <intent-filter>

                                    <action android:name="android.intent.action.MAIN" />

                                    <category android:name="android.intent.category.LAUNCHER" />

                                    </intent-filter>

                                    </activity>

                                    • Re: Android Studio java.lang.RuntimeException: stub
                                      Bill Hecox

                                      Hey Dave, is that the full manifest?  If so it seems you no longer have CountTemplateActivity declared.

                                        • Re: Android Studio java.lang.RuntimeException: stub
                                          Dave DiGregorio

                                          No. Here is the full manifest...

                                           

                                          <?xml version="1.0" encoding="utf-8"?>
                                          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                                             package="com.sap.johnshopkins.sapparinventory" >

                                           

                                            <uses-sdk
                                             android:minSdkVersion="16"
                                             android:targetSdkVersion="19" />

                                           

                                            <android:uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

                                            <android:uses-permission android:name="android.permission.READ_PHONE_STATE" />

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

                                            <android:uses-permission android:name="com.symbol.emdk.permission.EMDK" />

                                            <android:uses-permission
                                             android:name="android.permission.READ_EXTERNAL_STORAGE"
                                             android:maxSdkVersion="18" />

                                           

                                            <application
                                             android:allowBackup="true"
                                             android:icon="@mipmap/ic_launcher"
                                             android:label="@string/app_name"
                                             android:theme="@style/AppTheme" >

                                            <uses-library android:name="com.symbol.emdk" android:required="true"/>

                                            <activity
                                             android:name=".MainActivity"
                                             android:label="@string/app_name" >

                                            <intent-filter>

                                            <action android:name="android.intent.action.MAIN" />

                                            <category android:name="android.intent.category.LAUNCHER" />

                                            </intent-filter>

                                            </activity>

                                            <activity
                                             android:name=".CountTemplateActivity"
                                             android:label="@string/title_activity_count_template" >

                                           

                                            </activity>

                                            <activity
                                             android:name=".LoadTemplateActivity"
                                             android:label="@string/title_activity_load_template" >

                                            </activity>

                                            <activity
                                             android:name=".ChooseTemplateMenuActivity"
                                             android:label="@string/title_activity_choose_template_menu" >

                                            </activity>

                                            <activity
                                             android:name=".SettingsActivity"
                                             android:label="@string/title_activity_settings" >

                                            </activity>

                                            <activity
                                             android:name=".RefreshJHEDsActivity"
                                             android:label="@string/title_refresh_jheds" >

                                            </activity>

                                            <activity
                                             android:name=".RefreshTemplatesActivity"
                                             android:label="@string/title_refresh_templates" >

                                            </activity>

                                            <activity
                                             android:name=".LoadTemplateItemsActivity"
                                             android:label="@string/title_load_template_items" >

                                            </activity>

                                            <activity
                                             android:name=".TestConnectivityActivity"
                                             android:label="@string/title_test_connectivity" >

                                            </activity>

                                            <activity
                                             android:name=".UploadCountsActivity"
                                             android:label="@string/title_upload_counts" >

                                            </activity>

                                            </application>

                                           

                                          </manifest>