0

According to google's documentation, google play billing should work on API 8 and later, but isn't working.

https://developer.android.com/google/play/billing/billing_overview

I implemented the basic guide from their github:
https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive_v2

then I removed everything I didn't need, kept the core and transport to my real app

everything seems to run fine in my tests but when i deploy to production a huge amount of crashes were launched even before load the first activity, during the app initialization:

Caused by java.lang.ClassNotFoundException: Didn't find class "com.android.org.conscrypt.OpenSSLRSAPublicKey" on path: DexPathList[[zip file "/data/app/com.tomatedigital.instagramgiveawaywinner-5.apk", zip file "/data/data/com.tomatedigital.instagramgiveawaywinner/code_cache/secondary-dexes/com.tomatedigital.instagramgiveawaywinner-5.apk.classes2.zip"],nativeLibraryDirectories=[/data/app-lib/com.tomatedigital.instagramgiveawaywinner-5, /vendor/lib, /system/lib]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
       at java.lang.Class.classForName(Class.java)
      at com.tomatedigital.giveawaymaster.billing.Security.generatePublicKey(Security.java:73)
       at com.tomatedigital.giveawaymaster.util.App$2.run(App.java:302)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
       at java.lang.Thread.run(Thread.java:841)

the method which fails is:

/**
 * Generates a PublicKey instance from a string containing the
 * Base64-encoded public key.
 *
 * @param encodedPublicKey Base64-encoded public key
 * @throws IllegalArgumentException if encodedPublicKey is invalid
 */
public static PublicKey generatePublicKey(String encodedPublicKey) {
    try {
        byte[] decodedKey = Base64.decode(encodedPublicKey, Base64.DEFAULT);
        KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
        return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (InvalidKeySpecException e) {
        Log.e(TAG, "Invalid key specification.");
        throw new IllegalArgumentException(e);
    }
}

this method is COPY/PASTE from google's example, no modifications on my side not even variables renaming...

my class itself doens't even import the missing class referred in the exception com.android.org.conscrypt.OpenSSLRSAPublicKey so it means this class is used by some of google's inner api call and was not included in the package avaible for import

implementation 'com.android.billingclient:billing:1.1'

my question is how to use google billing on android api lvl 15 - 18 (my app minimum api level is 15)?

what is the minimum package available i can import in order to provide all needed classes since google didn't?

i checked on maven and the conscrypt package itself is 5MB... i'm not willing to import 5MB of api since my WHOLE APP is 5MB i would make it twice bigger and it doesn't make sence because if there is any device still using android 4.3 or older it is a device with very limited resources and is not reasonable to have su much largger apk for it

===========UPDATE=============

i imported the dependency mentioned in comments but i'm still getting the same exception

olderImplementation 'org.conscrypt:conscrypt-android:1.2.0'
Rafael Lima
  • 3,079
  • 3
  • 41
  • 105
  • This looks like part of https://github.com/google/conscrypt and the package mentioned there is `implementation 'org.conscrypt:conscrypt-android:1.2.0'` 3.4MB according to https://mvnrepository.com/artifact/org.conscrypt/conscrypt-android/1.2.0. But before importing anything have you tried to run the release apk, to see if it is reproducible? Do you have minification enabled? – madlymad Oct 14 '18 at 21:53
  • the error is reproducible as i described only on api below 19... i dont have minification enabled – Rafael Lima Oct 15 '18 at 13:18

0 Answers0