
ふう! このモンスターのトラックの下から出たばかりです。 また、幸運ではなかった人もいました。 前の記事で約束したように、本日は、Buildozerユーティリティを使用してKivyフレームワークを使用して作成されたプログラムのapkパッケージがどのように構築されるかを説明します。
これには何が必要ですか? 既知のツール-コーヒータバコ、1ポンドの神経-に加えて、GitHubの格納庫にある新しいブルドーザーと関連する依存症の鍵が必要です。 Android用のパッケージを組み立てることはできません。
ちなみに、Microsoftユーザーは、Windowsマシンでブルドーザーを使用することはありません。apkパッケージを構築するには、Linuxシステムまたは仮想マシン上のそのイメージが必要だからです。 じゃあ そして、githubに移動し、 ブルドーザーをけん引し、アーカイブを何らかのディレクトリに解凍します。 くそー はい、それはただのモンスターです!
落ち着いて。 開始しないでください。 レバレッジを取得しません。 最初に、Pythonパッケージをインストールおよび管理するためのツールであるpipパッケージをダウンロードする必要があります。
sudo apt-get install python-pip
ブルドーザーのあるフォルダー内の意味で、格納庫に入ります...

...コマンドを実行します-
sudo python setup.py install
buildozerが正常にインストールされたことにより、インストールが成功したことが通知されます。 ブルドーザーは、Python 2.7とPython> = 3.3の両方で機能します。 Python 2.7を使用しています。 Kivy開発者によると、3番目のPythonは完全にサポートされていますが、Python 3を使用して記述されたプログラムのapkパッケージをまだ作成しようとしていないためです。 さて、そして今、実際にpython-for-androidをダウンロードしましょう。 このブランチは私のために働くので、他の人には提供しません。 python-for-android.zipを解凍し、今のところ忘れてください。
依存関係
それらの多くがあり、あなたが大切なapk-chechkaを集めることができるか、バリドーラを飲んで最初からやり直す必要があるかどうかは、適切なインストールに依存します。 上記のパッケージがすべて揃っているわけではないと考えられており、Kivyフレームワークがインストールされており、正常に使用されていると想定されています。
sudo pip install --upgrade cython sudo pip install virtualenv sudo pip install Jinja2
Android用のパッケージをビルドするには、Android SDKが必要です。 バイナリの一部はまだ32ビットライブラリにあるため、利用可能にする必要があります。
dpkg --add-architecture i386
その後、次のパッケージをインストールできます。
sudo apt-get update sudo apt-get install -y build-essential ccache git zlib1g-dev python2.7 python2.7-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-7-jdk unzip
さて、そして今、最後に、私たちは快適なブルドーザーの椅子に座って、制御レバーをつかむ準備ができています。 プロジェクトフォルダーに移動し、ターミナルでコマンドを実行します-
buildozer init
...これにより、プロジェクトにbuildozer.spec仕様ファイルが作成されます。ここで、アプリケーションをビルドするためのパラメーターをブルドーザーに伝えます。

このファイルを開き、その内容を確認します。
[app] # (str) Title of your application title = DemoCleanMaster # (str) Package name package.name = democleanmaster # (str) Package domain (needed for android/ios packaging) package.domain = org.heattheatr # (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,kv,jpg # (list) Source files to exclude (let empty to not exclude anything) #source.exclude_exts = [] # (list) List of directory to exclude (let empty to not exclude anything) #source.exclude_dirs = [] # (list) List of exclusions using pattern matching #source.exclude_patterns = license,images/*/*.jpg # (str) Application versioning (method 1) version.regex = __version__ = ['"](.*)['"] version.filename = %(source.dir)s/main.py # (str) Application versioning (method 2) # version = 1.2.0 # (list) Application requirements # comma seperated eg requirements = sqlite3,kivy requirements = kivy # (str) Custom source folders for requirements # Sets custom source for any requirements with recipes # requirements.source.kivy = ../../kivy # (list) Garden requirements #garden_requirements = # (str) Presplash of the application presplash.filename = %(source.dir)s/Data/Images/presplash.jpg # (str) Icon of the application icon.filename = %(source.dir)s/Data/Images/logo.png # (str) Supported orientation (one of landscape, portrait or all) orientation = portrait # (bool) Indicate if the application should be fullscreen or not fullscreen = 1 # # Android specific # # (list) Permissions android.permissions = INTERNET # (int) Android API to use android.api = 18 # (int) Minimum API required (8 = Android 2.2 devices) android.minapi = 8 # (int) Android SDK version to use android.sdk = 21 # (str) Android NDK version to use android.ndk = 9 # (bool) Use --private data storage (True) or --dir public storage (False) android.private_storage = False # (str) Android NDK directory (if empty, it will be automatically downloaded.) android.ndk_path = /home/zavulon/Opt/android-ndk-r9 # (str) Android SDK directory (if empty, it will be automatically downloaded.) android.sdk_path = /home/zavulon/Opt/android-sdk # (str) python-for-android git clone directory (if empty, it will be automatically cloned from github) android.p4a_dir = /home/zavulon/Opt/Python/python-for-android # (list) python-for-android whitelist #android.p4a_whitelist = # (str) Android entry point, default is ok for Kivy-based app #android.entrypoint = org.renpy.android.PythonActivity # (list) List of Java .jar files to add to the libs so that pyjnius can access # their classes. Don't add jars that you do not need, since extra jars can slow # down the build process. Allows wildcards matching, for example: # OUYA-ODK/libs/*.jar #android.add_jars = foo.jar,bar.jar,path/to/more/*.jar # (list) List of Java files to add to the android project (can be java or a # directory containing the files) #android.add_src = # (str) python-for-android branch to use, if not master, useful to try # not yet merged features. #android.branch = master # (str) OUYA Console category. Should be one of GAME or APP # If you leave this blank, OUYA support will not be enabled #android.ouya.category = GAME # (str) Filename of OUYA Console icon. It must be a 732x412 png image. #android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png # (str) XML file to include as an intent filters in <activity> tag #android.manifest.intent_filters = # (list) Android additionnal 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_x86 = libs/android-x86/*.so #android.add_libs_mips = libs/android-mips/*.so # (bool) Indicate whether the screen should stay on # Don't forget to add the WAKE_LOCK permission if you set this to True #android.wakelock = False # (list) Android application meta-data to set (key=value format) #android.meta_data = # (list) Android library project to add (will be added in the # project.properties automatically.) #android.library_references = # # iOS specific # # (str) Name of the certificate to use for signing the debug version # Get a list of available identities: buildozer ios list_identities #ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)" # (str) Name of the certificate to use for signing the release version #ios.codesign.release = %(ios.codesign.debug)s [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 = 0 # ----------------------------------------------------------------------------- # List as sections # # You can define all the "list" as [section:key]. # Each line will be considered as a option to the list. # Let's take [app] / source.exclude_patterns. # Instead of doing: # #[app] #source.exclude_patterns = license,data/audio/*.wav,data/images/original/* # # This can be translated into: # #[app:source.exclude_patterns] #license #data/audio/*.wav #data/images/original/* # # ----------------------------------------------------------------------------- # Profiles # # You can extend section / key with a profile # For example, you want to deploy a demo version of your application without # HD content. You could first change the title to add "(demo)" in the name # and extend the excluded directories to remove the HD content. # #[app@demo] #title = My Application (demo) # #[app:source.exclude_patterns@demo] #images/hd/* # # Then, invoke the command line with the "demo" profile: # #buildozer --profile demo android debug
今、より詳細に検討してください...
title = DemoCleanMaster
これは、Androidデバイスに表示され、インストールapkパッケージを運ぶアプリケーションの名前です。
package.name = democleanmaster package.domain = org.heattheatr
一意のアプリケーションドメイン。

source.dir = .
アプリケーションへのエントリポイントがあるディレクトリは、main.pyファイルです。 デフォルトでは、これはプロジェクトのルートディレクトリです。

source.include_exts = py,kv,jpg,png
プロジェクトのアセンブリapkパッケージに含まれるファイルの拡張子。 指定されたファイルが取得されるディレクトリツリー構造が保存されます。
version.regex = __version__ = ['"](.*)['"] version.filename = %(source.dir)s/main.py
プログラムのバージョンと、それを探すファイル(バージョン)。 このメソッドは、プロジェクトのルートディレクトリのmain.pyファイルに、アプリケーションのバージョン値を持つ変数が必要であることを示しています。
# main.py __version__ = '0.0.1' # ...
requirements = kivy
アセンブリに含まれるサードパーティライブラリ。 アプリケーションが動作するライブラリパッケージをカンマで区切って指定できます。たとえば、kivy、opencv、pil、sqlite3です。
利用可能なライブラリの完全なリストは、UIを作成するツール-Kivy Designerの仕様エディターで確認できます。 私はそれを強くお勧めします!

presplash.filename = %(source.dir)s/Data/Images/presplash.jpg
アプリケーションの起動中にデバイス画面に表示される画像。%(source.dir)sはプロジェクトのルートディレクトリへのパスです。

icon.filename = %(source.dir)s/Data/Images/logo.png
デバイスに表示されるアプリケーションアイコン。
orientation = portrait fullscreen = 1
デバイス上のアプリケーションの向き。 「ポートレート」に加えて、「ランドスケープ」の値を取ることができます。 「フルスクリーン」は、アクティビティをフルスクリーンに展開することを示します。 また、値「0」を取ります。
android.permissions = INTERNET
アプリケーションの権利。
android.api = 18
アプリケーションで使用されるAndroid APIのバージョン(Android SDKにある必要があります)。 これは、たとえば、Android NDKで利用できないAndroid API 10のバージョンを指定した場合に問題を引き起こす可能性があります。

android.minapi = 8
アプリケーションがサポートするAndroid APIの最小バージョン。
android.sdk = 21
Android SDKバージョン。
android.ndk = 9
Android NDKバージョン。
android.private_storage = False
SDカード上のデバイスにプロジェクトファイルを含むフォルダーを作成するように指定します。 お勧めです。 この場合、* .pyoプロジェクトファイルのバイトコンパイルされた表現をソーステキストに置き換えることができるため、プロジェクトに小さな変更を加える必要がある場合は、ソースを編集するか、コンピューターからそれらを再読み込みすることにより、デバイスで直接これを行うことができます。
android.ndk_path = /home/zavulon/Opt/android-ndk-r9 android.sdk_path = /home/zavulon/Opt/android-sdk android.p4a_dir = /home/zavulon/Opt/Python/python-for-android
ここではすべてが明確です。 次のようにできます。
android.ndk_path = android.sdk_path = android.p4a_dir =
この場合、ブルドーザーは、仕様で指定されているANDROID APIバージョンのAndroid SDKと、Android NDK、およびPython-for-android、Apache-antがブルドーザーで見つからない場合にダウンロードされます。 Python自体とモジュールの次のライブラリとソースコードもダウンロードされます。

はい これはやや面倒ですが、これは一度行われます。 次に、プロジェクトをビルドするには、buildozer.spec仕様ファイルを編集して、ビルドするプロジェクトにドロップします。 これまで自分で使用していないため、残りの仕様パラメータについては考慮しません。 そして、はい、iOS向けのビルドのオプションも軌道に乗ったままです。なぜなら、このプラットフォームを備えたデバイスを持っていないからです。
実際には、ブルドーザーのドアを閉じて滑走路から遠ざけます-プロジェクトフォルダーに入り、ターミナルでコンパイル開始コマンドを実行します。
buildozer android debug
切望されているメッセージが表示されるまでには、かなり時間がかかります(タバコとコーヒーが便利になりました)。

apk-checkはバーゲンとして取得されることに注意してください。 署名済みパッケージの作成プロセスについて説明したHabr に関する記事があります。 さらに、ビルドサイズは非常に印象的で、7.6 MBです。 これは、ブルドーザーのすべてのテストと不要なライブラリを含むアセンブリにすべてのPythonが含まれているためです。 また、Kivy自体は、アプリケーションで使用されていなくても、すべてのAPIに含まれています。
組み立てられたapkをデバイスにインストールして起動すると、アプリケーションはかなりの時間実行されます。 Kivyは、すべてのライブラリを抽出して展開するのに時間がかかります。 幸いなことに、プログラムのそれ以降のダウンロードはすべて5秒以下で終わります。
次の記事では、ブルドーザーを活用して、組み立てられたプロジェクトを見るためにプルするものを説明しますが、すでにはるかに小さい...

素敵なビルドを! トラックの下を見てください!