Android studio does not sees my project (I can't run it)

Viewed 136

I am new to Android studio, but I decided to write my first app using kivy and then with help of buildozer create .apk file out of it.

App works on my ubuntu when running python main.py.

enter image description here

After some struggle (following the video https://www.youtube.com/watch?v=yr7n0C2tspI&ab_channel=ShawCode) it worked and command buildozer -v android debug worked creating .apk file.

I uploaded it to google drive and then installed on my phone, but it did not start (black screen for a couple of seconds and then it exits).

I decided it would be a good idea to try to debug it using Android-studio and launched it but as I am new to it I am not quite sure how to use it.

I tried to open directory when the project is located, but it acts, as it could not run it.

enter image description here

Anyone has idea what I am doing wrong, or how to fix this situation?

[EDIT] I managed to run LogCat and extract logs (warnings and errors) from my app. Here they are:

2021-05-25 12:52:59.581 19114-19130/org.test.misia W/libEGL: [ANDROID_RECORDABLE] format: 1
2021-05-25 12:53:02.495 19114-19143/org.test.misia E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
2021-05-25 12:53:02.499 19114-19143/org.test.misia W/libEGL: [ANDROID_RECORDABLE] format: 1

Unfortunately they don't say much. Anyone able to translate them and see what causes it?

3 Answers

well, you are doing one crucial thing wrong: you are trying to import project made in some IDE (PyCharm?) in Android Studio, which does NOT support such projects. "mobile" project made in one IDE rarely works in any other IDE, due to different project structure and sometimes even language. you've picked Kivy and Python, you have to go with it and it's tools, Android Studio is for native apps, not some ports/forks. powodzenia

After some debugging and running another android emulator we were able to conduct that the reason for crashing was that not all packages were included in buildozer.spec. The full list is:

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy,kivymd,mapview,requests,urllib3,chardet,idna

Now it starts correctly.

Too long for a comment, but it might be helpful. For cross platform frameworks, I've seen examples where the code produces an Android Studio project and the final step is to use Android Studio to build the project. That's why some developers suggest looking at building a native app first when you start developing apps: so that you understand how the native tools work.

Going by the Kivy documentation, it looks like Kivy produces an apk file using buildozer (as you've done), but not an Android Studio project. From here, to debug it, it looks like you're going to have to use log files and logcat.

In your app code, you'll need to write to STDOUT or STDERR (i.e. you'll need to add some log statements). In Android Studio, you'll need to attach logcat to a running instance of your code. There are two options for this. You can either use a cable to attach your actual phone to the computer with Android Studio running on it and then connect LogCat to that. Alternatively, you can use Android Studio to start an emulator (you'll need to select a suitable emulator - there are lots of options), then install your .apk file on that emulator (i.e. just click and drag the .apk file on to the emulator once it's open).

LogCat should then be able to see the output from your apk file (although you'll probably have to filter LogCat's output because some apps can be quite "chatty" on LogCat).

Unfortunately, debugging it might be difficult - with Android Studio, you need to select the version of Android that you want to target to produce a suitable .apk for an actual device. I can't see anything in your post that indicates that you've actually made that choice, so I've no idea what level of Android you're targeting. You might get some debug info out of LogCat, but it might just be something about your app failing to launch.

Related