为什么我在标准Android Level 10 API上收到此错误?我创建了最简单、最短的测试用例,因此我可以将整个Android 项目粘贴到下面:
E/AndroidRuntime( 406): java.lang.UnsatisfiedLinkError: getDeclaredAnnotations
E/AndroidRuntime( 406): at java.lang.Package.getDeclaredAnnotations(Native Method)
E/AndroidRuntime( 406): at java.lang.Package.getDeclaredAnnotations(Package.java:107)
E/AndroidRuntime( 406): at com.foobar.android.heartbeat.CustomAppWidgetProvider.onEnabled(CustomAppWidgetProvider.java:15)
E/AndroidRuntime( 406): at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:73)
1.AndroidManifest.xml _
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foobar.android.cannotate"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application>
<receiver android:name="com.foobar.android.cannotate.CustomAppWidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/custom_app_widget_provider_info" />
</receiver>
</application>
</manifest>
2. src/com/foobar/android/cannotate/CustomAppWidgetProvider.java`
package com.foobar.android.heartbeat;
import java.lang.annotation.Annotation;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.util.Log;
public class CustomAppWidgetProvider extends AppWidgetProvider {
@Override
public void onEnabled (Context context) {
super.onEnabled(context);
Log.d(getClass().getCanonicalName(), "about to get annotations");
Annotation [] annotations = CustomAppWidgetProvider.class.getPackage().getDeclaredAnnotations();
Log.d(getClass().getCanonicalName(), "annotations.length = " + annotations.length);
}
}
3. res/xml/custom_app_widget_provider_info.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/custom_app_widget"
>
</appwidget-provider>
4. res/layout/custom_app_widget.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/value"
android:text="@string/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
5. res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="empty">-</string>
</resources>