【问题标题】:Android App Licensing crashes on Android PieAndroid 应用许可在 Android Pie 上崩溃
【发布时间】:2018-08-25 19:15:03
【问题描述】:

错误提示找不到URLEncodedUtils。有没有解决办法。

Caused by java.lang.ClassNotFoundException
    Didn't find class "org.apache.http.client.utils.URLEncodedUtils" on path: DexPathList[[zip file "/data/app/com.app.p-MY70To6m946K0_uiYLCsSg==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.p-MY70To6m946K0_uiYLCsSg==/lib/arm64, /data/app/com.app.p-MY70To6m946K0_uiYLCsSg==/base.apk!/lib/arm64-v8a, /system/lib64]]

【问题讨论】:

标签: android android-app-licensing


【解决方案1】:

Apache 库已被删除。如果您以前使用过

useLibrary 'org.apache.http.legacy 

在您的 build.gradle 中,它不再适用于 Android Pie。

相反,您必须添加

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

致您的AndroidManifest

有关官方发行说明,请参阅 here

【讨论】:

  • 我的应用程序需要两者,我猜是因为我的 targetSdkVersion 高而 minSdkVersion 低。
【解决方案2】:

Google 不支持旧版 apache 库,因此在原始类 APKEpansionPolicy 中,此方法使用 URLEncodedUtilsNameValuePair

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) {
                String name = item.getName();
                int i = 0;
                while (results.containsKey(name)) {
                    name = item.getName() + ++i;
                }
                results.put(name, item.getValue());
            }
        } catch (URISyntaxException e) {
            Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
        }
        return results;
    }

用这段分割查询并使用Map而不是NameValuePair的代码替换这个类和任何其他类中的这个方法。

private Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<String, String>();
    try {
        URI rawExtras = new URI("?" + extras);
        Map<String, String> extraList = splitQuery(new URL(rawExtras.toString()));
        for (Map.Entry<String, String> entry : extraList.entrySet())
        {
            String name = entry.getKey();
            int i = 0;
            while (results.containsKey(name)) {
                name = entry.getKey() + ++i;
            }
            results.put(name, entry.getValue());
        }
    } catch (URISyntaxException e) {
        Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return results;
}

public static Map<String, String> splitQuery(URL url) throws UnsupportedEncodingException {
    Map<String, String> query_pairs = new LinkedHashMap<String, String>();
    String query = url.getQuery();
    String[] pairs = query.split("&");
    for (String pair : pairs) {
        int idx = pair.indexOf("=");
        query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
    }
    return query_pairs;
}

【讨论】:

    【解决方案3】:

    我想知道这在 Pie 上是否仍然可用,但除了其他可能重复的问题的建议之外,还有一个 Gradle 配置:useLibrary 'org.apache.http.legacy',以便使用遗留类(虽然仍然可用)。否则,一般来说,迁移到 okhttp3 可能仍然是最佳选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-02
      • 2019-05-10
      • 1970-01-01
      • 2020-01-09
      • 2020-12-27
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多