Google Colab on KivyApp To APK

1,621 views
Skip to first unread message

Jay T

unread,
Sep 16, 2022, 9:07:04 PM9/16/22
to Kivy users support
Hello, 
I have to make an app that goes to a website, because i host websites now and i have made a fishmap...
that will become my app hopefully so i can get data and stuff from users, as well as google adds. 
Right now i have utilized a Google Colab:(i found this)

so i upload my main.py and some buildozer.spec params and it makes an app that only opens on my phone however the installed app doesnt work yet.....any help...


Screenshot_20220916-114608204.png

so it wont run..... after it compiles on the colab into an apk.....just opens....

main.py
#!/usr/bin/env python3
print ('''Content-Type: text/html\n''')
print ('''
<html><head>
  <title>LFTR Fishmap</title>
  <meta name="description" content="fish fishing map with Doppler Radar Map weather" />
  <meta http-equiv="content-type" content="text/html" />
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<iframe src="fishmap.lftr.biz"></iframe>
</body>
</html>''')


Robert

unread,
Sep 16, 2022, 10:38:31 PM9/16/22
to Kivy users support
The FISHMAP link is reported as a security risk, I didn't go there.

Generally about debugging on Android:

The question may be missing some context, or perhaps there is some misunderstanding about what Buildozer does.

By default Buildozer builds an apk consisting of a UI built from the Kivy package, and other Python packages.
A 'Hello World' app source look like this https://kivy.org/doc/stable/guide/basic.html#create-an-application 

From main.py it looks like you want Buildozer to build a webbrowser, and render HTML from Python stdout

I think the answer the app must be built using Kivy, not HTML. Or maybe I'm not understanding the context....

Jay T

unread,
Sep 16, 2022, 10:55:23 PM9/16/22
to Kivy users support
Excellent....you have helped for sure, i think that kivy guide in python maybe how i proceed next.  I will update the thread with any update, yeah it goes to a website that i made a certificate for that i capitalized my name for one field however not for both throwing a security issue....

Jay T

unread,
Sep 17, 2022, 12:19:20 AM9/17/22
to Kivy users support
Well, I have listened to Robert and applied some of my own direction to update the colab:


import kivy
kivy.require('2.1.0') # replace with your current kivy version !
 
from kivy.app import App
from kivy.uix.label import Label
from kivy_garden.ebs.cefkivy.browser import CefBrowser, cefpython
 
class CefBrowserApp(App):
    def build(self):
        return Label(text='LFTR.biz FISHMAP WITH RADAR')
        return CefBrowser(start_url='fishmap.lftr.biz')
 
CefBrowserApp().run()
cefpython.Shutdown()


I am still compiling the apk with my fingers crossed

Robert

unread,
Sep 17, 2022, 1:41:21 AM9/17/22
to Kivy users support
I don't think you will find CefBrowser is portable to Android see the README
"Works currently on Linux and Windows 64bit with python 2.7."
A quick look show x86 Linux and Windows libraries, which are not going to work on an Android device.

Also in your code the App class build() method has two return statements.
Which means the CefBrowser widget won't be instantiated.
Which is another reason it wont work. Look at some Kivy basics.

As an alternative CefBrowser look at https://github.com/Android-for-Python/Webview-Example
(Android only, and full screen only)

Jay T

unread,
Sep 17, 2022, 10:14:49 AM9/17/22
to Kivy users support
Wowzer, yes Robert, the new topic this morning is the lead-up to what you have just described...an issue maybe with older versions of kivy-garden ...however...download and installable via pip with the correct version of python between 3.4 and 3.8 so a different  buildozer requirement=hostpython3==3.6.0, has solved the issue, only mostly....and

i just read your assisistance and ya, thats even closer it should compile like a breeze....later today

anway .... here is my current buildozer.spec of the collab....it says what i mean about the requirements



[app]

# (str) Title of your application
title = LFTR Fishmap

# (str) Package name
package.name = Fishmap

# (str) Package domain (needed for android/ios packaging)
package.domain = lftr.biz

# (str) Source code where the main.py live
source.dir = .

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas

# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png


# (str) Application versioning (method 1)
version = 0.1

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3==3.10.4,hostpython3==3.6.0,kivy,kivy-garden.ebs.cefkivy

# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
orientation = portrait


# Android specific
#

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 0

# (string) Presplash background color (for android toolchain)
# Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
# red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
# darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
# olive, purple, silver, teal.
android.presplash_color = #RRGGBB

# (list) Permissions
android.permissions = INTERNET

# (list) features (adds uses-feature -tags to manifest)
#android.features = android.hardware.usb.host

# (int) Target Android API, should be as high as possible.
android.api = 27

# (int) Minimum API your APK / AAB will support.
android.minapi = 21

# (int) Android SDK version to use
android.sdk = 20

# (str) Android NDK version to use
android.ndk = 23b

# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
android.ndk_api = 21

# (list) Android additional libraries to copy into libs/armeabi
#android.add_libs_armeabi = libs/android/*.so
android.add_libs_armeabi_v7a = libs/android-v7/*.so
android.add_libs_arm64_v8a = libs/android-v8/*.so

# (list) The Android archs to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
# In past, was `android.arch` as we weren't supporting builds for multiple archs at the same time.
android.archs = arm64-v8a, armeabi-v7a

[buildozer]

# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2

# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1

Jay T

unread,
Sep 17, 2022, 12:05:33 PM9/17/22
to Kivy users support

The new working main.py with just the google.colab and internet permissions has produced an apk or two...now

main.py

from kivy.app import App
from webview import WebView

class BrowserApp(App):
    def build(self):
        self.browser = None
        self.browser = WebView('https://google.com', enable_javascript = True, enable_downloads = True, enable_zoom = True)
BrowserApp().run()

yup...

also with my site it does not work with an https security issue i must resolve..however the app!!!!

Jay T

unread,
Sep 18, 2022, 4:29:50 AM9/18/22
to Kivy users support
MY APK  

Screenshot_20220917-230753789.jpg

Robert

unread,
Sep 18, 2022, 2:22:57 PM9/18/22
to Kivy users support
😀

Jay T

unread,
Sep 21, 2022, 10:21:10 AM9/21/22
to Kivy users support
Hello all, 

Well I haven't had time to relax yet because the app, doesn't upload.....and I have been trying to fix it...


To be more specific; there is a java file choose dialog that pops up in the site that is hosted by the app that doesn't appear in the app 
because of possible permissions......I am actually missing mostly upload and gps permission access.

On the site, which the app routes too, it all works good.  so here are some pics describing the access needed
Screenshot_20220919-152929424.png


So, I have also created a google group because i would like to turn this app/project into more reality with time associated:

At my Google Group there are files describing the whole program and setup....


Any help with permissions would be great:

Right now buildozer.spec

[app]
title = LFTR FISHMAP
package.name = FISHMAP
package.domain = fishmap.lftr.biz
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
version = 0.1
requirements = python3,kivy
# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png
# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png
orientation = all
fullscreen = 0
android.presplash_color = aqua
# (list) Permissions
android.permissions=INTERNET,ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION,ACCESS_BACKGROUND_LOCATION,MANAGE_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE,ACCESS_LOCATION_EXTRA_COMMANDS,CAMERA

# (list) Gradle dependencies to add
#android.gradle_dependencies =

# (bool) Enable AndroidX support. Enable when 'android.gradle_dependencies'
# contains an 'androidx' package, or any package from Kotlin source.
# android.enable_androidx requires android.api >= 28
#android.enableJetifier=true
#android.enable_androidx = true

# (list) add java compile options
# this can for example be necessary when importing certain java libraries using the 'android.gradle_dependencies' option
# see https://developer.android.com/studio/write/java8-support for further information
android.add_compile_options = "sourceCompatibility = 1.8", "targetCompatibility = 1.8"

# (list) Gradle repositories to add {can be necessary for some android.gradle_dependencies}
# please enclose in double quotes
# e.g. android.gradle_repositories = "maven { url 'https://kotlin.bintray.com/ktor' }"
#android.add_gradle_repositories =

# (list) packaging options to add
# see https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
# can be necessary to solve conflicts in gradle_dependencies
# please enclose in double quotes
# e.g. android.add_packaging_options = "exclude 'META-INF/common.kotlin_module'", "exclude 'META-INF/*.kotlin_module'"
#android.add_packaging_options =

# (list) Java classes to add as activities to the manifest.
#android.add_activities = com.example.ExampleActivity

android.archs = arm64-v8a, armeabi-v7a

android.allow_backup = True




[buildozer]
log_level = 2
warn_on_root = 1

Robert

unread,
Sep 21, 2022, 5:22:48 PM9/21/22
to Kivy users support
I don't know anything about the a Webkit popup, Webkit behavior is way off topic here.

Android INTERNET permission is bidirectional

I don't know anything about gps access, specially since I presume this access is via Javscript - way off topic here.
That said any Android manifest permissions documented as "dangerous", additionally require a run time permissions dialog.

As I look at this it is not clear why you are using Python. In this case it seems doing so just adds obscurity and as the project proceeds complexity.
Android's native language is Java (well Kotlin now), I suggest this will be by the end of the project easier if you build in Java using Android Studio.
Reply all
Reply to author
Forward
0 new messages