-
-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build packages for Android #647
Changes from 2 commits
d5dfa2f
0661084
06c5da5
6ce88d1
a42cb81
f94f62b
8f9267b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,6 +379,40 @@ def install_app_support_package(self, app: BaseConfig): | |
print() | ||
raise InvalidSupportPackage(support_package_url) | ||
|
||
def build_env(self, app: BaseConfig): | ||
""" | ||
Return an environment in which to build the dependencies for the app. | ||
This should include the path to Python.h in CPPFLAGS, and libpython | ||
and its path in LDFLAGS. | ||
|
||
:param app: The config object for the app | ||
""" | ||
env = dict(os.environ) | ||
if self.platform == "android": | ||
# sysconfig.get_config_var("INCLUDEPY") | ||
includepy = os.path.join( | ||
self.bundle_path(app), "app", "include", | ||
"python{}m".format(self.python_version_tag), | ||
) | ||
assert os.path.exists(includepy), includepy | ||
cppflags = env.get("CPPFLAGS", "").split(" ") | ||
cppflags = [ | ||
"-I{}".format(includepy.replace(" ", "\\ ")), | ||
] + cppflags | ||
env.update({"CPPFLAGS": " ".join(cppflags)}) | ||
# sysconfig.get_config_var("LIBDIR") | ||
libdir = os.path.join( | ||
self.bundle_path(app), "app", "libs", "arm64-v8a" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it hardcoded for arm64-v8a? It should be compatible with all available targets, as the emulator can run with a x86_64 arch for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good point. This will require changes to the beeware/Python-Android-support project to include four architecture-specific "app_packages" directories, as well as changes to the beeware/briefcase-android-gradle-template project to add the right directory to sys.path. I'll try to implement this. Edit: We may be able to avoid architecture-specific directories by having architecture-specific filename extensions. This is set by the variable |
||
) | ||
assert os.path.exists(libdir), libdir | ||
ldflags = env.get("LDFLAGS", "").split(" ") | ||
ldflags = [ | ||
"-L{}".format(libdir.replace(" ", "\\ ")), | ||
"-lpython{}m".format(self.python_version_tag), | ||
] + ldflags | ||
env.update({"LDFLAGS": " ".join(ldflags)}) | ||
return env | ||
|
||
def install_app_dependencies(self, app: BaseConfig): | ||
""" | ||
Install the dependencies for the app. | ||
|
@@ -387,15 +421,19 @@ def install_app_dependencies(self, app: BaseConfig): | |
""" | ||
if app.requires: | ||
try: | ||
pip = [sys.executable, "-m", "pip"] | ||
options = [ | ||
"--upgrade", | ||
"--no-user", | ||
"--target={}".format(self.app_packages_path(app)), | ||
] | ||
if self.platform == "android": | ||
pip = [sys.executable, "-m", "androidenv"] + pip | ||
options += ["--no-binary", ":all:"] | ||
self.subprocess.run( | ||
[ | ||
sys.executable, "-m", | ||
"pip", "install", | ||
"--upgrade", | ||
"--no-user", | ||
"--target={}".format(self.app_packages_path(app)), | ||
] + app.requires, | ||
pip + ["install"] + options + app.requires, | ||
check=True, | ||
env=self.build_env(app), | ||
) | ||
except subprocess.CalledProcessError: | ||
raise DependencyInstallError() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path doesn't exist, is the trailing 'm' a mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "m" is a suffix added by Python when it is configured with --with-pymalloc. It seems this is only valid for 3.6 and 3.7: https://github.com/beeware/Python-Android-support/blob/master/main.sh#L84 I'll fix this.