Enable developer mode in the mobile
Install adb tool in the MacBook
This tool will be useful to
copy files to and from the mobile
Send commands to mobile
brew cask install android-platform-tools
adb devices
adb devices -l
ADB push -> https://adbshell.com/commands/adb-push
Pushing apk to android device
(base) Deepaks-MacBook-Air:KivyHelloWorld deepak$ adb devices
List of devices attached
4f5bac59 device
(base) Deepaks-MacBook-Air:KivyHelloWorld deepak$ adb push helloworld-0.1-armeabi-v7a-debug.apk /mnt/sdcard/Download/helloworld.apk
helloworld-0.1-armeabi-v7a-debug.apk: 1 file pushed, 0 skipped. 3.4 MB/s (12979124 bytes in 3.601s)
(base) Deepaks-MacBook-Air:KivyHelloWorld deepak$
Refer https://developer.android.com/studio/command-line/adb#devicestatus
ADB logcat
It allows to get device logs
ADB logcat example where python app has done 'DKK Hi' in log
(base) Deepaks-MacBook-Air:KivyHelloWorld deepak$ adb logcat | grep DKK
04-20 04:27:18.980 27859 27937 I python : DKK Hi
Python code example:
(buildozerenv3) deepak@containerd121:~/deepak/neo4j/android/KivyHelloWorld$ cat main.py
from kivy.app import App
from kivy.uix.button import Button
class MainApp(App):
def build(self):
print("DKK Hi\n")
return Button(text="Hello World4")
MainApp().run()
adb shell pm list packages -f
Refer: https://stackoverflow.com/questions/6289149/read-the-package-name-of-an-android-apk
package name listing
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ adb shell pm list packages -f | grep kivyhello
package:/data/app/org.test.kivyhello-2/base.apk=org.test.kivyhello
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$
Below command will launch org.test.kivyhello app only if it is not
adb shell monkey -p <app pkg name> -c android.intent.category.LAUNCHER 1
Example
adb shell monkey -p org.test.kivyhello -c android.intent.category.LAUNCHER 1
Refer: https://stackoverflow.com/questions/4567904/how-to-start-an-application-using-android-adb-tools
Below mobile screenshot helps to see the app getting launched
Example for attaching and clearing the app
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ adb shell am set-debug-app -w --persistent org.test.kivyhello
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ adb shell am clear-debug-app org.test.kivyhello
$ echo here package name is org.test.kivyhello
It is done via logcat (Buildozer or adb)
Example via Buildozer
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ buildozer android debug deploy run logcat | grep python
....
....
05-18 16:17:21.967 8606 8794 I python : os.environ is environ({'PATH': '/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/tcmiface.jar:/system/framework/WfdCommon.jar:/system/framework/com.qti.dpmframework.jar:/system/framework/dpmapi.jar:/system/framework/com.qti.location.sdk.jar:/system/framework/qcom.fmradio.jar:/system/framework/qcmediaplayer.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar', 'LD_PRELOAD': 'libNimsWrap.so', 'ANDROID_PROPERTY_WORKSPACE': '10,0', 'ANDROID_SOCKET_zygote_secondary': '12', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/org.test.kivyhello/files/app', 'ANDROID_APP_PATH': '/data/user/0/org.test.kivyhello/files/app', 'ANDROID_PRIVATE': '/data/user/0/org.test.kivyhello/files', 'ANDROID_UNPACK': '/data/user/0/org.test.kivyhello/files/app', 'PYTHONHOME': '/data/user/0/org.test.kivyhello/files/app', 'PYTHONPATH': '/data/user/0/org.test.kivyhello/files/app:/data/user/0/org.test.kivyhello/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'True', 'P4A_ORIENTATION': 'portrait', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
05-18 16:17:21.967 8606 8794 I python : Android kivy bootstrap done. __name__ is __main__
05-18 16:17:21.967 8606 8794 I python : AND: Ran string
05-18 16:17:21.967 8606 8794 I python : Run user program, change dir and execute entrypoint
05-18 16:17:22.220 8606 8794 I python : [WARNING] [Config ] Older configuration version detected (0 instead of 21)
05-18 16:17:22.221 8606 8794 I python : [WARNING] [Config ] Upgrading configuration in progress.
05-18 16:17:22.233 8606 8794 I python : [INFO ] [Logger ] Record log in /data/user/0/org.test.kivyhello/files/app/.kivy/logs/kivy_20-05-18_0.txt
05-18 16:17:22.234 8606 8794 I python : [INFO ] [Kivy ] v1.11.1
05-18 16:17:22.234 8606 8794 I python : [INFO ] [Kivy ] Installed at "/data/user/0/org.test.kivyhello/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
05-18 16:17:22.234 8606 8794 I python : [INFO ] [Python ] v3.8.1 (default, Apr 21 2020, 15:00:43)
05-18 16:17:22.234 8606 8794 I python : [Clang 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec7462
05-18 16:17:22.235 8606 8794 I python : [INFO ] [Python ] Interpreter at ""
05-18 16:17:23.587 8606 8794 I python : [INFO ] [Factory ] 184 symbols loaded
05-18 16:17:24.406 8606 8794 I python : [INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
05-18 16:17:24.486 8606 8794 I python : Traceback (most recent call last):
05-18 16:17:24.487 8606 8794 I python : File "/Users/shilpimittal/Documents/coding/python/android/kivyHelloWorld/.buildozer/android/app/main.py", line 4, in <module>
05-18 16:17:24.488 8606 8794 I python : File "/Users/shilpimittal/Documents/coding/python/android/kivyHelloWorld/.buildozer/android/app/checkdm.py", line 4, in <module>
05-18 16:17:24.489 8606 8794 I python : ModuleNotFoundError: No module named 'jsonpickle' --> This is output from the app
05-18 16:17:24.489 8606 8794 I python : Python for android ended.
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ vim main.py
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ ls
bin checkdm.py checkdm.py_orig main.py_2 main.py_4 my.kv
buildozer.spec checkdm.py_3 main.py main.py_3 main.py_orig myapp1.ini
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ vim main.py
(kivyenv) Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ buildozer android debug deploy run logcat | grep python
Log output via adb
Shilpis-MacBook-Air:kivyHelloWorld shilpimittal$ adb logcat | grep python
....
....
05-18 16:21:57.774 10022 10039 I python : _python_bundle dir exists
05-18 16:21:57.774 10022 10039 I python : calculated paths to be...
05-18 16:21:57.774 10022 10039 I python : /data/user/0/org.test.kivyhello/files/app/_python_bundle/stdlib.zip:/data/user/0/org.test.kivyhello/files/app/_python_bundle/modules
05-18 16:21:57.775 10022 10039 I python : set wchar paths...
05-18 16:21:57.895 10022 10039 I python : Initialized python
05-18 16:21:57.895 10022 10039 I python : AND: Init threads
05-18 16:21:57.897 10022 10039 I python : testing python print redirection
05-18 16:21:57.899 10022 10039 I python : Android path ['.', '/data/user/0/org.test.kivyhello/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.test.kivyhello/files/app/_python_bundle/modules', '/data/user/0/org.test.kivyhello/files/app/_python_bundle/site-packages']
05-18 16:21:57.899 10022 10039 I python : os.environ is environ({'PATH': '/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/tcmiface.jar:/system/framework/WfdCommon.jar:/system/framework/com.qti.dpmframework.jar:/system/framework/dpmapi.jar:/system/framework/com.qti.location.sdk.jar:/system/framework/qcom.fmradio.jar:/system/framework/qcmediaplayer.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar', 'LD_PRELOAD': 'libNimsWrap.so', 'ANDROID_PROPERTY_WORKSPACE': '10,0', 'ANDROID_SOCKET_zygote_secondary': '12', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/org.test.kivyhello/files/app', 'ANDROID_APP_PATH': '/data/user/0/org.test.kivyhello/files/app', 'ANDROID_PRIVATE': '/data/user/0/org.test.kivyhello/files', 'ANDROID_UNPACK': '/data/user/0/org.test.kivyhello/files/app', 'PYTHONHOME': '/data/user/0/org.test.kivyhello/files/app', 'PYTHONPATH': '/data/user/0/org.test.kivyhello/files/app:/data/user/0/org.test.kivyhello/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'True', 'P4A_ORIENTATION': 'portrait', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
05-18 16:21:57.899 10022 10039 I python : Android kivy bootstrap done. __name__ is __main__
05-18 16:21:57.899 10022 10039 I python : AND: Ran string
05-18 16:21:57.899 10022 10039 I python : Run user program, change dir and execute entrypoint
05-18 16:21:58.179 10022 10039 I python : [INFO ] [Logger ] Record log in /data/user/0/org.test.kivyhello/files/app/.kivy/logs/kivy_20-05-18_1.txt
05-18 16:21:58.180 10022 10039 I python : [INFO ] [Kivy ] v1.11.1
05-18 16:21:58.180 10022 10039 I python : [INFO ] [Kivy ] Installed at "/data/user/0/org.test.kivyhello/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
05-18 16:21:58.180 10022 10039 I python : [INFO ] [Python ] v3.8.1 (default, Apr 21 2020, 15:00:43)
05-18 16:21:58.180 10022 10039 I python : [Clang 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec7462
05-18 16:21:58.181 10022 10039 I python : [INFO ] [Python ] Interpreter at ""
05-18 16:21:59.465 10022 10039 I python : [INFO ] [Factory ] 184 symbols loaded
05-18 16:22:00.251 10022 10039 I python : [INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
05-18 16:22:00.316 10022 10039 I python : Traceback (most recent call last):
05-18 16:22:00.317 10022 10039 I python : File "/Users/shilpimittal/Documents/coding/python/android/kivyHelloWorld/.buildozer/android/app/main.py", line 4, in <module>
05-18 16:22:00.318 10022 10039 I python : File "/Users/shilpimittal/Documents/coding/python/android/kivyHelloWorld/.buildozer/android/app/checkdm.py", line 4, in <module>
05-18 16:22:00.318 10022 10039 I python : ModuleNotFoundError: No module named 'jsonpickle'
05-18 16:22:00.318 10022 10039 I python : Python for android ended.
^C
Just drag and drop to the android studio (Ref: below example)
Ref: https://proandroiddev.com/how-to-enable-logging-on-any-android-app-5880f2d1a6fc