0

My android app runs fine using eclipse but not when exported to an apk it gives me the following error when I try to run the app:

11-26 11:47:48.587: E/AndroidRuntime(20554): FATAL EXCEPTION: main
11-26 11:47:48.587: E/AndroidRuntime(20554): Process: ca.uwaterloo.kin.rehabmonitor.client, PID: 20554
11-26 11:47:48.587: E/AndroidRuntime(20554): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ca.uwaterloo.kin.rehabmonitor.client/ca.uwaterloo.kin.rehabmonitor.client.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "ca.uwaterloo.kin.rehabmonitor.client.MainActivity" on path: DexPathList[[zip file "/data/app/ca.uwaterloo.kin.rehabmonitor.client-1.apk"],nativeLibraryDirectories=[/data/app-lib/ca.uwaterloo.kin.rehabmonitor.client-1, /vendor/lib, /system/lib]]
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.os.Handler.dispatchMessage(Handler.java:102)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.os.Looper.loop(Looper.java:136)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.app.ActivityThread.main(ActivityThread.java:5001)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at java.lang.reflect.Method.invokeNative(Native Method)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at java.lang.reflect.Method.invoke(Method.java:515)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at dalvik.system.NativeStart.main(Native Method)
11-26 11:47:48.587: E/AndroidRuntime(20554): Caused by: java.lang.ClassNotFoundException: Didn't find class "ca.uwaterloo.kin.rehabmonitor.client.MainActivity" on path: DexPathList[[zip file "/data/app/ca.uwaterloo.kin.rehabmonitor.client-1.apk"],nativeLibraryDirectories=[/data/app-lib/ca.uwaterloo.kin.rehabmonitor.client-1, /vendor/lib, /system/lib]]
11-26 11:47:48.587: E/AndroidRuntime(20554):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
11-26 11:47:48.587: E/AndroidRuntime(20554):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
11-26 11:47:48.587: E/AndroidRuntime(20554):    ... 11 more

Here is my AndroidManifest.xml file:

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

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-feature android:name="android.hardware.camera" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomActionBarTheme" >
    <service
        android:name="com.estimote.sdk.service.BeaconService"
        android:exported="false" />

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".development.SensorDisplayActivity"
        android:configChanges="orientation|keyboardHidden"
        android:exported="false"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".prefs.SettingsActivity"
        android:exported="false"
        android:label="@string/title_activity_settings" >
    </activity>
    <activity
        android:name=".prompting.PromptActivity"
        android:exported="false"
        android:theme="@android:style/Theme.Translucent" >
    </activity>
    <activity
        android:name=".development.DeveloperActivity"
        android:exported="false"
        android:label="@string/title_activity_developer" >
    </activity>
    <activity
        android:name=".development.StatusDisplayActivity"
        android:exported="false"
        android:label="@string/title_activity_developer" >
    </activity>
    <activity
        android:name=".development.ShowErrorLogActivity"
        android:exported="false"
        android:label="@string/title_activity_developer" >
    </activity>
    <activity
        android:name=".error.ErrorActivity"
        android:exported="false" >
    </activity>
    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
    </activity>

    <service android:name=".MainService" />
    <service android:name=".monitoring.MonitoringService" />
    <service android:name=".writing.EventsLoggingService" />

    <receiver android:name=".BootAndShutdownReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        </intent-filter>
    </receiver>
    <receiver android:name=".progress.OnNewDayReceiver" >
    </receiver>
    <receiver android:name=".calendar.CalendarReceiver" >
    </receiver>
    <receiver android:name=".progress.ProgressReceiver" >
    </receiver>
    <receiver android:name=".prompting.SnoozeReceiver" >
    </receiver>
    <receiver android:name=".progress.HourlyReceiver" >
    </receiver>

    <activity
        android:name=".PasswordActivity"
        android:label="" >
        <intent-filter>
            <action android:name="android.intent.action.PasswordActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".tabs.TabActivity"
        android:label="@string/title_activity_tab" >
        <intent-filter>
            <action android:name="android.intent.action.TabActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".camera.CameraActivity"
        android:label="@string/title_activity_camera" >
        <intent-filter>
            <action android:name="android.intent.action.CameraActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".calendar.CalendarActivity"
        android:label="Calendar" >
    </activity>
    <activity
        android:name=".calendar.CalendarNotificationActivity"
        android:label="@string/title_activity_calendar_notification"
        android:theme="@android:style/Theme.NoTitleBar" >
    </activity>
    <activity
        android:name=".summary.SummaryActivity"
        android:label="@string/title_activity_summary" >
    </activity>
</application>

</manifest>

Any help would be greatly appreciated

edbert
  • 125
  • 1
  • 5
  • 16
  • Make sure that your MainActivity is not in another package, if it is you should add the package to the android:name – arlistan Nov 26 '14 at 17:01
  • 1)Make sure you export all libs in properties/java build path/order and export 2)Check your prodguard options, it may mangle class names for third-side libs so they cannot be found – Raiv Nov 26 '14 at 17:11
  • Thank you, MainActivity is in ca.uwaterloo.kin.rehabmonitor.client so I don't think that is the issue. I will check the libs and prodguard options – edbert Nov 26 '14 at 17:38

1 Answers1

0

Firstly, you should ensure your MainActvity.java is ca.uwaterloo.kin.rehabmonitor.client.MainActivity and not in another package. When you specified the package name in the manifest and defined .MainActivity, it attempted to resolve MainActivity as the above. Should your actual package containing MainActvity be different, you will need to rename the .MainActivity and other activities in the manifest to the FULL package name of the Activity.

Alternatively, a ClassNotFoundException may occur when exporting if your app uses progaurd. You should check your progaurd settings found in proguard-project.txt, as it could be obfuscating your application.

Ed Holloway-George
  • 5,092
  • 2
  • 37
  • 66
  • I'm not using proguard so I don't think that's it. My MainActivity class is in the package ca.uwaterloo.kin.rehabmonitor.client so I think this is fine as well. However what gets me is this line : ca.uwaterloo.kin.rehabmonitor.client/ca.uwaterloo.kin.rehabmonitor.client.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "ca.uwaterloo.kin.rehabmonitor.client.MainActivity Any ideas why it would think the path to MainActivity is ca.uwaterloo.kin.rehabmonitor.client/ca.uwaterloo.kin.rehabmonitor.client.MainActivity ? – edbert Nov 26 '14 at 17:50
  • Possibly try: http://stackoverflow.com/questions/8678630/noclassdeffounderror-for-code-in-an-java-library-on-android – Ed Holloway-George Nov 27 '14 at 00:03
  • Thanks, there seem to be quite a few things I can try there. None of them have worked so far but it's a start – edbert Nov 27 '14 at 15:04