Convert Python to Android with WINDOWS & LINUX + Fix Common Bugs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone today i will show you how to convert your python files into android applications using windows windows for this we will first create a python app with either tv or and if you guys are not quite sure how to do this don't worry i actually have a few very handy tutorials on the subject so just pick any of the links in the description of the video and once you're ready let's start compiling we will begin by setting up a windows subsystem for linux which is basically a linux terminal that we can run from our windows system for this we will need to open our powershell so we will navigate to the start menu we will type power we will then click on the right mouse button and we will run it as administrator then we will navigate to the official microsoft installation instructions which you can find in the description of the video i already have it ready in my browser we will then scroll and copy the command under step 1 and we will paste it inside our terminal and hit enter we will then scroll a little bit more we will copy the command from step 3 and we will paste it once again inside our terminal and once again we will hit enter and then we will restart our computer for the changes to take place and once we have restarted our computer we can go ahead and download the linux kernel update package just by clicking on the link and we will then install it on our computer in my case i already have it installed so i'm just gonna click on finish we will then open our powershell once again as administrators and we will type wsl which stands for a windows subsystem for linux followed by two dashes and then set dash default dash version space 2 which is the current version for august 2021 we will then hit enter and now we can go ahead and install ubuntu so we will navigate to the microsoft store we will search for ubuntu and my choice would be the regular ubuntu app even though you can choose any other we will install it and before we launch it let's first download the code we would like to convert we will navigate to my github account and we will select the binary to decimal repository we will then download the code we will extract this archive preferably somewhere near the root folder which in my case is c users maria documents and we will dispose of all the files we will not need so we will navigate to the android pre-build folder and we will copy all the files excluding the build dozer file which we will build on our own so we will copy logo and main as well we will paste it inside the folder we created for the archive and we will dispose of the rest now one thing i should mention is if you are watching this video years after i filmed it you will most likely need a newer version of the adb server which includes all these three files we will talk about them in much more detail shortly and i will show you where you can download different versions of them but for now your life is slightly easier because i've included everything in the project files now the tool we will use to convert our python files into android files is called builddozer and it works in particular with kivy and kvmd gui libraries if you will try to use it with kinter or pi qd5 it's not gonna work so let's begin by installing it inside our new ubuntu shell for this we will navigate to the start menu we will open ubuntu and here we will select a username in my case that would be maria because that's my name we will hit enter and we will then select a password we will retype it we will then navigate to the same directory where we save their project files we will do this with cd change directory now the way to access the windows file system through an ubuntu terminal is slightly different than what we've used to so instead of typing c users maria documents we will type slash mnt c slash users slash maria which already sounds familiar slash documents and lastly the project folder which is called b2d binary to decimal and we will hit enter once the address appears in blue we know that we are inside the correct folder and we are ready to install billdozer for this we will navigate to the official buildozer documentation link is also in the description and we will copy the very first command but if we paste it inside our terminal and hit enter we see that the pip 3 library is not even installed so let's install it together by first typing sudo apt update and enter we will enter the password we have selected and once everything is updated we can go ahead and type sudo apt install python 3 dash pip and we will hit enter yes we would love to continue and pip 3 is officially installed so let's paste this command once again and we will hit enter and boom we have build dozer and then we will move on with installing the dependencies now since we have already ran this command just a few seconds ago we will not need to do it again instead we will copy the next line of code and we will paste it in our terminal enter then we will copy the next line of code excluding the comment we don't really need it and we will paste it back inside our terminal and now we have installed a virtual environment lastly we will copy the very very last line of code we will paste it once again hit enter and boom we have installed all the buldozer dependencies and now it's time to talk about the android debugging bridge also known as adb which i have briefly mentioned a few minutes ago this bridge allows communication between our computer and our mobile device and because we are using a windows system we cannot really use the linux bridge that is accessed through our ubuntu terminal instead we will need to download a special windows bridge and access it through our powershell so first let's find out which bridge version our linux requires we can do this by typing adb and then dash dash version and surprise surprise just as we didn't have the pip 3 library we also don't have the adb so we can install it with sudo apt install adb we will hit enter we will then hit the up arrow twice and we will check the version and we see that our android debug bridge has the version of 1.0.39 which is slightly older than the current version and you are probably wondering how do i know it's slightly older so for this we will navigate to the official android developer platform tools which is also in the description and we will scroll a bit down we will download the sdk platform tools for windows we will agree to the terms and conditions of course we have read all of them we will open the archive we will open the folder and we will unzip the first three files somewhere on our computer and then inside the same folder of the files we've just extracted we will press shift along with the right mouse button and then we will open the powershell window here and then we can check the current version with dot slash adb dash dash version which is indeed slightly newer than 1.0.39 but the only way for the conversion to work is if both our windows bridge and linux bridge match in their versions that's why we will need a slightly older one so we can close this powershell window we can dispose of the stamp folder we can navigate back to our b2d folder where i have included the exact version i was just talking about in the project files so if we press on shift and then the right mouse button we open the powershell window here and we will type dot slash adb dash dash version once again hit enter we can finally begin our conversion next we will connect our computer to our phone with a usb cable and then we will need to set our phone to a developer mode on our phone we will navigate to the settings we will then select about phone we will search for the build number and once we find it we will press on it seven times we will then enter our secret combination and we have activated the developer mode so now when we navigate back to the settings we suddenly have a brand new developer options option at the bottom of our menu we will select it we will scroll a bit down and we will turn on the usb debugging next we will initialize a builddozer spec file inside our project folder for this we will type bill dowser init and we will hit enter and once we go back to our folder we see a brand new file was created so let's go ahead and open it inside the file we will select a title for our app in my case that would be number base converter and then we can select a name to the app which is base converter in camel case because we are not allowed to use spaces we will then scroll down a little bit and we will need to add some specific requirements now simply specifying kivy will not do the trick we need to be very particular with the version of kv we used to create our app in my particular case i've used kivy 2.0.0 but that's not all i have also used tv md in the version of 0.104.1 very specific and since my app includes a logo i will also need to require pillow which is an image processing library also known as pill and here we luckily don't need to specify a version so we can go ahead and save this file with ctrl s and it's time to turn on our android bridge server so as you remember we will access the powershell we will type dot slash adb start server and we will hit enter and then we will see if our phone is detected by the powershell so we will type dot slash adb devices enter and we can see a device was found which means our server is running our phone is in developer mode and it is connected with a usb cable to our computer only then we will type builder dash v android debug and we will hit enter and hello hello to our very first error so if we scroll up a little bit we see that we have an issue with permissions but we can fix it by typing sudo mount dash t d r v f s and then our c drive and then our linux version of c drive which is mnt c then dash o and finally metadata we will hit enter it will type the password and let's give our conversion another try we will hit enter and right now it looks very promising so we will hit y it will hit enter now this process may take you quite some time and when i say quite some time i actually mean something along the 20 minutes range maybe a little bit more depending on your computer cool and when we see those two beautiful beautiful messages we know that our app has finished compiling and then we can navigate back to our b2d folder where we see two brand new directories were added we will then find our apk file inside the bin directory and we will copy it into our mobile device which i already have here so i'm just going to open it in a new window i'm going to access my downloads folder and i will paste it here then on our phone we will navigate to my files we will then select the apk installation files we will select download and we will tap on our newly compiled apk file we will select install then install anyway we will hit don't send and then we can finally open the app and here's our gorgeous app now if you guys cannot see the icon at the very top right of our menu don't worry about it because i'll show you how to fix it in a moment for now let's quickly test the app so we will type 101 which in decimal means 5. we will then add 0.001 and perfect it looks like it worked then we will hit on the flip button which will work even if you can't see it we will then type 5 which is exactly what we expected and then we will try with 5.125 which is also a perfect match and then if we type a weird string which is not a number even then our app doesn't fail and surprisingly everything is rainbows and butterflies but the last time i've been compiling the exact same app i had a lot of issues with displaying the toolbar icon now if you guys encounter the exact same issue there's actually a solution on github so the way to solve it is to navigate to the python for android github repository and to press on fork which will create a copy of this particular repository on your github account then we will navigate to our b2d folder we will open the buldozer directory it will go to android we will then hit platform then python for android and then python for android once again we will then access the recipes and we will scroll down we will find the sdl2 ttf folder and we will open it we will then double click on the init file and we will change our version from 14 to 15. then we will save this file we will close it we will return to our b2d folder and we will open our build dozer file we will then scroll to our requirements which we can find here and we will add an additional requirement which is sdl2 underscore ttf that's the same recipe we have just edited and we will set the version to 2.0 point instead of 2.0.14 but that's not all we will also scroll much much much lower until we see the python for android p4a specifics where we will replace kv with our github username and the only reason why we can do it is because we made a p4a fork on our account so we will type mariasha which is my github account as you probably know and then additionally we will change the branch to develop we will then save this file we will close it and we will remove the bill dozer folder all together and once our build dozer folder was deleted we can go ahead and compile our app once again awesome so now we have finally learned how to create android applications with python i wanted to give a special thank you to all the lovely viewers who helped me with this project i saw your tips i saw your suggestions they were absolutely incredible thank you i also wanted to mention in particular nikolai also known as delphi nikki and winston also known as wintash thank you so much for sharing your github code with me it helped me a lot now thank you so much for watching this tutorial if you found it useful please give it a like maybe subscribe to my channel leave me a comment turn on the notification bell or even share this tutorial with android developers who are still for some reason not using python let's force them now i will see you guys very soon in a brand new machine learning tutorial so don't go too far
Info
Channel: Python Simplified
Views: 32,455
Rating: 4.9574165 out of 5
Keywords: python for android, python programming, python to android, py to apk, kivy tro android, kivy, kivymd, gui, python gui, convert python to android, convert py to apk, mobile app, android app, apk, adb, wsl, windows subsystem for Linux, Android Debug Bridge, adb for windows, adb server, buildozer, kivy buildozer, buildozer windows, buildozer wsl, ubuntu wsl, python tutorial, python on phone, python on mobile, python mobile app, python android app, p4a, kivy gui, kivymd app, compile
Id: VsTaM057rdc
Channel Id: undefined
Length: 18min 58sec (1138 seconds)
Published: Thu Aug 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.