1

为什么我在标准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>
4

1 回答 1

1

Package.getDeclaredAnnotations()您看到的异常正在发生,因为您正在运行的平台上的运行时系统未实现本机代码方法。

根据这个 android issue,Davlik 目前根本不支持 Package annotations。例外是一个症状。

AFAIK,除了避免使用包注释之外,您无能为力。(并动员您的亲朋好友为要解决的问题投票!)

于 2011-12-23T01:20:23.787 回答