How to read/write file as root using Kivy for Android?
Вопрос
I would like to write to /etc/hosts in my Kivy app, and I've surely a rooted device to test. I tried several ways but always get my app exit without any warning or error.
I've tried:
subprocess.Popen("su -c touch /etc/hosts", shell = True)
subprocess.Popen("su -c bash -c touch /etc/hosts", shell = True)
subprocess.Popen(["su", "-c", "bash -c touch /etc/hosts"])
and several combinations of them. Every time I can get the su app message box asking me for permission and I pressed "Allow", but my app exits after that.
EDIT: logcat output is at http://pastebin.com/YMT5Vxra
Many thanks if anyone can give any suggestion!
Решение
Your error indicate that string-escape is not a known encoding. Kivy is shipping a lite version of Python with their libs, not all the encodings for example. What you can try is to:
- Grab python-for-android project
- Go into private/lib/encodings
- Copy the file from your computer to this directory (/usr/lib/python2.7/encodings/string_escape.pyo)
- Rebuild your application
Then that should work.
The pgs4a-kivy project is not good as soon as kivy is not shipping the files you want. This is why i've started python-for-android project. You'll have the power of what you want or not in your final distribution.