Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key manipulation InvalidKeySpecException #10

Closed
jpardogo opened this issue Jan 11, 2017 · 7 comments
Closed

Key manipulation InvalidKeySpecException #10

jpardogo opened this issue Jan 11, 2017 · 7 comments

Comments

@jpardogo
Copy link

jpardogo commented Jan 11, 2017

I'm pretty curious about why you deal this way with the string key for google in app. I'm getting 'InvalidKeySpecException', an example project with the library would help.

https://github.com/eggheadgames/android-in-app-payments/blob/1.2.8/library/src/main/java/com/billing/google/GoogleBillingService.java#L40

@jpardogo jpardogo reopened this Jan 11, 2017
@mikemee
Copy link
Collaborator

mikemee commented Jan 11, 2017

Hi @jpardogo! Yes, a sample project is a great idea.

Here's some code from one of our apps that lives in the activity that displays the items to purchase. Because we build both Amazon and Google from the same codebase, we rely on the Gradle flavor mechanism for that.

Hopefully this will get you started.

    private void initIap() {
        String iapKey;
        int iapBuildTarget;

        if ("amazon".equals(BuildConfig.FLAVOR)) {
            iapKey = "";
            iapBuildTarget = IAPManager.BUILD_TARGET_AMAZON;
        } else if ("google".equals(BuildConfig.FLAVOR)) {
            iapKey = "***** INSERT YOUR GOOGLE IAP KEY HERE ******";
            iapBuildTarget = IAPManager.BUILD_TARGET_GOOGLE;
        } else {
            return;
        }

        List<String> iapKeys = yourFunctionToGetIapKeys();
        IAPManager.build(this, iapBuildTarget, iapKeys);
        IAPManager.addPurchaseListener(this);
        IAPManager.init(iapKey, BuildConfig.DEBUG);
    }

Does that help?

@mikemee
Copy link
Collaborator

mikemee commented Jan 11, 2017

@jpardogo from further reading here, https://stackoverflow.com/questions/32428947/android-in-app-billing-error-invalidkeyspecexception, it sounds like your key is likely invalid somehow. As this library doesn't really do anything except pass it through, we don't have much control.

@jpardogo
Copy link
Author

Hi, yes the library was modifying the string key I passed as a parameter (I debug it and confirmed it).
I basically add the project as a module and remove the for loop and pass the key and it works. I don't see the need of the for loop.

Other improvements that could be good:

  • Have different function for amazon and google when it is the case, such as:
public static void init(boolean enableLogging) {
   init(null, enableLogging)
}

public static void init(String key, boolean enableLogging) {
   if(key!=null){        
      billingService.init(key);
   }
   billingService.enableDebugLogging(enableLogging);
}
  • Create an onError callback for errors on the listeners, here:

https://github.com/eggheadgames/android-in-app-payments/blob/1.2.8/library/src/main/java/com/billing/google/GoogleBillingListener.java#L54

and here:

https://github.com/eggheadgames/android-in-app-payments/blob/1.2.8/library/src/main/java/com/billing/amazon/AmazonBillingListener.java#L59

  • Callbacks on the main thread, like onPricesUpdated

@mikemee
Copy link
Collaborator

mikemee commented Jan 11, 2017

@jpardogo Thanks for the several great ideas there. I've created new issues:

I'm not sure why the for-loop is there either. As far as I know, this is the exact same sample code that Google provides for IAP in multiple places. I wonder why they bother to rebuild the key? I'm hesitant to change their code without understanding why. Do you know what section of your key it was changing and why?

@jpardogo
Copy link
Author

I guess they where sending the IAP key in an specific format and the app was decoding it, with the for loop, this way the real inapp key wasn't store as a plain string on the source code.
But again, It is just an idea, I would need to check the source code of this example to be sure.

Also we can follow the same init method strategy for other end points where some arguments are not required for amazon or Google.

@jpardogo
Copy link
Author

jpardogo commented Jan 11, 2017

I would send all callback in the main thread and the user will take care of doing anything they want with its own threading strategy.

Also the onError callback is useful for error user feedback, not only debuging.

Great lib by the way, with a bit of work it could be awesome.

@mikemee
Copy link
Collaborator

mikemee commented Jun 2, 2020

The only item left here is covered in #12, which we're not going to do in this round of releases (see comments there). Closing this for now.

@jpardogo Thanks again for your ideas and feedback. They really helped to improve this library!

@mikemee mikemee closed this as completed Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants