简体   繁体   中英

java.lang.UnsatisfiedLinkError: in HTTP Get on Android

I'm executing a HTTP Get from an Async function and I keep getting this UnsatisfiedLinkError:-

Caused by: java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-universal-image-loader-1.9.5_5a96e3a3bb879858d826e5f3576c34ad5d6c1936-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-support-annotations-23.3.0_55d9fdcf7c91c0058d2cbcc7e08fd782b38fe66d-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-socialauth-android-3.2_9611dca6f615df1d34c2b5a60ba28a7611388175-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-socialauth-4.4_1b9c6d31199994c03c332e5e0578e2f0b2fe0c48-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_9-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_8-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_7-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_6-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_5-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_4-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_3-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_2-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_1-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-slice_0-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-simple-xml-2.7.1_f2a506737e8b5ed93d4b881fc0c6c7a35026d813-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-library-2.4.0_16c20551d1515298e4f820dbb2437cde217a49b7-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-ksoap2-android-assembly-3.6.1-jar-with-dependencies_a1a9b67170b6d055b09be56a35ddecd8b9faafce-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-internal_impl-23.3.0_e42bbcf06b9ce4060096cb8ce36b6ab3c865197c-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-httpclient-4.3.6_e4c2a7ccc6f36fc0c0b6db3cd84168431f19da97-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-guava-19.0_789e0cb8a020dcf43fb5056f93875e715c03d36c-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-gcm_4bcd93ef73ae7672956b56c7a5314a899b41e0a9-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-de.mrmaffen-vlc-android-sdk-1.9.8_183f7022a4ff9bc2fcad3ecf80fe616b030d8981-classes.dex", dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-com.github.ganfra-material-spinner-1.1.1_3c6f77a530740d43591c90873c9d9105e0afdcd9-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.3.0_a59a3afa176f79a2a84e41a6156deee0023dc2e8-classes.dex",
dex file "/data/data/com.myapp.myapp/files/instant-run/dex/slice-com.android.support-support-v4-23.3.0_95f566be28123c8c85ef97806b7b803eab311dd5-classes.dex", dex file "/data/data/com.myapp.myapp/f

The code I'm executing is simply as below (inside doInBackground) :-

 String url1 = "http://172.23.3.54:8054/Streaming/channels/102/preview";

 httpclient = new DefaultHttpClient();
 httpParams = httpclient.getParams();
 httpget = new HttpGet(URI.create(url1));
 HttpConnectionParams.setConnectionTimeout(httpParams, 5 * 1000);
 HttpConnectionParams.setSoTimeout(httpParams, 5 * 1000);
 Log.i(TAG, "1. Sending http request");

 credentials = new UsernamePasswordCredentials("admin", "12345");
 httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);


 try {
  res = httpclient.execute(httpget);
  Log.i(TAG, "2. Request finished, status = " + res.getStatusLine().getStatusCode() + ", " + res.getStatusLine().getReasonPhrase());

  try {
   InputStream is = res.getEntity().getContent(); //error occurs here
  } catch (IOException e) {
   e.printStackTrace();
  }

 } catch (IOException e) {
  e.printStackTrace();
 }

I can't seem to find much info about UnsatisfiedLinkError . I've tried rebuilding the project but to no avail. Would appreciate if someone can tell me the possible cause of this as the stack trace didn't provide much useful information.


Update

The error occurs only on my actual device (LG G4) and not on Nexus 4 AVD. It looks something like this.

在此处输入图片说明

Ok, I finally managed to solve this problem. First, I disabled instant run on Android studio. This somehow changed the error message that was produced:-

Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myapp.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.myapp-1/lib/arm64, /data/app/com.myapp.myapp-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libImageProc.so"

So it turns out that native libraries was missing.

In the end, I solved the problem by applying a filter in my gradle build.

defaultConfig {
...
    ndk {
        moduleName "ImageProc"
        abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
    }
}

What this does is specify only 32-bit architectures to be packaged.

In stead of HttpDefaultClient() to HttpUrlConnection You have to use because onw it's depricated. or if you use HttpDefaultClient() then you need to add library for HttpDefaultClient so i suggest you to use HttpUrlConnection.

private class DownloadWebpageTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {

        // params comes from the execute() call: params[0] is the url.
        try {
            return downloadUrl(urls[0]);
        } catch (IOException e) {
            return "Unable to retrieve web page. URL may be invalid.";
        }
    }
    // onPostExecute displays the results of the AsyncTask.
    @Override
    protected void onPostExecute(String result) {
        textView.setText(result);
   }
}


private String downloadUrl(String myurl) throws IOException {
InputStream is = null;
// Only display the first 500 characters of the retrieved
// web page content.
int len = 500;

try {
    URL url = new URL(myurl);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(10000 /* milliseconds */);
    conn.setConnectTimeout(15000 /* milliseconds */);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    // Starts the query
    conn.connect();
    int response = conn.getResponseCode();
    Log.d(DEBUG_TAG, "The response is: " + response);
    is = conn.getInputStream();

    // Convert the InputStream into a string
    String contentAsString = readIt(is, len);
    return contentAsString;

// Makes sure that the InputStream is closed after the app is
// finished using it.
} finally {
    if (is != null) {
        is.close();
    }
}

}

Reads an InputStream and converts it to a String.

public String readIt(InputStream stream, int len) throws IOException, UnsupportedEncodingException {
Reader reader = null;
reader = new InputStreamReader(stream, "UTF-8");
char[] buffer = new char[len];
reader.read(buffer);
return new String(buffer);

}

It may help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM