Android的远程code装 [英] Android remote code loading
问题描述
我正在开发一个图书馆为Android,需要从中央服务器频繁的更新。我想这将是多么好的是,如果我的图书馆会自动更新 - 或者,如果我可以只发布一个引导库,下载安装应用程序时的目标库
I am developing a library for Android that requires frequent updates from a central server. I was thinking how nice it would be if my library could update itself -- or if I could just release a bootstrap library that downloads the target library when the app is installed.
我看到这个类在1.5被称为DexClassLoader,但似乎有precious一点除了API文档在网络上。有没有人使用这个成功地为我描述的场景?
I see this class in 1.5 called "DexClassLoader" but there seems to be precious little on the web besides the API docs. Has anyone used this successfully for the scenario which I described?
另外,不要在Android Market的条款允许这样的事?
Also, do the terms of the Android Market permit such a thing?
推荐答案
我已经成功地使用 DexClassLoader 。重要的是要提供一个 dexOutputDir
这是你的应用程序实际上写的,所以不可以 /数据/达尔维克缓存
。否则,日志将显示一行或两行约没有写在那里,然后按 ClassNotFoundException的
。
I've successfully used DexClassLoader. It's important to provide a dexOutputDir
that is actually writeable by your app, so not /data/dalvik-cache
. Otherwise the log will show one or two lines about failing to write there, followed by ClassNotFoundException
.
cl = new DexClassLoader("/full/path/com.example.apk",
getFilesDir().getAbsolutePath(),// /data/data/foo/files
null, // native lib path, I haven't used this
MyClass.class.getClassLoader());
// This doesn't make Class.forName() work, instead I do this:
Class<?> foo = cl.loadClass("com.example.foo");
若要的Class.forName()
的工作,你可以尝试<一href="http://developer.android.com/reference/java/lang/Thread.html#setContextClassLoader%28java.lang.ClassLoader%29">Thread.setContextClassLoader() (我没有)。
To make Class.forName()
work, you could try Thread.setContextClassLoader() (I haven't).
这篇关于Android的远程code装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!