Skip to content

Commit 9d367a5

Browse files
Merge pull request #7 from flet-dev/android
Android support
2 parents c911b93 + 5865e26 commit 9d367a5

File tree

71 files changed

+27965
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+27965
-116
lines changed

.appveyor.yml

Lines changed: 157 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,164 @@ skip_commits:
99
- "*.md"
1010

1111
environment:
12-
FLUTTER_MACOS_URL: https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_3.10.3-stable.zip
12+
PYTHON_STACK: python 3.10
13+
FLUTTER_MACOS_URL: https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_3.10.5-stable.zip
1314
GITHUB_TOKEN:
1415
secure: doX0dwjWhBmT56aJqR9NCbtMFJpDpdYxPCIB4vQoHfSR+nTa+pLCo6Yv5qWpD/90
1516

17+
matrix:
18+
- job_name: Build Python for iOS
19+
job_group: build_python
20+
APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey
21+
22+
- job_name: Build Python for Android
23+
job_group: build_python
24+
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
25+
26+
- job_name: Publish serious_python package to pub.dev
27+
job_group: publish_package
28+
job_depends_on: build_python
29+
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
30+
1631
stack:
17-
- python 3.10
18-
19-
install:
20-
# update build version
21-
- ps: |
22-
if ($env:APPVEYOR_REPO_TAG_NAME) {
23-
$v = $env:APPVEYOR_REPO_TAG_NAME.replace("v", "")
24-
} else {
25-
$cv = [version](git describe --abbrev=0).substring(1)
26-
$v = "$($cv.major).$($cv.minor+1).0+$($env:APPVEYOR_BUILD_NUMBER)"
27-
}
28-
Update-AppveyorBuild -Version $v
29-
30-
# install Flutter
31-
- HOMEBREW_NO_AUTO_UPDATE=1 brew install cocoapods
32-
- curl $FLUTTER_MACOS_URL -o "$HOME/flutter_macos_stable.zip"
33-
- unzip -qq "$HOME/flutter_macos_stable.zip" -d $HOME
34-
- export PATH="$PATH:$HOME/flutter/bin"
35-
- flutter config --enable-macos-desktop
36-
- flutter doctor
37-
38-
# install Kivy toolchain
39-
- pip3 install kivy-ios
40-
- HOMEBREW_NO_AUTO_UPDATE=1 brew install autoconf automake libtool pkg-config
41-
- brew link libtool
42-
43-
build_script:
44-
# build Python 3
45-
- toolchain build python3
46-
- ls dist
47-
- sh: |
48-
DIST_FILE_NAME=dist/python-ios-dist-v$APPVEYOR_BUILD_VERSION.tar.gz
49-
tar -czvf $DIST_FILE_NAME dist/*
50-
appveyor PushArtifact $DIST_FILE_NAME -DeploymentName python-dist
51-
52-
# publish package
53-
- sh: |
54-
if [[ "$APPVEYOR_REPO_TAG_NAME" != "" ]]; then
55-
mkdir -p $HOME/Library/Application\ Support/dart
56-
echo $PUB_DEV_TOKEN | base64 --decode > $HOME/Library/Application\ Support/dart/pub-credentials.json
57-
dart pub publish --force
58-
elif [[ "$APPVEYOR_PULL_REQUEST_NUMBER" == "" ]]; then
59-
dart pub publish --dry-run
60-
fi
61-
62-
deploy:
63-
provider: GitHub
64-
auth_token: $(GITHUB_TOKEN)
65-
release: $(APPVEYOR_REPO_TAG_NAME)
66-
artifact: python-dist
67-
on:
68-
APPVEYOR_REPO_TAG: true
69-
70-
test: off
32+
- $PYTHON_STACK
33+
34+
for:
35+
# ======================================
36+
# Build Python for iOS
37+
# ======================================
38+
39+
- matrix:
40+
only:
41+
- job_name: Build Python for iOS
42+
43+
install:
44+
# update build version
45+
- ps: |
46+
if ($env:APPVEYOR_REPO_TAG_NAME) {
47+
$v = $env:APPVEYOR_REPO_TAG_NAME.replace("v", "")
48+
} else {
49+
$cv = [version](git describe --abbrev=0).substring(1)
50+
$v = "$($cv.major).$($cv.minor+1).0+$($env:APPVEYOR_BUILD_NUMBER)"
51+
}
52+
Update-AppveyorBuild -Version $v
53+
54+
# install Kivy toolchain
55+
- pip3 install kivy-ios
56+
- HOMEBREW_NO_AUTO_UPDATE=1 brew install autoconf automake libtool pkg-config
57+
- brew link libtool
58+
59+
build_script:
60+
# build Python 3
61+
- toolchain build python3
62+
- ls dist
63+
64+
# remove hostpython
65+
- rm -rf dist/hostpython3
66+
67+
# package the rest of dist
68+
- DIST_FILE_NAME=dist/python-ios-dist-v$APPVEYOR_BUILD_VERSION.tar.gz
69+
- tar -czvf $DIST_FILE_NAME dist/*
70+
- appveyor PushArtifact $DIST_FILE_NAME -DeploymentName python-dist-macos
71+
72+
deploy:
73+
provider: GitHub
74+
auth_token: $(GITHUB_TOKEN)
75+
release: $(APPVEYOR_REPO_TAG_NAME)
76+
artifact: python-dist-macos
77+
on:
78+
APPVEYOR_REPO_TAG: true
79+
80+
test: off
81+
82+
# ======================================
83+
# Build Python for Android
84+
# ======================================
85+
86+
- matrix:
87+
only:
88+
- job_name: Build Python for Android
89+
90+
install:
91+
# update build version
92+
- ps: |
93+
if ($env:APPVEYOR_REPO_TAG_NAME) {
94+
$v = $env:APPVEYOR_REPO_TAG_NAME.replace("v", "")
95+
} else {
96+
$cv = [version](git describe --abbrev=0).substring(1)
97+
$v = "$($cv.major).$($cv.minor+1).0+$($env:APPVEYOR_BUILD_NUMBER)"
98+
}
99+
Update-AppveyorBuild -Version $v
100+
101+
# install NDK
102+
- export ANDROID_SDK_ROOT="/usr/lib/android-sdk"
103+
- export NDK_VERSION=25.2.9519653
104+
- export SDK_VERSION=android-33
105+
- echo "y" | sdkmanager --install "ndk;$NDK_VERSION" --channel=3 > /dev/null
106+
- echo "y" | sdkmanager --install "platforms;$SDK_VERSION" > /dev/null
107+
108+
# install Kivy for Android
109+
- pip3 install python-for-android
110+
- pip3 install --upgrade cython
111+
- p4a --help
112+
- p4a create --requirements python3 --arch arm64-v8a --arch armeabi-v7a --arch x86_64 --sdk-dir $ANDROID_SDK_ROOT --ndk-dir $ANDROID_SDK_ROOT/ndk/$NDK_VERSION --dist-name serious_python
113+
114+
# package
115+
- BUNDLE_NAME=libpythonbundle.so
116+
117+
# arm64-v8a
118+
- pushd ~/.local/share/python-for-android/dists/serious_python/_python_bundle__arm64-v8a/_python_bundle
119+
- zip -r $BUNDLE_NAME .
120+
- mv $BUNDLE_NAME ../../libs/arm64-v8a
121+
- popd
122+
123+
# armeabi-v7a
124+
- pushd ~/.local/share/python-for-android/dists/serious_python/_python_bundle__armeabi-v7a/_python_bundle
125+
- zip -r $BUNDLE_NAME .
126+
- mv $BUNDLE_NAME ../../libs/armeabi-v7a
127+
- popd
128+
129+
# armeabi-v7a
130+
- pushd ~/.local/share/python-for-android/dists/serious_python/_python_bundle__x86_64/_python_bundle
131+
- zip -r $BUNDLE_NAME .
132+
- mv $BUNDLE_NAME ../../libs/x86_64
133+
- popd
134+
135+
# package all .so files
136+
- DIST_FILE_NAME=python-android-dist-v$APPVEYOR_BUILD_VERSION.zip
137+
- pushd ~/.local/share/python-for-android/dists/serious_python/libs
138+
- zip -r $DIST_FILE_NAME .
139+
- appveyor PushArtifact $DIST_FILE_NAME -DeploymentName python-dist-android
140+
- popd
141+
142+
deploy:
143+
provider: GitHub
144+
auth_token: $(GITHUB_TOKEN)
145+
release: $(APPVEYOR_REPO_TAG_NAME)
146+
artifact: python-dist-android
147+
on:
148+
APPVEYOR_REPO_TAG: true
149+
150+
# =========================================
151+
# Publish serious_python package to pub.dev
152+
# =========================================
153+
154+
- matrix:
155+
only:
156+
- job_name: Publish serious_python package to pub.dev
157+
158+
install:
159+
- flutter upgrade --force
160+
161+
build_script:
162+
# publish package
163+
- sh: |
164+
if [[ "$APPVEYOR_REPO_TAG_NAME" != "" ]]; then
165+
mkdir -p $HOME/Library/Application\ Support/dart
166+
echo $PUB_DEV_TOKEN | base64 --decode > $HOME/Library/Application\ Support/dart/pub-credentials.json
167+
dart pub publish --force
168+
elif [[ "$APPVEYOR_PULL_REQUEST_NUMBER" == "" ]]; then
169+
dart pub publish --dry-run
170+
fi
171+
172+
test: off

.metadata

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: 796c8ef79279f9c774545b3771238c3098dbefab
8+
channel: stable
9+
10+
project_type: plugin_ffi
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
17+
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
18+
- platform: android
19+
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
20+
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
21+
- platform: ios
22+
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
23+
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
24+
25+
# User provided section
26+
27+
# List of Local paths (relative to this file) that should be
28+
# ignored by the migrate tool.
29+
#
30+
# Files that are not part of the templates will be ignored by default.
31+
unmanaged_files:
32+
- 'lib/main.dart'
33+
- 'ios/Runner.xcodeproj/project.pbxproj'

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0
2+
3+
Android support.
4+
15
## 0.1.5
26

37
* SeriousPython.run() should be split into two methods to return temp dir with unpacked python app ([#6](https://github.com/flet-dev/serious-python/issues/6)).

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributing to `serious_python`
2+
3+
## Releasing a new version
4+
5+
Bump version in:
6+
7+
* `pubspec.yaml`
8+
* `android/build.gradle`
9+
* `ios/serious_python.podspec`
10+
11+
Bump `serious_python` dependency version with `flutter pub get` in example lock files:
12+
13+
* `example/flet_example/pubspec.lock`
14+
* `example/flask_example/pubspec.lock`

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ Build app backend service in Python and host it inside a Flutter app. Flutter ap
88

99
Serious Python is part of [Flet](https://flet.dev) project - the fastest way to build Flutter apps in Python. The motivation for building Serious Python was having a re-usable easy-to-use plugin, maintained and supported, to run real-world Python apps, not just "1+2" or "hello world" examples, on iOS or Android devices and hence the name "Serious Python".
1010

11-
Serious Python relies on [Kivy toolchain for iOS](https://github.com/kivy/kivy-ios) to build Python runtime and native packages.
12-
1311
## Platform Support
1412

15-
| iOS | Android |
13+
| iOS | Android |
1614
| :-----: | :----------: |
17-
|| Coming soon |
15+
|| |
1816

1917
### Python versions
2018

2119
iOS version of plugin is based on [Kivy toolchain](https://github.com/kivy/kivy-ios) and currently uses Python 3.10.10.
2220

21+
Android version of plugin is based on [Kivy python-for-android](https://github.com/kivy/python-for-android) and currently uses Python 3.10.10.
22+
2323
## Usage
2424

2525
Zip your Python app into `app.zip`, copy to `app` (or any other) directory in the root of your Flutter app and add it as an asset to `pubspec.yaml`:

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ include: package:flutter_lints/flutter.yaml
22

33
# Additional information about this file can be found at
44
# https://dart.dev/guides/language/analysis-options
5+
6+
analyzer:
7+
exclude: [lib/src/android/gen.dart]

android/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx
10+
/src/main/jniLibs

android/build.gradle

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
group 'com.flet.serious_python'
2+
version '0.2.0'
3+
4+
buildscript {
5+
repositories {
6+
google()
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
// The Android Gradle Plugin knows how to build native code with the NDK.
12+
classpath 'com.android.tools.build:gradle:7.3.0'
13+
classpath 'de.undercouch:gradle-download-task:4.1.2'
14+
}
15+
}
16+
17+
rootProject.allprojects {
18+
repositories {
19+
google()
20+
mavenCentral()
21+
}
22+
}
23+
24+
apply plugin: 'com.android.library'
25+
apply plugin: 'de.undercouch.download'
26+
27+
android {
28+
// Bumping the plugin compileSdkVersion requires all clients of this plugin
29+
// to bump the version in their app.
30+
compileSdkVersion 31
31+
32+
// Bumping the plugin ndkVersion requires all clients of this plugin to bump
33+
// the version in their app and to download a newer version of the NDK.
34+
ndkVersion "23.1.7779620"
35+
36+
// Invoke the shared CMake build with the Android Gradle Plugin.
37+
externalNativeBuild {
38+
cmake {
39+
path "../src/CMakeLists.txt"
40+
41+
// The default CMake version for the Android Gradle Plugin is 3.10.2.
42+
// https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
43+
//
44+
// The Flutter tooling requires that developers have CMake 3.10 or later
45+
// installed. You should not increase this version, as doing so will cause
46+
// the plugin to fail to compile for some customers of the plugin.
47+
// version "3.10.2"
48+
}
49+
}
50+
51+
compileOptions {
52+
sourceCompatibility JavaVersion.VERSION_1_8
53+
targetCompatibility JavaVersion.VERSION_1_8
54+
}
55+
56+
defaultConfig {
57+
minSdkVersion 16
58+
}
59+
}
60+
61+
import de.undercouch.gradle.tasks.download.Download
62+
63+
task downloadZipFile(type: Download) {
64+
src "https://github.com/flet-dev/serious-python/releases/download/v${version}/python-android-dist-v${version}.zip"
65+
dest new File(buildDir, "python-android-dist-v${version}.zip")
66+
}
67+
68+
task unzipFile(dependsOn: downloadZipFile, type: Copy) {
69+
from zipTree(downloadZipFile.dest)
70+
into 'src/main/jniLibs'
71+
}
72+
73+
preBuild.dependsOn unzipFile

android/settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'serious_python'

0 commit comments

Comments
 (0)