Closed ElHacker closed 6 years ago
Based on: http://python-for-android.readthedocs.io/en/latest/quickstart/ First create a main.py file in the directory where you're keeping your app
Example main.py file:
import kivy
kivy.require('1.0.9')
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.properties import NumericProperty
from kivy.app import App
Builder.load_string('''
<HelloWorldScreen>:
cols: 1
Label:
text: 'Welcome to the Hello world'
Button:
text: 'Click me! %d' % root.counter
on_release: root.my_callback()
''')
class HelloWorldScreen(GridLayout):
counter = NumericProperty(0)
def my_callback(self):
print 'The button has been pushed'
self.counter += 1
class HelloWorldApp(App):
def build(self):
return HelloWorldScreen()
if __name__ == '__main__':
HelloWorldApp().run()
Connect your android device in developer mode and enable USB debugging: https://developer.android.com/studio/debug/dev-options.html
Now run:
p4a apk --private ~/Developer/Android/ptam --package=org.cs231a.ptam --name "PTAM" --version 0.1 --bootstrap=sdl2 --requirements=python2,kivy,numpy --arch=armeabi-v7a
If successful now let's install the apk in our android device:
sudo adb -d install <path_apk>/name.apk
To uninstall the apk, you'll need the package name:
sudo adb uninstall org.cs231a.ptam
To check the logs of your apk running on device:
abd logcat
Numpy is supported!
cp build/other_builds/kivy3/armeabi-v7a/kivy3/kivy3/default.glsl dists/unnamed_dist_2/private/lib/python2.7/site-packages/kivy3/
If there are any cython compilation errors it might be due to having the wrong cython version you should install cython 0.21
pip install cython==0.21
/.local/share/python-for-android/dists/unnamed_dist_1/src/main/java/org/cs231a/ptam$
To do the android app deployment
deployapp ~/Developer/Android/PTAM/src/ org.cs231a.ptam /home/elhacker/.local/share/python-for-android/dists/unnamed_dist_1/build/outputs/apk/unnamed_dist_1-debug.apk ~/Developer/Android/PTAM/src/java_src/ ~/.local/share/python-for-android/dists/unnamed_dist_1/src/main/java/org/cs231a/ptam/
Here's the bash script for deploy app:
# aliases for android dev.
deployapp() {
echo "Compiling java for errors"
java_src_dir=$4
find $4 -name "*.java" > $java_src_dir/sources.txt
javac @${java_src_dir}/sources.txt || kill -INT $$
echo "Copying the java src files to the apk"
apk_java_src_dir=$5
cp $java_src_dir/*.java $apk_java_src_dir
echo "Building the new apk..."
p4a apk --private $1
echo "Uninstalling the old apk from the phone"
adb uninstall $2
echo "Installing the new apk on the phone"
adb -d install $3
}
Put it on your .bashrc file
https://kivy.org/docs/guide/packaging-android.html