简体   繁体   中英

Running a shell script on android device using adb

Manually, we can run:

adb shell
su
chmod 666 /dev/graphics/fb0
export CLASSPATH=/data/local/device.jar
export LD_LIBRARY_PATH=/data/local
exec app_process /system/bin com.device.client.Main /data/local/device.conf &

However, we need to be able to run that from a bash script on the computer compiling the program.

I have tried:

adb shell "su
    && chmod 666 /dev/graphics/fb0
    && export CLASSPATH=/data/local/device.jar
    && export LD_LIBRARY_PATH=/data/local
    && exec app_process /system/bin com.device.client.Main /data/local/device.conf &"

But since we are entering the su shell, this does not work.

Can you please suggest a solution?

Try this:

adb shell "su -c '
chmod 666 /dev/graphics/fb0
&& export CLASSPATH=/data/local/device.jar
&& export LD_LIBRARY_PATH=/data/local
&& exec app_process /system/bin com.device.client.Main
    /data/local/device.conf &'"

It might be possible to simplify it, too:

adb shell "su -c '
chmod 666 /dev/graphics/fb0 &&
CLASSPATH=/data/local/device.jar
LD_LIBRARY_PATH=/data/local
app_process /system/bin com.device.client.Main
    /data/local/device.conf &'"

This is because you can set environment variables for one job just by prepending them on the line, rather than the export this, export that form.

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