我的项目的构建路径上有一个库(jar)。该项目使用以下意图访问 jar 中的 MainActivity:
final Intent it = new Intent();
it.setClassName("com.example.lib", "com.example.lib.MainActivity");
startActivity(it);
它曾经工作过一段时间,但突然开始出现“ActivityNotFoundException:找不到处理 Intent 的活动”,我能够解决。但是现在我遇到了“java.lang.SecurityException:Permission Denial:starting Intent”。
我已经尝试了关于 stackoverflow 的所有建议(检查清单文件中的重复项;将 android:exported="true" 添加到 lib 清单;Eclipse> Project> Clean;添加/修改“intent-filter”标签;等等)。我什至尝试重写项目的清单,但没有去任何地方。
这是 logcat 输出:
11-07 06:20:52.176: E/AndroidRuntime(4626): FATAL EXCEPTION: main
11-07 06:20:52.176: E/AndroidRuntime(4626): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.example.lib/.MainActivity } from ProcessRecord{40dd3778 4626:com.example.project/u0a10046} (pid=4626, uid=10046) not exported from uid 10047
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.os.Parcel.readException(Parcel.java:1425)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.os.Parcel.readException(Parcel.java:1379)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1885)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1412)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.Activity.startActivityForResult(Activity.java:3370)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.Activity.startActivityForResult(Activity.java:3331)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:824)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.Activity.startActivity(Activity.java:3566)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.Activity.startActivity(Activity.java:3534)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.example.project.MainActivity.onOptionsItemSelected(MainActivity.java:93)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:366)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.view.View.performClick(View.java:4204)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.view.View$PerformClick.run(View.java:17355)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.os.Handler.handleCallback(Handler.java:725)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.os.Looper.loop(Looper.java:137)
11-07 06:20:52.176: E/AndroidRuntime(4626): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-07 06:20:52.176: E/AndroidRuntime(4626): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 06:20:52.176: E/AndroidRuntime(4626): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-07 06:20:52.176: E/AndroidRuntime(4626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-07 06:20:52.176: E/AndroidRuntime(4626): at dalvik.system.NativeStart.main(Native Method)
项目清单 XML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project"
android:versionCode="4"
android:versionName="4.0" >
<!-- Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<supports-screens android:anyDensity="true" />
<!-- SDK Settings -->
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<!-- APP Start -->
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- App Activity -->
<activity
android:name="com.example.project.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>
<!-- Library Activity -->
<activity android:name="com.example.lib.MainActivity" android:label="LibMain">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
</intent-filter>
</activity>
</application>
<!-- END - APP -->
</manifest>
我在看什么?有什么建议么?
编辑
我用所有其他活动更新了 manifest.xml 并以某种方式解决了问题。意图活动启动时没有任何错误。但是,这仅在 AVD 上。在实际设备上,它仍然抛出相同的错误。我已经从设备上完全卸载了该应用程序并重新安装,但同样的错误。