dimanche 11 octobre 2015

java.lang.RuntimeException: Unable to instantiate Android stub

Sorry if this is a repeated question, it looks basic but I couldn't find any answer. I'm trying to run Amazon's SNS KindleMobilePushApp demo app in a Kindle Fire tablet, but I get the following error:

    10-09 14:19:33.508    3101-3101/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40b05228)
10-09 14:19:33.508    3101-3101/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to instantiate service com.amazonaws.kindletest.ADMMessageHandler: java.lang.RuntimeException: Stub!
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2315)
            at android.app.ActivityThread.access$1600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4533)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Stub!
            at com.amazon.device.messaging.ADMMessageHandlerBase.<init>(Unknown Source)
            at com.amazonaws.kindletest.ADMMessageHandler.<init>(ADMMessageHandler.java:32)
            at java.lang.Class.newInstanceImpl(Native Method)
            at java.lang.Class.newInstance(Class.java:1319)
            at android.app.ActivityThread.handleCreateService(ActivityThread.java:2312)
            at android.app.ActivityThread.access$1600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4533)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
10-09 14:21:08.359    3101-3101/? E/AndroidRuntime﹕ Handle UnCaght exceptions. KILLING PID: 3101

This happens in the default constructor of this class of the sample project:

package com.amazonaws.kindletest;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.amazon.device.messaging.ADMConstants;
import com.amazon.device.messaging.ADMMessageHandlerBase;
import com.amazon.device.messaging.ADMMessageReceiver;

public class ADMMessageHandler extends ADMMessageHandlerBase {
    private static String savedMessage = null;
    private static int numberOfMissedMessages = 0;
    public static boolean inBackground = true;

    public ADMMessageHandler(){
        super(ADMMessageHandler.class.getName()); //ERROR!
    }

    ...
}

Which is derived from this class in Amazon's library:

package com.amazon.device.messaging.ADMMessageHandlerBase

import android.app.IntentService;
import android.content.Intent;

public abstract class ADMMessageHandlerBase extends IntentService {
    public ADMMessageHandlerBase(String var1) {
        super((String)null);
        throw new RuntimeException("Stub!");
    }

    protected final void onHandleIntent(Intent var1) {
        throw new RuntimeException("Stub!");
    }

    protected abstract void onMessage(Intent var1);

    protected abstract void onRegistrationError(String var1);

    protected abstract void onRegistered(String var1);

    protected abstract void onUnregistered(String var1);
}

I understand Amazon's class is a stub intended to be replaced by an actual implementation, but how is that done?. This is my build.gradle:

buildscript {
    repositories {
        mavenCentral() // or jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1+'
    }
}
apply plugin: 'com.android.application'
android {
    compileSdkVersion 18
    buildToolsVersion "23.0.1"

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
    }

    defaultConfig {
        applicationId "com.amazonaws.kindletest"
        minSdkVersion 11
        targetSdkVersion 18
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

And manifest:

<manifest xmlns:android="http://ift.tt/nIICcg"
    xmlns:amazon="http://ift.tt/1sA8Tkp"
    package="com.amazonaws.kindletest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

   <!-- This permission ensures that no other application can intercept your ADM messages. It
   should have the form packagename.permission.RECIEVE_ADM_MESSAGE where packagename is the
   name defined in the "package" property of the manifest tag. --> 
    <permission android:name="com.amazonaws.kindletest.permission.RECEIVE_ADM_MESSAGE"
        android:protectionLevel="signature"/>

    <!-- Required permissions -->
    <uses-permission android:name="com.amazonaws.kindletest.permission.RECEIVE_ADM_MESSAGE"/>
    <uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"        
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.amazonaws.kindletest.KindleMobilePushApp"
            android:screenOrientation="portrait"
            android:label="@string/title_activity_main"
            android:launchMode="singleTop" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Your application's API Key -->
        <meta-data android:name="AmazonAPIKey" android:value="@string/api_key"/>

        <!--  Declare your ADMMessageHandlerBase implementation as a service -->
        <service android:name="com.amazonaws.kindletest.ADMMessageHandler" 
            android:exported="false" />

        <!-- You must explicitly enable ADM. You must also declare whether your application will run with or without ADM.
        If you specify android:required="false", your app must degrade gracefully when ADM is unavailable. -->
        <amazon:enable-feature android:name="com.amazon.device.messaging" 
            android:required="true" />

        <receiver android:name="com.amazonaws.kindletest.ADMMessageHandler$MessageAlertReceiver" 
            android:permission="com.amazon.device.messaging.permission.SEND">
            <intent-filter>
               <action android:name="com.amazon.device.messaging.intent.REGISTRATION" /> 
               <action android:name="com.amazon.device.messaging.intent.RECEIVE" /> 
               <category android:name="com.amazonaws.kindletest"/>
            </intent-filter>
        </receiver>

    </application>

</manifest>

I have posted posted about this in Amazon's developer forum with no success yet. Please let me know if you need more information, thank you.




Aucun commentaire:

Enregistrer un commentaire