Unable to instantiate activity

Hi there,

I'm trying to integrate an app with T55 scanner, however, when I try to launch my app, it crashes with error:

 

 

 

2763-2763/? E/com.amazon.XXX.mobile﹕ java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.amazon.XXX.YYY.ZZZ/com.amazon.XXX.YYY.ZZZ.ui.activity.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.amazon.XXX.YYY.ZZZ.activity.LoginActivity" on path: DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.amazon.XXX.YYY.AMAZONAPP-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amazon.XXX.YYY.AMAZONAPP-2, /vendor/lib, /system/lib]]

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

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

            at android.app.ActivityThread.access$800(ActivityThread.java:141)

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

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

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

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

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

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

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

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

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

     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.amazon.XXX.YYY.ZZZ.activity.LoginActivity" on path: DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.amazon.XXX.YYY.AMAZONAPP-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amazon.XXX.YYY.AMAZONAPP-2, /vendor/lib, /system/lib]]

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

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

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

            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)

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

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

            at android.app.ActivityThread.access$800(ActivityThread.java:141)

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

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

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

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

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

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

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

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

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

08-04 21:29:52.641    2763-2763/? W/System.err﹕ Aug 4, 2015 9:29:52 PM com.amazon.XXX.mobile.core.L e

08-04 21:29:52.641    2763-2763/? W/System.err﹕ SEVERE:

08-04 21:29:52.641    2763-2763/? W/System.err﹕ Throwable occurred: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.amazon.XXX.YYY.ZZZ/com.amazon.XXX.YYY.ZZZ.ui.activity.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.amazon.XXX.YYY.ZZZ.ui.activity.LoginActivity" on path: DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.amazon.XXX.YYY.AMAZONAPP-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amazon.XXX.YYY.AMAZONAPP-2, /vendor/lib, /system/lib]]

 

 

I tried to follow the instructions at https://portal.motorolasolutions.com/Support/US-EN/Resolution?solutionId=96043&redirectForm=search&searchQuery=%3Fsearch… to run the EnterpriseEnabler APK, however, after reboot, there is no 'Enterprise Mode' item in Settings > About Phone > SW components.

Is there a detailed wiki page on how (and where) to download & install the latest EnterpriseEnabler APK?

BTW, I can't run any of the sample applications, and got the same/similar error.

Anonymous (not verified)
Hello Kerry, Which BSP are

Hello Kerry, Which BSP are you running on your TC55?  Find this in Settings>About Phone> Build number

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kerry Wei
Hi Bill, Thanks for the

Hi Bill,

Thanks for the response.

The build number is 150324-SI-1800EN-02.50-23257-4.4.4-user.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Kerry, from the log above, I

Kerry, from the log above, I assume you are attempting the use the EMDK in your application.  Could be possibly step back and have you test/run one of the pre-built sample apps that are included with the EMDK install, or pull down the the example project at the bottom of the basic barcode scanning tutorial and try it out?  I would like to rule out any issues you may be having in the project build process. 

Just download the zip, extract and then install the apk from the bin folder.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kerry Wei
I can run the APK in bin

I can run the APK in bin folder and perform scanning.

Found someone having the same issue at , but the mentioned solution does not work for me.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kerry Wei
I organized my projects as

I organized my projects as follows:

a shared library project: contains a base activity which is integrated with T55 scanner

a application project: this project requires the shared library, and my login activity is a subclass of the base activity.

In AndroidStudio, I added the following to the shared library project in build.gradle:

compile fileTree(dir: 'libs', include: ['*.jar'], exclude: ['com.symbol.emdk.jar'])

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

Could it be some issue with gradle build?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Pietro Francesc...
Hi Kelly,those lines in the

Hi Kelly,

those lines in the build.gradle file are needed only if you're using the standard Google SDK as target for your project. If you're building using the Zebra EMDK as CompileSDK, they're not required.

I mean, it's not needed when you've:

android {

  compileSdkVersion 'Symbol Technologies, Inc.:EMDK 3.1 (API 19):19'

. . . .

. . . .

. . . .

}


Are you sure to include the Activity class in the resulting apk? from the error seems that the Dalvik VM on the device is not able to locate the right class.


~Pietro

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Kerry Wei
Bill and Pietro,Thank you for

Bill and Pietro,

Thank you for your replies.

I get rid of the 'Unable to instantiate activity ...' error by moving the base activity which has the integration with T55 scanner from the shared library project to the application project, and it builds and run. It should be some gradle build issue that causes the trouble.

However, the new issue I have is the application is supposed to integrate with other hardware scanners as well. I noticed that if I put

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

in the app, the app will quit (but launches without issue on TC55) on the other hardware platform with error:

08-05 22:57:59.374  13271-13271/com.amazon.XXX.mobile.YYY E/com.amazon.XXX.mobile﹕ java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.amazon.XXX.mobile.YYY/com.amazon.XXX.mobile.YYY.ui.activity.LoginActivity}: java.lang.ClassNotFoundException: com.amazon.XXX.mobile.YYY.ui.activity.LoginActivity in loader dalvik.system.PathClassLoader[/data/app/com.amazon.XXX.mobile.YYY-2.apk]

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

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

            at android.app.ActivityThread.access$1500(ActivityThread.java:117)

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

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

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

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

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

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

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

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

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

     Caused by: java.lang.ClassNotFoundException: com.amazon.XXX.mobile.YYY.ui.activity.LoginActivity in loader dalvik.system.PathClassLoader[/data/app/com.amazon.XXX.mobile.YYY-2.apk]

            at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)

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

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

            at android.app.Instrumentation.newActivity(Instrumentation.java:1021)

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

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

            at android.app.ActivityThread.access$1500(ActivityThread.java:117)

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

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

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

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

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

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

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

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

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

If I put

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

in the app, it launches fine on the other hardware platform, but crashes on TC55 with the original error error I posted:


2763-2763/? E/com.amazon.XXX.mobile﹕ java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.amazon.XXX.YYY.ZZZ/com.amazon.XXX.YYY.ZZZ.ui.activity.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.amazon.XXX.YYY.ZZZ.activity.LoginActivity" on path: DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.amazon.XXX.YYY.AMAZONAPP-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amazon.XXX.YYY.AMAZONAPP-2, /vendor/lib, /system/lib]]

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

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

            at android.app.ActivityThread.access$800(ActivityThread.java:141)

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

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

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

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

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

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

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

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

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

     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.amazon.XXX.YYY.ZZZ.activity.LoginActivity" on path: DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.amazon.XXX.YYY.AMAZONAPP-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amazon.XXX.YYY.AMAZONAPP-2, /vendor/lib, /system/lib]]

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

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

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

            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)

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

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

            at android.app.ActivityThread.access$800(ActivityThread.java:141)

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

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

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

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

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

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

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

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

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

08-04 21:29:52.641    2763-2763/? W/System.err﹕ Aug 4, 2015 9:29:52 PM com.amazon.XXX.mobile.core.L e

08-04 21:29:52.641    2763-2763/? W/System.err﹕ SEVERE:

08-04 21:29:52.641    2763-2763/? W/System.err﹕ Throwable occurred: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.amazon.XXX.YYY.ZZZ/com.amazon.XXX.YYY.ZZZ.ui.activity.LoginActivity}: java.lang.ClassNotFoundException: Didn't find class "com.amazon.XXX.YYY.ZZZ.ui.activity.LoginActivity" on path: DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.amazon.XXX.YYY.AMAZONAPP-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.amazon.XXX.YYY.AMAZONAPP-2, /vendor/lib, /system/lib]]

The question I have now is: is there a way to build ONE APK (I know I can specify different flavors in gradle build to use different manifest files) that works on multiple platforms including TC55?

The error looks like some issue with compiling the EMDK jar file to me.

Thanks

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Yes you can get the

Yes you can get the application to run on other non-Zebra Android devices. In your Android manifest you'll need to set the EMDK as not required using the following:

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

Then what I did (you can do what you think is best) was take the EMDK calls and move it into its own class that checks for a Zebra device before using the EMDK or use another scanning library. I was able to get this working with the EMDK and a 3rd party camera based scanning library that ran on both Zebra and generic Android phones.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kerry Wei
Hi Derek, Did you compile the

Hi Derek,

Did you compile the com.symbol.emdk.jar file in your universal app?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kerry Wei
I did specify<uses-library

I did specify

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

However, after compile, it would complain about 'java.lang.RuntimeException: Unable to instantiate activity' on TC55 if I compile com.symbol.emd.jar;

If I don't compile com.symbol.emd.jar (use 'provide files('./libs/com.symbol.emdk.jar')' ), it works on TC55, but crashes on other Android device for error 'Unable to instantiate activity'

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Pietro Francesc...
Kerry,you probably need that

Kerry,

you probably need that your entry point Activity (the one intercepting the Intent "android.intent.action.MAIN") does not require any EMDK functionality (e.g. does not implement the EMDKListener interface).

In this first activity you can then use something like the "Build.DEVICE" or check if there's the package com.symbol.emdk on the device and decide if you're running on a TC55 (and use our EMDK) or on a consumer device and works without the barcode scanner.

~Pietro

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
I only provided the EMDK I

I only provided the EMDK I didn't compile with it.

What Pietro is saying is correct if your main activity uses the EMDKListener (public class YourActivity implements EMDKListener) it will cause the application to crash since it isn't available on the device. Add a check like Pietro suggested then you can determine to create an object that uses the EMDK calls on Zebra devices.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kanagal Raj Ram...
If you want write a common

If you want write a common application which works on both Zebra and Non Zebra device, you should not implement the EMDK Listener on the MainActiviity because the EMDKListener classes will not be available on the non Zebra devices.

So I would recommend below:

1. Create separate class (ex: EMDKAPIWrapper or any other name) and implement the EMDK related calls in that. When the activity starts, create the EMDKAPIWrapper object only if you are using the Zebra Device.

2. Add the below line in the manifest file so that it will not look for EMDK files on during installation and this will solve the installation problem on non zebra device and app dynamically links to the EMDK on the zebra device.

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


3. The com.symbol.emdk.jar file distributed in sdk-addon must be used on the PC only for compiling the application. If you copy the file to applications libs folder, it will conflict with jar on the device. In your gradle file you must specify to use EMDK for compiling the application.

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 sample gradle file is:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 16
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.nrwv87.myapplication"
        minSdkVersion 19
        targetSdkVersion 21
        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'
        }
    }
}

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

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

If you are using the MAKE file, you can use the below syntax:

LOCAL_JAVA_LIBRARIES := com.symbol.emdk

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kerry Wei
Thank you for the help, Derek

Thank you for the help, Derek, Pietro, Bill, and Kanagal.

My LoginActivity implementing EMDKListener is the root cause for the crashing. I moved the logic to a separate wrapper class and resolves the issue.

Again, thank you all for the help!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Kerry, If you remove "provide

Kerry, If you remove "provide files('./libs/com.symbol.emdk.jar')" does it run?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kerry Wei
It wouldn't compile as one of

It wouldn't compile as one of my class uses EMDJ libraries

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Kerry, Its possible that the

Kerry, Its possible that the the lines in your build.gradle are the culprit but I'm just not sure without more information, or being able to look at the project source. 

Since the Barcode Sample apk ran as expected, could you also import the Barcode Sample project and build it in your environment to make sure it works as expected. Then we can compare that projects properties and build.gradle to help find what may be different.

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Pietro Francesc...
Hi Kerry,The Enterprise

Hi Kerry,

The Enterprise Enabler is needed only if you have a TC55 with Android Jelly Bean v4.1 and the Google Mobile Services. Is not needed when you're using Android KitKat v4.4.x. So you're good on this and the issue is somewhere else.

~Pietro

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments