Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
inclement committed Nov 25, 2017
2 parents 726ddeb + d1c44c7 commit 73a6ae8
Show file tree
Hide file tree
Showing 136 changed files with 2,894 additions and 2,455 deletions.
4 changes: 4 additions & 0 deletions doc/source/old_toolchain/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ using distribute.sh and build.py. This it entirely superseded by the
new toolchain, you do not need to read it unless using this old
method.

.. warning:: The old toolchain is deprecated and no longer
supported. You should instead use the :doc:`current version
<../quickstart>`.

Python for android is a project to create your own Python distribution
including the modules you want, and create an apk including python, libs, and
your application.
Expand Down
28 changes: 25 additions & 3 deletions doc/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,45 @@ Installing Android SDK

You need to download and unpack the Android SDK and NDK to a directory (let's say $HOME/Documents/):

- `Android SDK <https://developer.android.com/sdk/index.html#Other>`_
- `Android SDK <https://developer.android.com/studio/index.html>`_
- `Android NDK <https://developer.android.com/ndk/downloads/index.html>`_

For the Android SDK, you can download 'just the command line
tools'. When you have extracted these you'll see only a directory
named ``tools``, and you will need to run extra commands to install
the SDK packages needed.

For Android NDK, note that modern releases will only work on a 64-bit
operating system. If you are using a 32-bit distribution (or hardware),
the latest useable NDK version is r10e, which can be downloaded here:

- `Legacy 32-bit Linux NDK r10e <http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86.bin>`_

First, install a platform to target (you can also replace ``19`` with
a different platform number, this will be used again later)::

$SDK_DIR/tools/bin/sdkmanager "platforms;android-19"

Second, install the build-tools. You can use
``$SDK_DIR/tools/bin/sdkmanager --list`` to see all the
possibilities, but 26.0.2 is the latest version at the time of writing::

$SDK_DIR/tools/bin/sdkmanager "build-tools;26.0.2"

Then, you can edit your ``~/.bashrc`` or other favorite shell to include new environment variables necessary for building on android::

# Adjust the paths!
export ANDROIDSDK="$HOME/Documents/android-sdk-21"
export ANDROIDNDK="$HOME/Documents/android-ndk-r10e"
export ANDROIDAPI="14" # Minimum API version your application require
export ANDROIDAPI="19" # Minimum API version your application require
export ANDROIDNDKVER="r10e" # Version of the NDK you installed

You have the possibility to configure on any command the PATH to the SDK, NDK and Android API using:

- :code:`--sdk_dir PATH` as an equivalent of `$ANDROIDSDK`
- :code:`--ndk_dir PATH` as an equivalent of `$ANDROIDNDK`
- :code:`--android_api VERSION` as an equivalent of `$ANDROIDAPI`
- :code:`--ndk_ver PATH` as an equivalent of `$ANDROIDNDKVER`
- :code:`--ndk_version PATH` as an equivalent of `$ANDROIDNDKVER`


Usage
Expand Down
12 changes: 7 additions & 5 deletions doc/source/services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ Services support a range of options and interactions not yet
documented here but all accessible via calling other methods of the
``service`` reference.

.. note:: The app root directory for Python imports will be in the app
root folder even if the service file is in a subfolder. To import from
your service folder you must use e.g. ``import service.module``
instead of ``import module``, if the service file is in the
``service/`` folder.
.. note::

The app root directory for Python imports will be in the app
root folder even if the service file is in a subfolder. To import from
your service folder you must use e.g. ``import service.module``
instead of ``import module``, if the service file is in the
``service/`` folder.
18 changes: 18 additions & 0 deletions doc/source/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,21 @@ This error appears in the logcat log if you try to access
``org.renpy.android.PythonActivity`` from within the new toolchain. To
fix it, change your code to reference
``org.kivy.android.PythonActivity`` instead.

websocket-client: if you see errors relating to 'SSL not available'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ensure you have the package backports.ssl-match-hostname in the buildozer requirements, since Kivy targets python 2.7.x

You may also need sslopt={"cert_reqs": ssl.CERT_NONE} as a parameter to ws.run_forever() if you get an error relating to host verification

Requested API target 19 is not available, install it with the SDK android tool
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This means that your SDK is missing the required platform tools. You
need to install the ``platforms;android-19`` package in your SDK,
using the ``android`` or ``sdkmanager`` tools (depending on SDK
version).

If using buildozer this should be done automatically, but as a
workaround you can run these from
``~/.buildozer/android/platform/android-sdk-20/tools/android``.
2 changes: 1 addition & 1 deletion pythonforandroid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = '0.5.2'
__version__ = '0.6.0'
31 changes: 25 additions & 6 deletions pythonforandroid/archs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os.path import (join, dirname)
from os.path import (exists, join, dirname)
from os import environ, uname
import sys
from distutils.spawn import find_executable
Expand Down Expand Up @@ -33,13 +33,32 @@ def include_dirs(self):
def get_env(self, with_flags_in_cc=True):
env = {}

env["CFLAGS"] = " ".join([
"-DANDROID", "-mandroid", "-fomit-frame-pointer",
"--sysroot", self.ctx.ndk_platform])
env['CFLAGS'] = ' '.join([
'-DANDROID', '-mandroid', '-fomit-frame-pointer'
' -D__ANDROID_API__={}'.format(self.ctx._android_api),
])
env['LDFLAGS'] = ' '

sysroot = join(self.ctx._ndk_dir, 'sysroot')
if exists(sysroot):
# post-15 NDK per
# https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md
env['CFLAGS'] += ' -isystem {}/sysroot/usr/include/{}'.format(
self.ctx.ndk_dir, self.ctx.toolchain_prefix)
else:
sysroot = self.ctx.ndk_platform
env['CFLAGS'] += ' -I{}'.format(self.ctx.ndk_platform)
env['CFLAGS'] += ' -isysroot {} '.format(sysroot)
env['CFLAGS'] += '-I' + join(self.ctx.get_python_install_dir(),
'include/python{}'.format(
self.ctx.python_recipe.version[0:3])
)

env['LDFLAGS'] += '--sysroot {} '.format(self.ctx.ndk_platform)

env["CXXFLAGS"] = env["CFLAGS"]

env["LDFLAGS"] = " ".join(['-lm', '-L' + self.ctx.get_libs_dir(self.arch)])
env["LDFLAGS"] += " ".join(['-lm', '-L' + self.ctx.get_libs_dir(self.arch)])

if self.ctx.ndk == 'crystax':
env['LDFLAGS'] += ' -L{}/sources/crystax/libs/{} -lcrystax'.format(self.ctx.ndk_dir, self.arch)
Expand Down Expand Up @@ -102,7 +121,7 @@ def get_env(self, with_flags_in_cc=True):

hostpython_recipe = Recipe.get_recipe('hostpython2', self.ctx)

# AND: This hardcodes python version 2.7, needs fixing
# This hardcodes python version 2.7, needs fixing
env['BUILDLIB_PATH'] = join(
hostpython_recipe.get_build_dir(self.arch),
'build', 'lib.linux-{}-2.7'.format(uname()[-1]))
Expand Down
13 changes: 6 additions & 7 deletions pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import importlib

from pythonforandroid.logger import (warning, shprint, info, logger,
debug)
debug, error)
from pythonforandroid.util import (current_directory, ensure_dir,
temp_directory, which)
from pythonforandroid.recipe import Recipe
Expand Down Expand Up @@ -178,8 +178,6 @@ def get_bootstrap(cls, name, ctx):
This is the only way you should access a bootstrap class, as
it sets the bootstrap directory correctly.
'''
# AND: This method will need to check user dirs, and access
# bootstraps in a slightly different way
if name is None:
return None
if not hasattr(cls, 'bootstraps'):
Expand All @@ -195,20 +193,21 @@ def get_bootstrap(cls, name, ctx):
bootstrap.ctx = ctx
return bootstrap

def distribute_libs(self, arch, src_dirs, wildcard='*'):
def distribute_libs(self, arch, src_dirs, wildcard='*', dest_dir="libs"):
'''Copy existing arch libs from build dirs to current dist dir.'''
info('Copying libs')
tgt_dir = join('libs', arch.arch)
tgt_dir = join(dest_dir, arch.arch)
ensure_dir(tgt_dir)
for src_dir in src_dirs:
for lib in glob.glob(join(src_dir, wildcard)):
shprint(sh.cp, '-a', lib, tgt_dir)

def distribute_javaclasses(self, javaclass_dir):
def distribute_javaclasses(self, javaclass_dir, dest_dir="src"):
'''Copy existing javaclasses from build dir to current dist dir.'''
info('Copying java files')
ensure_dir(dest_dir)
for filename in glob.glob(javaclass_dir):
shprint(sh.cp, '-a', filename, 'src')
shprint(sh.cp, '-a', filename, dest_dir)

def distribute_aars(self, arch):
'''Process existing .aar bundles and copy to current dist dir.'''
Expand Down
2 changes: 0 additions & 2 deletions pythonforandroid/bootstraps/pygame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def run_distribute(self):

info('Copying python distribution')
hostpython = sh.Command(self.ctx.hostpython)
# AND: This *doesn't* need to be in arm env?
try:
shprint(hostpython, '-OO', '-m', 'compileall', self.ctx.get_python_install_dir(),
_tail=10, _filterout="^Listing")
Expand All @@ -64,7 +63,6 @@ def run_distribute(self):
shprint(sh.cp, '-a', join('python-install', 'lib'), 'private')
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))

# AND: Copylibs stuff should go here
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))

Expand Down
Loading

0 comments on commit 73a6ae8

Please sign in to comment.