android动态库放在那,android动态库存放路径问题

首先来看下我们是如何使用自己的动态库:

public class MyActivity extends Activity {

/** Called when the activity is first created. */

//WebView webView;

public native int sum(int i, int j);

static{

System.loadLibrary("test");

}

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//setContentView(R.layout.main);

TextView tv = new TextView(this);

tv.setText("这是一个测试Android的helloWorld! sum() = " + sum(2, 3));

setContentView(tv);

}

}

@system.java

public static void loadLibrary(String libName) {

Runtime.getRuntime().loadLibrary(libName, VMStack.getCallingClassLoader());

}

@Runtime.java

private Runtime(){

String pathList = System.getProperty("java.library.path", ".");

String pathSep = System.getProperty("path.separator", ":");

String fileSep = System.getProperty("file.separator", "/");

mLibPaths = pathList.split(pathSep);

// Add a '/' to the end so we don't have to do the property lookup

// and concatenation later.

for (int i = 0; i < mLibPaths.length; i++) {

if (!mLibPaths[i].endsWith(fileSep)) {

mLibPaths[i] += fileSep;

}

}

}...

void loadLibrary(String libraryName, ClassLoader loader) {

if (loader != null) {

String filename = loader.findLibrary(libraryName);

if (filename == null) {

throw new UnsatisfiedLinkError("Couldn't load " + libraryName + ": " +

"findLibrary returned null");

}

String error = nativeLoad(filename, loader);

if (error != null) {

throw new UnsatisfiedLinkError(error);

}

return;

}

String filename = System.mapLibraryName(libraryName);

List candidates = new ArrayList();

String lastError = null;

for (String directory : mLibPaths) {

String candidate = directory + filename;

candidates.add(candidate);

if (new File(candidate).exists()) {

String error = nativeLoad(candidate, loader);

if (error == null) {

return; // We successfully loaded the library. Job done.

}

lastError = error;

}

}

if (lastError != null) {

throw new UnsatisfiedLinkError(lastError);

}

throw new UnsatisfiedLinkError("Library " + libraryName + " not found; tried " + candidates);

}

@System.java

public static String getProperty(String prop, String defaultValue) {

if (prop.isEmpty()) {

throw new IllegalArgumentException();

}

return getProperties().getProperty(prop, defaultValue);

}

public static Properties getProperties() {

if (systemProperties == null) {

initSystemProperties();

}

return systemProperties;

}

private static void initSystemProperties() {

VMRuntime runtime = VMRuntime.getRuntime();

Properties p = new Properties();

String projectUrl = "http://www.android.com/";

String projectName = "The Android Project";

p.put("java.boot.class.path", runtime.bootClassPath());

p.put("java.class.path", runtime.classPath());

// None of these four are meaningful on Android, but these keys are guaranteed

// to be present for System.getProperty. For java.class.version, we use the maximum

// class file version that dx currently supports.

p.put("java.class.version", "50.0");

p.put("java.compiler", "");

p.put("java.ext.dirs", "");

p.put("java.version", "0");

p.put("java.home", getenv("JAVA_HOME", "/system"));

p.put("java.io.tmpdir", "/tmp");

p.put("java.library.path", getenv("LD_LIBRARY_PATH"));

上面的系统环境变量“LD_LIBRARY_PATH”,在init.rc文件中进行配置

export LD_LIBRARY_PATH/vendor/lib:/system/lib

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值