question

Amit avatar image
Amit asked

Invalid API Key for Android Sample app

Hi,

I am trying to integrate AVS in my android app by following this tutorial for the beginners.

https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/getting-started-with-the-alexa-voice-service.

I followed each step but when I run my app on Nexus5 I get below error:

08-12 14:28:43.431 26749-26749/com.example.asingh.voicesearch D/com.amazon.identity.auth.device.authorization.api.AmazonAuthorizationManager.PII: AmazonAuthorizationManager:sdkVer=2.0.1 libVer=3.5.1:<obscured>
08-12 14:28:43.431 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier: getAppInfo : packageName=com.example.asingh.voicesearch
08-12 14:28:43.431 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier: getAppInfoFromAPIKey : packageName=com.example.asingh.voicesearch
08-12 14:28:43.431 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.AbstractAppIdentifier: Finding API Key for com.example.asingh.voicesearch
08-12 14:28:43.431 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.utils.ThirdPartyResourceParser: Attempting to parse API Key from assets directory
08-12 14:28:43.432 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.APIKeyDecoder: Begin decoding API Key for packageName=com.example.asingh.voicesearch
08-12 14:28:43.432 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.APIKeyDecoder: getKeyParts for packageName=com.example.asingh.voicesearch
08-12 14:28:43.432 26749-26749/com.example.asingh.voicesearch D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: APIKey:<obscured>
08-12 14:28:43.432 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.APIKeyDecoder: verifySignature for packageName=com.example.asingh.voicesearch
08-12 14:28:43.432 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.APIKeyDecoder: verifySignature Sha256 for packageName=com.example.asingh.voicesearch
08-12 14:28:43.434 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.APIKeyDecoder: verifyPayload for packageName=com.example.asingh.voicesearch
08-12 14:28:43.434 26749-26749/com.example.asingh.voicesearch D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Signature checking.:<obscured>
08-12 14:28:43.442 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.APIKeyDecoder: num sigs = 1
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Fingerprint checking:<obscured>
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch I/com.amazon.identity.auth.device.appid.APIKeyDecoder:  num sigs = 1
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Fingerpirints checking:<obscured>
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Failed to decode: Decoding fails: certificate fingerprint can't be verified! pkg=com.example.asingh.voicesearch
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Unable to decode APIKEy for pkg=com.example.asingh.voicesearch
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err: java.lang.IllegalArgumentException: Invalid API Key
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at com.amazon.identity.auth.device.authorization.api.AmazonAuthorizationManager.<init>(AmazonAuthorizationManager.java:133)
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at com.example.asingh.voicesearch.MainActivity.onCreate(MainActivity.java:101)
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.Activity.performCreate(Activity.java:6251)
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4077)
08-12 14:28:43.443 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.ActivityThread.-wrap15(ActivityThread.java)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.os.Looper.loop(Looper.java:148)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-12 14:28:43.444 26749-26749/com.example.asingh.voicesearch E/Amit: Unable to use Amazon Authorization Manager. APIKey is incorrect or does not exist.
                                                                      java.lang.IllegalArgumentException: Invalid API Key
                                                                          at com.amazon.identity.auth.device.authorization.api.AmazonAuthorizationManager.<init>(AmazonAuthorizationManager.java:133)
                                                                          at com.example.asingh.voicesearch.MainActivity.onCreate(MainActivity.java:101)
                                                                          at android.app.Activity.performCreate(Activity.java:6251)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                          at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4077)
                                                                          at android.app.ActivityThread.-wrap15(ActivityThread.java)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:148)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

What I am missing here? I generated the api key successfully and same is placed as api_key.txt in the assets folder.

Additionally in instruction it's not mention about ca.crt to place in raw directory but I have placed it in order to resolve the compilation error. Can the error be linked with this?

Really appreciate any help.

alexa voice serviceandroidjava
1 comment
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I am located in India. Can location be a problem?

0 Likes 0 ·
Eric@Amazon avatar image
Eric@Amazon answered

How did you create the api_key.txt? Can you double-check it for whitespace? That often causes problems.

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

stephen avatar image
stephen answered

Hi Amit,

I have the same problem. Can you tell me how to solve it in the end?

Thank you very much!

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

stephen avatar image
stephen answered

Hi,

My log info is below:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ding.sign/com.ding.sign.SampleLoginWithAmazonActivity}: java.lang.IllegalArgumentException: Invalid API Key
                                                   
...
 Caused by: java.lang.IllegalArgumentException: Invalid API Key

10-18 02:17:14.022 6628-6628/? I/com.amazon.identity.auth.device.appid.APIKeyDecoder: Begin decoding API Key for packageName=com.ding.sign
10-18 02:17:14.039 6628-6628/? D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: APIKey:<obscured>
10-18 02:17:14.039 6628-6628/? I/com.amazon.identity.auth.device.appid.APIKeyDecoder: verifyPayload for packageName=com.ding.sign
10-18 02:17:14.040 6628-6628/? D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Validating MD5 signature in API key:<obscured>
10-18 02:17:14.044 6628-6628/? I/com.amazon.identity.auth.device.appid.APIKeyDecoder: Number of signatures = 1
10-18 02:17:14.044 6628-6628/? D/com.amazon.identity.auth.device.appid.APIKeyDecoder.PII: Fingerprint checking:<obscured>
10-18 02:17:14.045 6628-6628/? W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Failed to decode: Decoding failed: certificate fingerprint can't be verified! pkg=com.ding.sign
10-18 02:17:14.045 6628-6628/? W/com.amazon.identity.auth.device.appid.APIKeyDecoder: Unable to decode APIKey for pkg=com.ding.sign
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Krishna Meena avatar image
Krishna Meena answered

I am also facing same issue

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-0592ab28-4694-46d1-b530-cc01fdf99703 avatar image
newuser-0592ab28-4694-46d1-b530-cc01fdf99703 answered

Any solution for this

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.