Question

Why I am I getting this error on a standard Android Level 10 API? I have created the simplest, shortest possible test case so I can paste the entire Android project below:

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>
Was it helpful?

Solution

The exception you are seeing is happening because the native code method for Package.getDeclaredAnnotations() is not implemented by the runtime system on the platform you are running.

According to this android issue, Davlik currently doesn't support Package annotations at all. The exception is a symptom of that.

AFAIK, there's nothing you can do about it except avoid using Package annotations. (And mobilize your friends and relatives to vote for the issue to be fixed!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top