Android Pie上的Android应用许可崩溃

mjo*_*osh 5 android android-app-licensing

错误消息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]]
Run Code Online (Sandbox Code Playgroud)

ami*_*mit 5

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

useLibrary 'org.apache.http.legacy 
Run Code Online (Sandbox Code Playgroud)

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

相反,您必须添加

<uses-library android:name="org.apache.http.legacy" android:required="false"/>
Run Code Online (Sandbox Code Playgroud)

给你AndroidManifest

请参阅此处以获取官方发行说明


mjo*_*osh 3

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;
    }
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)