如何在Android应用中运行打包的二进制文件? [英] How do I run my packaged binary in my Android app?

查看:191
本文介绍了如何在Android应用中运行打包的二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,需要运行我编写的自定义二进制应用程序.我已经使用ndk构建了二进制文件,并将其打包在res/raw下的apk中.

我做了类似的事情来首先运行su程序.

 处理过程;进程= Runtime.getRuntime().exec("su");DataOutputStream os = new DataOutputStream(process.getOutputStream()); 

此后如何从资源运行二进制文件?这里还有一个问题建议使用AssetManager,但我不知道该怎么做.我签出了一些打包有二进制文件的开源应用程序(例如android-wifi-tether等),但在其源代码的任何地方都看不到AssetManager,也不了解他们的工作方式.

解决方案

添加到David Given的响应中,这很棒,这是我在Android.mk末尾使用的自动重命名二进制文件的方法.可能对其他尝试相同操作的人有用:

  ...LOCAL_MODULE:= yourbinaryname此处包括$(BUILD_EXECUTABLE)全部:$(LOCAL_MODULE)$(shell(MV libs/$(TARGET_ARCH_ABI)/$< libs/$(TARGET_ARCH_ABI)/lib$<.so)) 

根据标准GNU Make,在$(shell ...空格之前请注意TAB.

I have an Android app that needs to run a custom binary app I wrote. I already built the binary using ndk and packaged it in the apk under res/raw

I did something like this to first run the su process.

Process process;
process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());

What do I do after this to run the binary from resources? There was another question here that suggested the use of AssetManager but I don't understand how to do it exactly. I checked out some opensource Apps (android-wifi-tether, etc.) that have binaries packaged with them and I don't see AssetManager anywhere in their source and don't understand how exactly they're doing it.

解决方案

Adding to David Given's response, which is great, this is what I use at the end of Android.mk to rename the binary automatically. May be of some use to others trying the same thing:

...
LOCAL_MODULE := yourbinarynamehere

include $(BUILD_EXECUTABLE)

all: $(LOCAL_MODULE)
    $(shell (mv libs/$(TARGET_ARCH_ABI)/$< libs/$(TARGET_ARCH_ABI)/lib$<.so))

Mind the TAB before $(shell... spaces won't work as per standard GNU Make.

这篇关于如何在Android应用中运行打包的二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆