Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:06:11+00:00 2026-06-15T21:06:11+00:00

I’ve wrote android app with native shared library ( libnativeext.so ). Inside java class

  • 0

I’ve wrote android app with native shared library ( libnativeext.so ).

Inside java class in app I load libnativeext.so with
System.loadLibrary(“nativeext”).
All works great.
Native code compiles, and libnativeext.so places in /libs/armeabi/ folder.
So final first.apk file contains /lib/armeabi/libnativeext.so, installs on device and all work ok.

Then I export project in javaext.jar.

At this point javaext.jar contains libnativeext.so in /libs/armeabi/.

In the new project (second-proj) I include javaext.jar and add path to javaext.jar in java build path.
Project builds with only warning about native library in javaext.jar.
I disable warning in eclipse preferences.

But on device I got: java.lang.UnsatisfiedLinkError: Couldn’t load nativeext: findLibrary returned null

Strange, because second.apk have /libs/armeabi/libnativeext.so inside. I go to phone and figure out than folder on phone /data/data/myapp/lib/ is EMPTY! And ofcourse System.loadLibrary can’t find libnativeext.so.

I find solution for myself, but it looks very ugly, and I want to find better way.

I create inside existing second-proj/libs/ folder armeabi and place libnativeext.so inside.

second-proj:
/libs/armeabi/libnativeext.so
/libs/javaext.jar

When I build project, I look inside second.apk:

/lib/armeabi/libnativeext.so <— new one
/libs/armeabi/libnativeext.so

And this version work perfect on the phone.

So I assume, that during installation libraries from /libs/armeabi/ is ignored, and only libraries from /lib/armeabi/ is installed on the phone.

So question is: How to force apk bulder to copy *.so from *.jar to right *.apk folder?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:06:13+00:00Added an answer on June 15, 2026 at 9:06 pm

    In case there are no way to pack *.so library from included *.jar into final *.apk I solve this problem for myself.

    I write LibraryLoader, which:

    1. Tries to load library with System.loadLibrary().

    2. If it fails, loader search library in application storage, and if find loads it with System.load().

    3. If no library was found in the app storage, it find .apk file, serch there, and if loader find library – copies it to app storage, then loads it with System.load().

    Post code here – may be it helps somebody.

        import java.io.BufferedOutputStream;
        import java.io.File;
        import java.io.FileOutputStream;
        import java.io.IOException;
        import java.io.InputStream;
        import java.io.OutputStream;
        import java.util.Enumeration;
        import java.util.zip.ZipEntry;
        import java.util.zip.ZipFile;
    
        import android.content.Context;
        import android.util.Log;
    
        public class SharedLibraryLoader
        {
            private static Context context;
            private static String libDir = "lib";
            private static String shortLibName;
            private static String fullLibName;
    
            static public boolean loadLibrary(String libName, Context ctx)
            {
        context = ctx;
        shortLibName = libName;
        fullLibName = "lib" + libName + ".so";
    
        try
        {
            Log.d("SharedLibraryLoader", "Trying to load library");
            System.loadLibrary(shortLibName);
            Log.d("SharedLibraryLoader", "Library was loaded from default location");
            return true;
        }
        catch(UnsatisfiedLinkError e)
        {
            Log.d("SharedLibraryLoader","Lib wasn't found at default location. Trying to find in application private storage");
            String path = null;
            path = findInAppStorage(fullLibName);
            if(path != null)
            {
                Log.d("SharedLibraryLoader","Lib was found in application private storage. Loading lib...");
                System.load(path);
                return true;
            }
            else
            {
                Log.d("SharedLibraryLoader","Lib was not found in application private storage. Trying to find in apk...");
                path = findInApkAndCopyToAppStorage(fullLibName);
    
                if(path != null)
                {
                    Log.d("SharedLibraryLoader","Lib was found in apk and copied to application private storage. Loading lib...");
                    System.load(path);
                    return true;
                }
                else
                {
                    Log.d("SharedLibraryLoader", "FAILED TO LOAD LIBRARY");
                    return false;
                }
            }
        }
            }
    
            static private String findInAppStorage(String libName)
            {
    
        Log.d("SharedLibraryLoader","enter findInAppStorage()");
        String basePath = context.getApplicationInfo().dataDir;
        File dataDir = new File(basePath);
    
        String[] listFiles;
        String  lib = null;
        listFiles = dataDir.list();
    
    
        for(int i=0; i < listFiles.length; i++)
        {
            lib = findInStorage(basePath + "/" +listFiles[i], libName);
    
            if(lib != null)
            {
                return lib;
            }
                }
    
        Log.d("SharedLibraryLoader", "Lib wasn't found.");
        return null;
            }
    
            static private String findInStorage(String path, String nameOfLib)
            {
        File file = new File(path);
        if(file.isDirectory())
        {
            Log.d("SharedLibraryLoader","Strorage__dir: " + path + "/");
            String[]    list = file.list();
            String      target = null; 
            for(int i = 0; i < list.length; i++)
            {
                target = findInStorage(path + "/" + list[i], nameOfLib);
                if(target != null)
                {
                    return target;
                }
            }
        }
        else
        {
            Log.d("SharedLibraryLoader","Strorage_file: " + path);
            if(path.contains(nameOfLib))
            {
                Log.d("SharedLibraryLoader","Lib was found in: " + path);
                return path;
            }
        }
        return null;
            }
    
            static private String findInApkAndCopyToAppStorage(String libName)
            {
                Log.d("SharedLibraryLoader", "Enter findInApkAndCopyToStorage()");
    
                // ---------------- ZIP - find path to .so  inside .apk ------------------
        String apkPath = context.getPackageResourcePath();
        Log.d("SharedLibraryLoader", String.format("Path to Package resource is: %s", apkPath));
    
        try
        {
            ZipFile zf = new ZipFile(apkPath);
    
            Enumeration<ZipEntry> zipFiles = (Enumeration<ZipEntry>) zf.entries();
            ZipEntry    soZipEntry = null;
            ZipEntry    tempZipEntry;
            String      tmpString;
            for ( ; zipFiles.hasMoreElements();)
            {
                tempZipEntry = zipFiles.nextElement(); 
                tmpString = tempZipEntry.getName();
    
                if(tmpString.contains(libName))
                {
                    Log.d("SharedLibraryLoader", "Library " + fullLibName + " was found in: " + tmpString);
                    soZipEntry = tempZipEntry;
                }
            }
    
            //----------now copy library---------------
            Log.d("SharedLibraryLoader", "soZipEntry = " + soZipEntry.toString());
    
            if(soZipEntry != null)
            {
                InputStream soInputStream = zf.getInputStream(soZipEntry);
    
                File fileDir;
                File soFile;
                OutputStream outStream;
                fileDir = context.getApplicationContext().getDir(libDir, Context.MODE_PRIVATE); // but "app_lib" was created!
                String fullSoFilePath = fileDir.getAbsolutePath() + "/" + libName;
                Log.d("SharedLibraryLoader", "New libpath is "+ fullSoFilePath);
                soFile = new File(fullSoFilePath);
    
                Log.d("SharedLibraryLoader", "Is file already exists? - " + soFile.exists());
    
                outStream = new BufferedOutputStream(new FileOutputStream(soFile));
    
                Log.d("SharedLibraryLoader", "Start copying library...");
                byte[] byteArray = new byte[256];
                int copiedBytes = 0;
    
                while((copiedBytes = soInputStream.read(byteArray)) != -1)
                {
                    outStream.write(byteArray, 0, copiedBytes);
                }
    
                Log.d("SharedLibraryLoader", "Finish copying library");
                outStream.close();
    
                soInputStream.close();
                return fullSoFilePath;
            }
            else
            {
                Log.d("SharedLibraryLoader", "Library not Found in APK");
                return null;
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return null;
        }
            }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.