English 中文(简体)
我如何在安乐斯的运行时间进口共有的物体图书馆?
原标题:How do I import shared object libraries at runtime in Android?

I am developing an open-source emulator project, and it has multiple, customizable native plug-ins. These plug-ins are built as native shared object libraries (.so files), and have various interfaces between native and Java through JNI. Rather than distribute the APK with every single plug-in ever created, and in order to allow folks to build their own custom plug-ins, I need a method of importing these .so files any time after the app has been installed.

我发现,我可以向文件夹/数据/数据/[包装_名称]复制文件,但不能向校准/子夹(因为文件由“系统”集团所有)。 为了利用贾瓦的民族阵线接口,我必须使用该系统。 然而,这似乎要求将文件存放在校准/子夹中。 我认为,围绕这一点的唯一途径是要求用户拥有一个根深蒂固的装置。 是否有其他办法实现这一目标?

最佳回答

使用系统:

static
{
    final String[] libs = {
        "/data/data/com.foo.test/lib/liba.so",
        "/data/data/com.foo.test/lib/libb.so"
    };

    for (int i=0; i<libs.length; ++i)
    {
        Log.d(TAG, "Loading " + libs[i] + "...");
        System.load(libs[i]);
    }
}

ad

D/LibTest ( 1022): Loading /data/data/com.foo.test/lib/liba.so...
D/dalvikvm( 1022): Trying to load lib /data/data/com.foo.test/lib/liba.so 0x40512640
D/dalvikvm( 1022): Added shared lib /data/data/com.foo.test/lib/liba.so 0x40512640
D/dalvikvm( 1022): No JNI_OnLoad found in /data/data/com.foo.test/lib/liba.so 0x40512640, skipping init
D/LibTest ( 1022): Loading /data/data/com.foo.test/lib/libb.so...
D/dalvikvm( 1022): Trying to load lib /data/data/com.foo.test/lib/libb.so 0x40512640
D/dalvikvm( 1022): Added shared lib /data/data/com.foo.test/lib/libb.so 0x40512640
D/dalvikvm( 1022): No JNI_OnLoad found in /data/data/com.foo.test/lib/libb.so 0x40512640, skipping init

问题回答

• 散发你作为PK的原始材料,并通过国际太平洋共同体理事会机制从东道方向原始公司通报:

  • broadcast Intents
  • services (command or binding patterns)
  • ContentProvider

作为一种附带奖金,如果比东道方需要更多的/不同的许可,就会得到支持。

Admittedly, this will require IPC, which adds non-trivial overhead, steering you in the direction of a coarse-grained plugin communication protocol. And, it will use up more RAM (and the extra CPU time for the overhead will use up more battery life).

You can use dlopen for loading a so file with c++. I use this code in c++ to load so files in any folder.

// KGEmain function pointer
typedef void (*KGEmain) ();

std::string strPluginName = "/data/data/com.kge.android/lib/lib";
strPluginName += appname;
strPluginName += ".so";

void* handle = dlopen(strPluginName.c_str(), RTLD_LAZY);

const char* error;

if (!handle)
{
    LOGE("can t load the %s plugin. (%s)", strPluginName.c_str(), dlerror());
    return;
}
// Clear any exiting error
dlerror();

// Load the KGEmain function
pFn = (KGEmain)dlsym(handle, "KGEmain");
if ((error = dlerror()) != NULL || !pFn)
{
    LOGE("KGEmain function dose not find in %s plugin.
%s", strPluginName.c_str(), error);
    return;
}

pFn();




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签