0

For new Android app updates I have to set the compileSdkversion to 26.

When I do this than I get problems with vending licency library, in the following function (ServerManagedPolicy.java) :

private Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<String, String>();
    try {
        URI rawExtras = new URI("?" + extras);
        List<**NameValuePair**> extraList = 
        **URLEncodedUtils**.parse(rawExtras, "UTF-8");
        for (**NameValuePair** item : extraList) {
            results.put(item.getName(), item.**getValue**());
        }
    } catch (URISyntaxException e) {
        Log.w(TAG, "Invalid syntax error while decoding extras data 
        from server.");
    }
    return results;
}

I know that these functions are obsolete but there is no updated version of the Android Vending Licensing library and I can nowhere find how to make it working for Oreo, or in general for versions higher than Android 19 which is the compileSdkversion I use now.

Any who can help with this?

PS. useLibrary 'org.apache.http.legacyuseLibrary 'org.apache.http.legacy is not working. The app will crash directly.

Machavity
  • 30,841
  • 27
  • 92
  • 100
fausteric
  • 23
  • 4

1 Answers1

0

Try next:

import java.net.URLDecoder;

private static Map<String, String> decodeExtras(final String extras)
{
    final Map<String, String> results = new HashMap<>();

    try
    {
        if (TextUtils.isEmpty(extras) == false)
        {
            final String[] pairs = extras.split("&");

            if (pairs.length > 0)
            {
                for (final String pair : pairs)
                {
                    final int index = pair.indexOf('=');
                    final String name = URLDecoder.decode(pair.substring(0, index), "UTF-8");
                    final String value = URLDecoder.decode(pair.substring(index + 1), "UTF-8");

                    results.put(name, value);
                }
            }
        }
    }
    catch (UnsupportedEncodingException e)
    {
        Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
    }

    return results;
}
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
  • But the app crashes during the licence check in file LicenseChecker.java It jumps to file ActivityThread, function handleLaunchActivity. I get a message, in debug mode: Source code does not match the byte code – fausteric Sep 24 '18 at 18:55
  • The method you mention "handleLaunchActivity" and "ActivityThread" are not part of the License Verification Library. Please supply the rest of the code to understand the issue. On the other hand if you get a "Source code does not match the byte code" error, it means you need to rebuild the project, because what you have installed in the device and the project itself do no match. – PerracoLabs Sep 24 '18 at 19:57
  • compileSdkVersion 26 buildToolsVersion '28.0.2' minSdkVersion 14 targetSdkVersion 26 – fausteric Sep 25 '18 at 18:23
  • By rebuild the project I meant to press the rebuild button, and ensure also to rebuild the LVL library. "Source code does not match the byte code" means that your APK and the project source code in Android Studio don't match. Do a clean rebuild of the full project. – PerracoLabs Sep 25 '18 at 18:26
  • In the LicenseChecker.java file he is jumping out function boolean bindResult = mContext.bindService( new Intent(ILicensingService.class.getName()), this, // ServiceConnection. Context.BIND_AUTO_CREATE); to function handleLaunchActivity in file ActivityThread which is from sdk android-26 and get the message "Source code does not match the byte code" I used a real android device with android 8.1 – fausteric Sep 25 '18 at 18:31
  • First i did a clean and a re-build. – fausteric Sep 25 '18 at 18:31
  • How are you using the LVL library as an external library? jar? embedded directly into the project? did you rebuild the LVL library too? Can you publish the full stacktrace of the error? In addition please look at this answer for the byte code problem: https://stackoverflow.com/questions/39990752/source-code-does-not-match-the-bytecode-when-debugging-on-a-device – PerracoLabs Sep 25 '18 at 18:37
  • LVL library is embedded directly into the project. So it will be also rebuild i think? – fausteric Sep 25 '18 at 18:49
  • Yes it will rebuild. Look at the next answer for the byte code problem. And if you get a crash then supply the full stack trace so we can look at it: https://stackoverflow.com/questions/39990752/source-code-does-not-match-the-bytecode-when-debugging-on-a-device/40566459 – PerracoLabs Sep 25 '18 at 18:55
  • Forgot to mention, when you say that is embedded directly, I'm assuming that your LVL source code is also part of your main project. In such case yes it will rebuild. If the library is embedded in a different way, then ensure you rebuild the LVL correctly. – PerracoLabs Sep 25 '18 at 19:07
  • Where can I put the stack trace? Here is a small part: D/FA: Permission not granted: android.permission.ACCESS_NETWORK_STATE D/FA: Permission not granted: android.permission.ACCESS_NETWORK_STATE E/FA: App is missing ACCESS_NETWORK_STATE permission E/FA: Uploading is not possible. App measurement disabled V/FA: onActivityCreated I/LicenseChecker: Binding to licensing service. D/AndroidRuntime: Shutting down VM – fausteric Sep 25 '18 at 19:22
  • I added ACCESS_NETWORK_STATE but still it crashed – fausteric Sep 25 '18 at 19:28
  • Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.licensing.ILicensingService } – fausteric Sep 25 '18 at 19:29
  • This is the function where it goes wrong: boolean bindResult = mContext.bindService( new Intent(ILicensingService.class.getName()), this, // ServiceConnection. Context.BIND_AUTO_CREATE); – fausteric Sep 25 '18 at 19:32
  • The problem is that the LVL is still using implicit Intents which are not supported with the latest android versions, and the library was never updated. Right affter the Intent gets created with serviceIntent = new Intent(context, service), and before calling mContext.bindService(...) add this line: serviceIntent.setPackage("com.android.vending"); this will make the Intent explicit. – PerracoLabs Sep 25 '18 at 19:38