Kivy: 安卓 - 图1
    © Karobben

    由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
    本文GitPage地址

    Thanks for the help of @-=§复活℃ from QQ group kivy who gave me lots of supports when I want to give it up.

    Original Document: linuxrootok; 2018; GitHub
    It failed with error codes:
    AttributeError : 'Wv' object has no attribute 'f2'
    Resolution: omdo; 2020; python-for-android/issues/1908

    main.py

    1. from kivy.app import App
    2. from jnius import autoclass
    3. from kivy.clock import Clock
    4. from android.runnable import run_on_ui_thread
    5. from kivy.uix.widget import Widget
    6. WebView = autoclass('android.webkit.WebView')
    7. WebViewClient = autoclass('android.webkit.WebViewClient')
    8. activity = autoclass('org.kivy.android.PythonActivity').mActivity
    9. @run_on_ui_thread
    10. def create_webview(*args):
    11. webview = WebView(activity)
    12. webview.getSettings().setJavaScriptEnabled(True)
    13. wvc = WebViewClient();
    14. webview.setWebViewClient(wvc);
    15. activity.setContentView(webview)
    16. webview.loadUrl('https://www.baidu.com')
    17. class Wv(Widget):
    18. def __init__(self, **kwargs):
    19. super().__init__(**kwargs)
    20. self.__functionstable__ = {}
    21. Clock.schedule_once(create_webview, 0)
    22. class ServiceApp(App):
    23. def build(self):
    24. return Wv()
    25. if __name__ == '__main__':
    26. ServiceApp().run()

    buildozer.spec

    1. [app]
    2. # (str) Title of your application
    3. title = FileChooser
    4. # (str) Package name
    5. package.name = filechooser
    6. # (str) Package domain (needed for android/ios packaging)
    7. package.domain = org.sirfanas.filechooser
    8. # (str) Source code where the main.py live
    9. source.dir = .
    10. # (list) Source files to include (let empty to include all the files)
    11. source.include_exts = py,png,jpg,kv,atlas
    12. # (list) List of inclusions using pattern matching
    13. #source.include_patterns = assets/*,images/*.png
    14. # (list) Source files to exclude (let empty to not exclude anything)
    15. #source.exclude_exts = spec
    16. # (list) List of directory to exclude (let empty to not exclude anything)
    17. #source.exclude_dirs = tests, bin
    18. # (list) List of exclusions using pattern matching
    19. #source.exclude_patterns = license,images/*/*.jpg
    20. # (str) Application versioning (method 1)
    21. version = 0.5
    22. # (str) Application versioning (method 2)
    23. # version.regex = __version__ = ['"](.*)['"]
    24. # version.filename = %(source.dir)s/main.py
    25. # (list) Application requirements
    26. # comma separated e.g. requirements = sqlite3,kivy
    27. requirements = kivy, python3==3.7.5, docutils, android
    28. # (str) Custom source folders for requirements
    29. # Sets custom source for any requirements with recipes
    30. # requirements.source.kivy = ../../kivy
    31. # (list) Garden requirements
    32. # garden_requirements =
    33. # (str) Presplash of the application
    34. #presplash.filename = %(source.dir)s/data/presplash.png
    35. # (str) Icon of the application
    36. #icon.filename = %(source.dir)s/data/icon.png
    37. # (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
    38. orientation = all
    39. # (list) List of service to declare
    40. #services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
    41. #
    42. # OSX Specific
    43. #
    44. #
    45. # author = © Copyright Info
    46. # change the major version of python used by the app
    47. osx.python_version = 3
    48. # Kivy version to use
    49. osx.kivy_version = 2.0.0
    50. #
    51. # Android specific
    52. #
    53. # (bool) Indicate if the application should be fullscreen or not
    54. fullscreen = 0
    55. # (string) Presplash background color (for new android toolchain)
    56. # Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
    57. # red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
    58. # darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
    59. # olive, purple, silver, teal.
    60. #android.presplash_color = #FFFFFF
    61. # (list) Permissions
    62. android.permissions = INTERNET,WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE
    63. # (int) Target Android API, should be as high as possible.
    64. android.api = 27
    65. # (int) Minimum API your APK will support.
    66. android.minapi = 21
    67. # (str) Android NDK version to use
    68. android.ndk = 19b
    69. # (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
    70. android.ndk_api = 21
    71. # (bool) Use --private data storage (True) or --dir public storage (False)
    72. #android.private_storage = True
    73. # (str) Android NDK directory (if empty, it will be automatically downloaded.)
    74. #android.ndk_path =
    75. # (str) Android SDK directory (if empty, it will be automatically downloaded.)
    76. #android.sdk_path =
    77. # (str) ANT directory (if empty, it will be automatically downloaded.)
    78. #android.ant_path =
    79. # (bool) If True, then skip trying to update the Android sdk
    80. # This can be useful to avoid excess Internet downloads or save time
    81. # when an update is due and you just want to test/build your package
    82. android.skip_update = False
    83. # (bool) If True, then automatically accept SDK license
    84. # agreements. This is intended for automation only. If set to False,
    85. # the default, you will be shown the license when first running
    86. # buildozer.
    87. android.accept_sdk_license = True
    88. # (str) Android entry point, default is ok for Kivy-based app
    89. #android.entrypoint = org.renpy.android.PythonActivity
    90. # (list) Pattern to whitelist for the whole project
    91. #android.whitelist =
    92. # (str) Path to a custom whitelist file
    93. #android.whitelist_src =
    94. # (str) Path to a custom blacklist file
    95. #android.blacklist_src =
    96. # (list) List of Java .jar files to add to the libs so that pyjnius can access
    97. # their classes. Don't add jars that you do not need, since extra jars can slow
    98. # down the build process. Allows wildcards matching, for example:
    99. # OUYA-ODK/libs/*.jar
    100. #android.add_jars = foo.jar,bar.jar,path/to/more/*.jar
    101. # (list) List of Java files to add to the android project (can be java or a
    102. # directory containing the files)
    103. #android.add_src =
    104. # (list) Android AAR archives to add (currently works only with sdl2_gradle
    105. # bootstrap)
    106. #android.add_aars =
    107. # (list) Gradle dependencies to add (currently works only with sdl2_gradle
    108. # bootstrap)
    109. #android.gradle_dependencies =
    110. # (list) Java classes to add as activities to the manifest.
    111. #android.add_activites = com.example.ExampleActivity
    112. # (str) python-for-android branch to use, defaults to master
    113. #p4a.branch = master
    114. # (str) OUYA Console category. Should be one of GAME or APP
    115. # If you leave this blank, OUYA support will not be enabled
    116. #android.ouya.category = GAME
    117. # (str) Filename of OUYA Console icon. It must be a 732x412 png image.
    118. #android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png
    119. # (str) XML file to include as an intent filters in <activity> tag
    120. #android.manifest.intent_filters =
    121. # (str) launchMode to set for the main activity
    122. #android.manifest.launch_mode = standard
    123. # (list) Android additional libraries to copy into libs/armeabi
    124. #android.add_libs_armeabi = libs/android/*.so
    125. #android.add_libs_armeabi_v7a = libs/android-v7/*.so
    126. #android.add_libs_x86 = libs/android-x86/*.so
    127. #android.add_libs_mips = libs/android-mips/*.so
    128. # (bool) Indicate whether the screen should stay on
    129. # Don't forget to add the WAKE_LOCK permission if you set this to True
    130. #android.wakelock = False
    131. # (list) Android application meta-data to set (key=value format)
    132. #android.meta_data =
    133. # (list) Android library project to add (will be added in the
    134. # project.properties automatically.)
    135. #android.library_references =
    136. # (list) Android shared libraries which will be added to AndroidManifest.xml using <uses-library> tag
    137. #android.uses_library =
    138. # (str) Android logcat filters to use
    139. #android.logcat_filters = *:S python:D
    140. # (bool) Copy library instead of making a libpymodules.so
    141. #android.copy_libs = 1
    142. # (str) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
    143. android.arch = armeabi-v7a
    144. #
    145. # Python for android (p4a) specific
    146. #
    147. # (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
    148. #p4a.source_dir =
    149. # (str) The directory in which python-for-android should look for your own build recipes (if any)
    150. #p4a.local_recipes =
    151. # (str) Filename to the hook for p4a
    152. #p4a.hook =
    153. # (str) Bootstrap to use for android builds
    154. # p4a.bootstrap = sdl2
    155. # (int) port number to specify an explicit --port= p4a argument (eg for bootstrap flask)
    156. #p4a.port =
    157. #
    158. # iOS specific
    159. #
    160. # (str) Path to a custom kivy-ios folder
    161. #ios.kivy_ios_dir = ../kivy-ios
    162. # Alternately, specify the URL and branch of a git checkout:
    163. ios.kivy_ios_url = https://github.com/kivy/kivy-ios
    164. ios.kivy_ios_branch = master
    165. # Another platform dependency: ios-deploy
    166. # Uncomment to use a custom checkout
    167. #ios.ios_deploy_dir = ../ios_deploy
    168. # Or specify URL and branch
    169. ios.ios_deploy_url = https://github.com/phonegap/ios-deploy
    170. ios.ios_deploy_branch = 1.7.0
    171. # (str) Name of the certificate to use for signing the debug version
    172. # Get a list of available identities: buildozer ios list_identities
    173. #ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)"
    174. # (str) Name of the certificate to use for signing the release version
    175. #ios.codesign.release = %(ios.codesign.debug)s
    176. [buildozer]
    177. # (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
    178. log_level = 2
    179. # (int) Display warning if buildozer is run as root (0 = False, 1 = True)
    180. warn_on_root = 1
    181. # (str) Path to build artifact storage, absolute or relative to spec file
    182. build_dir = /media/ken/Data/Kivy/.buildozer/
    183. # (str) Path to build output (i.e. .apk, .ipa) storage
    184. # bin_dir = ./bin
    185. # -----------------------------------------------------------------------------
    186. # List as sections
    187. #
    188. # You can define all the "list" as [section:key].
    189. # Each line will be considered as a option to the list.
    190. # Let's take [app] / source.exclude_patterns.
    191. # Instead of doing:
    192. #
    193. #[app]
    194. #source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
    195. #
    196. # This can be translated into:
    197. #
    198. #[app:source.exclude_patterns]
    199. #license
    200. #data/audio/*.wav
    201. #data/images/original/*
    202. #
    203. # -----------------------------------------------------------------------------
    204. # Profiles
    205. #
    206. # You can extend section / key with a profile
    207. # For example, you want to deploy a demo version of your application without
    208. # HD content. You could first change the title to add "(demo)" in the name
    209. # and extend the excluded directories to remove the HD content.
    210. #
    211. #[app@demo]
    212. #title = My Application (demo)
    213. #
    214. #[app:source.exclude_patterns@demo]
    215. #images/hd/*
    216. #
    217. # Then, invoke the command line with the "demo" profile:
    218. #
    219. #buildozer --profile demo android debug
    Kivy: 安卓 - 图2

    Enjoy~

    本文由Python腳本GitHub/語雀自動更新

    由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
    本文GitPage地址

    GitHub: Karobben
    Blog:Karobben
    BiliBili:史上最不正經的生物狗