[Solved] Unable to instantiate receiver com.amazon.inapp.purchasing.ResponseReceiver

I’m trying to implement Unity IAP for use with Amazon AppStore (not underground). I have my implementation successfully working already with Google Play and iTunes Connect.

Unity version: 5.4.0f3 and the latest UnityPurchase plugin (as of 28th Nov 2016). I’m testing with a 4th generation Fire tablet using Live App Testing.

After doing a purchase for a consumable item I get the following error in logcat and the app crashes:

11-28 16:11:59.282 19223-19223/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.companyname.myapp, PID: 19223
java.lang.Error: FATAL EXCEPTION [main]
Unity version : 5.4.0f3
Device model : Amazon KFTHWI
Device fingerprint: Amazon/thor/thor:4.4.3/KTU84M/13.4.5.5_user_455004220:user/release-keys

Caused by: java.lang.RuntimeException: Unable to instantiate receiver com.amazon.inapp.purchasing.ResponseReceiver: java.lang.ClassNotFoundException: Didn’t find class “com.amazon.inapp.purchasing.ResponseReceiver” on path: DexPathList[[zip file “/data/app/com.companyname.myapp-1.apk”, zip file “/system/priv-app/MetricsApi-2066310.apk”, zip file “/system/priv-app/com.amazon.dp.logger.apk”],nativeLibraryDirectories=[/data/app-lib/com.companyname.myapp-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2493)
at android.app.ActivityThread.access$1700(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5266)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:826)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:642)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.amazon.inapp.purchasing.ResponseReceiver” on path: DexPathList[[zip file “/data/app/com.companyname.myapp-1.apk”, zip file “/system/priv-app/MetricsApi-2066310.apk”, zip file “/system/priv-app/com.amazon.dp.logger.apk”],nativeLibraryDirectories=[/data/app-lib/com.companyname.myapp-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2488)
at android.app.ActivityThread.access$1700(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5266)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:826)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:642)
at dalvik.system.NativeStart.main(Native Method)
11-28 16:11:59.332 920-1106/? W/ActivityManager: Force finishing activity com.companyname.myapp/.MyAppUnityPlayerActivity
11-28 16:11:59.412 920-1267/? I/WindowState: WIN DEATH: Window{41c08578 u0 com.companyname.myapp/com.companyname.myapp.MyAppUnityPlayerActivity}

I unpacked the APK I submitted to Live App Testing and it has the following response receiver automatically inserted into the AndroidManifest.xml by Unity during build time but it doesn’t match the actual error above: Unable to instantiate receiver com.amazon.inapp.purchasing.ResponseReceiver:

I seemed to have got around the issue by including the following in my AndroidManifest.xml:

 <receiver android:name="com.amazon.inapp.purchasing.ResponseReceiver"
      android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY">
      <intent-filter>
              <action android:name="com.amazon.inapp.purchasing.NOTIFY" />
      </intent-filter>
    </receiver>

and including a dummy Java class in one of the custom JARs I include in my Android version:

package com.amazon.inapp.purchasing;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ResponseReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    }
}