简体   繁体   中英

Error running exec(). Command: Working Directory: null Environment: null - how to execute a binary in Android correctly on a non-rooted device?

I want to run an executable on a non-rooted android device.

Using the following commands in java

Runtime.getRuntime().exec("/bin/chmod 744 /data/data/com.example.myapp/myBin");
Runtime.getRuntime().exec("/data/data/com.example.myapp/myBin");

results in

Error running exec(). Command: [/data/data/com.example.myapp/myBin] 
    Working Directory: null Environment: null

I found alot of questions on this but no answer that worked in my case. How can I execute the binary file correctly?

如果您从服务(而不是应用程序活动)运行此操作,则必须将权限设置为777。

Runtime.getRuntime().exec("/bin/chmod 744 /data/data/com.example.myapp/myBin");

虽然它可能不是你唯一的问题,但是大多数Android chmod版本都存在于/system/bin并且没有/bin目录,所以你的失败可能实际上是在尝试执行一个不存在的工具,甚至在到达之前你的自定义二进制

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM