Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do some Android phones cause our app to throw an java.lang.UnsatisfiedLinkError?
    primarykey
    data
    text
    <p>We're experiencing a <code>java.lang.UnsatisfiedLinkError</code> on some of the Android phones that are using our app in the market.</p> <p><strong>Problem description:</strong></p> <pre><code>static { System.loadLibrary("stlport_shared"); // C++ STL System.loadLibrary("lib2"); System.loadLibrary("lib3"); } </code></pre> <p>Crashes the app in on of the <code>System.loadLibrary()</code> lines with a <code>java.lang.UnsatisfiedLinkError</code>. <code>java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared from loader dalvik.system.PathClassLoader[dexPath=/data/app/app_id-2.apk,libraryPath=/data/app-lib/app_id-2]: findLibrary returned null</code></p> <p><strong>Solution approach</strong></p> <p>We started running some custom diagnostics on all our installs to check if every lib is unpacked in the <code>/data/data/app_id/lib</code> folder.</p> <pre><code>PackageManager m = context.getPackageManager(); String s = context.getPackageName(); PackageInfo p; p = m.getPackageInfo(s, 0); s = p.applicationInfo.dataDir; File appDir = new File(s); long freeSpace = appDir.getFreeSpace(); File[] appDirList = appDir.listFiles(); int numberOfLibFiles = 0; boolean subFilesLarger0 = true; for (int i = 0; i &lt; appDirList.length; i++) { if(appDirList[i].getName().startsWith("lib")) { File[] subFile = appDirList[i].listFiles(FileFilters.FilterDirs); numberOfLibFiles = subFile.length; for (int j = 0; j &lt; subFile.length; j++) { if(subFile[j].length() &lt;= 0) { subFilesLarger0 = false; break; } } } } </code></pre> <p>On every test phone that we have <code>numberOfLibFiles == 3</code> and <code>subFilesLarger0 == true</code>. We wanted to test if all libs are unpacked properly and are larger then 0 byte. In addition we're looking at <code>freeSpace</code> to see how much disk space is available. <code>freeSpace</code> matches the amount of memory that you can find in Settings --> Applications at the bottom of the screen. The thinking behind this approach was that when there is not enough space on the disk available that the installer might have problems unpacking the APK.</p> <p><strong>Real world scenario</strong></p> <p>Looking at the diagnostics, some of the devices out there do <strong>NOT</strong> have all 3 libs in the <code>/data/data/app_id/lib</code> folder but have plenty of free space. I'm wondering why the error message is looking for <code>/data/app-lib/app_id-2</code>. All our phones store their libs in <code>/data/data/app_id/lib</code>. Also the <code>System.loadLibrary()</code> should use a consistent path across installation and loading the libs? How can I know where the OS is looking for the libs?</p> <p><strong>Question</strong></p> <p>Anyone experiencing problems with installing native libs? What work arounds have been successful? Any experience with just downloading native libs over the internet when they are not existent and storing them manually? What could cause the problem in the first place? </p> <p><strong>EDIT</strong></p> <p>I now also have a user who runs into this problem after an application update. The previous version worked fine on his phone, an after an update the native libs seem missing. Copying the libs manually seem to cause trouble as well. He is on android 4.x with a non rooted phone without custom ROM.</p> <p><strong>EDIT 2 - Solution</strong></p> <p>After 2 years of spending time on this problem. We came up with a solution that works well for us now. We open sourced it: <a href="https://github.com/KeepSafe/ReLinker" rel="noreferrer">https://github.com/KeepSafe/ReLinker</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload