【问题标题】:licence check for oreo奥利奥执照检查
【发布时间】:2018-09-23 17:37:54
【问题描述】:

对于新的 Android 应用更新,我必须将 compileSdkversion 设置为 26。

当我这样做时,我会在以下函数 (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;
}

我知道这些功能已经过时,但没有更新版本的 Android Vending Licensing 库,我无法找到如何使其适用于 Oreo,或者通常适用于高于 Android 19 的版本,即compileSdkversion我现在用。

谁能帮忙解决这个问题?

PS。 useLibrary 'org.apache.http.legacyuseLibrary 'org.apache.http.legacy 不工作。应用会直接崩溃。

【问题讨论】:

    标签: android licensing android-lvl


    【解决方案1】:

    尝试下一个:

    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;
    }
    

    【讨论】:

    • 但是应用程序在LicenseChecker.java文件中的许可检查过程中崩溃它跳转到文件ActivityThread,函数handleLaunchActivity。我在调试模式下收到一条消息:源代码与字节码不匹配
    • 您提到的“handleLaunchActivity”和“ActivityThread”方法不属于License Verification Library。请提供其余代码以了解问题。另一方面,如果出现“Source code does not match the byte code”错误,则意味着您需要重新构建项目,因为您在设备中安装的内容与项目本身不匹配。
    • compileSdkVersion 26 buildToolsVersion '28.0.2' minSdkVersion 14 targetSdkVersion 26
    • 通过重建项目,我的意思是按下重建按钮,并确保重建 LVL 库。 “Source code does not match the byte code”是指你的APK和Android Studio中的项目源代码不匹配。对整个项目进行干净的重建。
    • 在 LicenseChecker.java 文件中他跳出 function boolean bindResult = mContext.bindService( new Intent(ILicensingService.class.getName()), this, // ServiceConnection.Context.BIND_AUTO_CREATE);在来自 sdk android-26 的文件 ActivityThread 中运行 handleLaunchActivity 并得到消息“源代码与字节码不匹配”我使用了一个真正的 android 设备和 android 8.1