我的Android应用程序使用eclipse运行正常但是当导出到apk时它没有在我尝试运行应用程序时出现以下错误:
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
这是我的AndroidManifest.xml文件:
<?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>
非常感谢任何帮助
答案 0 :(得分:0)
首先,您应确保MainActvity.java
为ca.uwaterloo.kin.rehabmonitor.client.MainActivity
,而不是其他包。当您在清单中指定了包名称并定义了.MainActivity
时,它会尝试解析MainActivity
,如上所述。如果包含MainActvity
的实际包不同,则需要将清单中的.MainActivity
和其他活动重命名为活动的FULL包名称。
或者,如果您的应用使用ClassNotFoundException
,导出时可能会出现progaurd
。您应该检查proguard-project.txt
中找到的progaurd设置,因为它可能会使您的应用程序混淆。