Skip to content

Commit ae913c0

Browse files
Merge branch 'master' into billing-api
Conflicts: docs/source/android.rst recipes/android/src/android.pyx recipes/android/src/android_jni.c src/build.py src/src/org/renpy/android/PythonActivity.java src/templates/AndroidManifest.tmpl.xml
2 parents 783407f + 6cf5232 commit ae913c0

Some content is hidden

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

52 files changed

+2481
-970
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ build
55
src/obj
66
src/local.properties
77
src/default.properties
8+
src/libs/armeabi
89
dist
910
*.pyc
1011
testsuite
12+
.packages
13+
14+
#ECLIPSE + PYDEV
15+
.project
16+
.pydevproject

README.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ Global overview
1414
---------------
1515

1616
#. Download Android NDK, SDK
17-
#. Launch "android", and download latest Android platform
17+
18+
* NDK: http://dl.google.com/android/ndk/android-ndk-r8c-linux-x86.tar.bz2
19+
20+
* More details at: http://developer.android.com/tools/sdk/ndk/index.html
21+
22+
* SDK: http://dl.google.com/android/android-sdk_r21.0.1-linux.tgz
23+
24+
* More details at:http://developer.android.com/sdk/index.html
25+
26+
#. Launch "android", and download latest Android platform, here API 14, which would be Android 4.0
27+
1828
#. Export some environment variables::
1929

2030
export ANDROIDSDK="/path/to/android/android-sdk-linux_86"
21-
export ANDROIDNDK="/path/to/android/android-ndk-r7"
22-
export ANDROIDNDKVER=r7
31+
export ANDROIDNDK="/path/to/android/android-ndk-r8c"
32+
export ANDROIDNDKVER=r8c
2333
export ANDROIDAPI=14
2434

35+
(Of course correct the paths mentioned in ANDROIDSDK and ANDROIDNDK)
36+
2537
#. Clone python-for-android::
2638

2739
git clone git://github.com/kivy/python-for-android

cythonizer.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os, sys
2+
3+
class cythonizer():
4+
def __init__(self,
5+
android_ndk = os.environ["ANDROIDNDK"],
6+
android_api = os.environ["ANDROIDAPI"],
7+
python_for_android = os.path.join(os.path.split(os.path.realpath(__file__))[0])
8+
):
9+
self.android_ndk = android_ndk
10+
self.android_api = android_api
11+
self.py_for_a = python_for_android
12+
13+
for path in [self.android_ndk, self.py_for_a]:
14+
if not os.path.isdir(path):
15+
print "!! Haven't found path:", repr(path)
16+
sys.exit()
17+
18+
self.gcc = "%s/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc" %(self.android_ndk)
19+
self.sysroot = "%s/platforms/android-%s/arch-arm" %(self.android_ndk, self.android_api)
20+
self.a_incl = "-I%s/platforms/android-%s/arch-arm/usr/include" %(self.android_ndk, self.android_api)
21+
self.p_incl = "-I%s/build/python-install/include/python2.7" %(self.py_for_a)
22+
self.libs = "-L%s/build/libs" %(self.py_for_a)
23+
self.p_libs = "-L%s/build/python-install/lib" %(self.py_for_a)
24+
self.a_libs = "-L%s/platforms/android-%s/arch-arm/usr/lib" %(self.android_ndk, self.android_api)
25+
26+
def make_o(self, c_file, o_file):
27+
command = """%s -mandroid -fomit-frame-pointer -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC --sysroot %s %s %s -c database.c -o database.o""" %(self.gcc,
28+
self.sysroot,
29+
self.a_incl,
30+
self.p_incl)
31+
print command
32+
33+
def make_so(self, o_file, so_file= None):
34+
if so_file == None:
35+
so_file = os.path.splitext(os.path.realpath(o_file))[0]+".so"
36+
command = """%s -shared -O3 -mandroid -fomit-frame-pointer --sysroot %s -lm -lGLESv2 -lpython2.7 %s %s %s %s -o %s """ %(self.gcc,
37+
self.sysroot,
38+
self.libs,
39+
self.p_libs,
40+
self.a_libs,
41+
o_file,
42+
so_file)
43+
print command
44+
def make(self, py_pyx):
45+
for root, dirs, files in os.walk(directory):
46+
for file in files:
47+
if file.endswith('.py') or file.endswith('.pyx'):
48+
print file
49+
self.make_o(py_pyx)
50+
self.make_so(py_pyx)
51+
52+
if __name__ == "__main__":
53+
c = cythonizer()
54+
c.make("test.py")

distribute.sh

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@
99
# Modules
1010
MODULES=$MODULES
1111

12+
# Resolve Python path
13+
PYTHON="$(which python2.7)"
14+
if [ "X$PYTHON" == "X" ]; then
15+
PYTHON="$(which python2)"
16+
fi
17+
if [ "X$PYTHON" == "X" ]; then
18+
PYTHON="$(which python)"
19+
fi
20+
1221
# Paths
13-
ROOT_PATH="$(dirname $(python -c 'import os,sys;print os.path.realpath(sys.argv[1])' $0))"
22+
ROOT_PATH="$(dirname $($PYTHON -c 'from __future__ import print_function; import os,sys;print(os.path.realpath(sys.argv[1]))' $0))"
1423
RECIPES_PATH="$ROOT_PATH/recipes"
1524
BUILD_PATH="$ROOT_PATH/build"
1625
LIBS_PATH="$ROOT_PATH/build/libs"
26+
JAVACLASS_PATH="$ROOT_PATH/build/java"
1727
PACKAGES_PATH="$ROOT_PATH/.packages"
1828
SRC_PATH="$ROOT_PATH/src"
1929
JNI_PATH="$SRC_PATH/jni"
@@ -42,8 +52,10 @@ if [ "X$WGET" == "X" ]; then
4252
echo "Error: you need at least wget or curl installed."
4353
exit 1
4454
else
45-
WGET="$WGET -L -O"
55+
WGET="$WGET -L -O -o"
4656
fi
57+
else
58+
WGET="$WGET -O"
4759
fi
4860

4961
case $OSTYPE in
@@ -123,7 +135,7 @@ function push_arm() {
123135
#export OFLAG="-Os"
124136
#export OFLAG="-O2"
125137

126-
export CFLAGS="-mandroid $OFLAG -fomit-frame-pointer --sysroot $NDKPLATFORM"
138+
export CFLAGS="-DANDROID -mandroid $OFLAG -fomit-frame-pointer --sysroot $NDKPLATFORM"
127139
if [ "X$ARCH" == "Xarmeabi-v7a" ]; then
128140
CFLAGS+=" -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb"
129141
fi
@@ -133,7 +145,7 @@ function push_arm() {
133145
export LDFLAGS="-lm"
134146

135147
# this must be something depending of the API level of Android
136-
PYPLATFORM=$(python -c 'import sys; print sys.platform')
148+
PYPLATFORM=$($PYTHON -c 'from __future__ import print_function; import sys; print(sys.platform)')
137149
if [ "$PYPLATFORM" == "linux2" ]; then
138150
PYPLATFORM="linux"
139151
elif [ "$PYPLATFORM" == "linux3" ]; then
@@ -150,7 +162,7 @@ function push_arm() {
150162
export TOOLCHAIN_VERSION=4.4.3
151163
fi
152164

153-
export PATH="$ANDROIDNDK/toolchains/$TOOLCHAIN_PREFIX-$TOOLCHAIN_VERSION/prebuilt/$PYPLATFORM-x86/bin/:$ANDROIDNDK:$ANDROIDSDK/tools:$PATH"
165+
export PATH="$ANDROIDNDK/toolchains/$TOOLCHAIN_PREFIX-$TOOLCHAIN_VERSION/prebuilt/$PYPLATFORM-x86/bin/:$ANDROIDNDK/toolchains/$TOOLCHAIN_PREFIX-$TOOLCHAIN_VERSION/prebuilt/$PYPLATFORM-x86_64/bin/:$ANDROIDNDK:$ANDROIDSDK/tools:$PATH"
154166

155167
# search compiler in the path, to fail now instead of later.
156168
CC=$(which $TOOLCHAIN_PREFIX-gcc)
@@ -213,6 +225,36 @@ function usage() {
213225
exit 0
214226
}
215227

228+
# Check installation state of a debian package list.
229+
# Return all missing packages.
230+
function check_pkg_deb_installed() {
231+
PKGS=$1
232+
MISSING_PKGS=""
233+
for PKG in $PKGS; do
234+
CHECK=$(dpkg -s $PKG 2>&1)
235+
if [ $? -eq 1 ]; then
236+
MISSING_PKGS="$PKG $MISSING_PKGS"
237+
fi
238+
done
239+
if [ "X$MISSING_PKGS" != "X" ]; then
240+
error "Packages missing: $MISSING_PKGS"
241+
error "It might break the compilation, except if you installed thoses packages manually."
242+
fi
243+
}
244+
245+
function check_build_deps() {
246+
DIST=$(lsb_release -is)
247+
info "Check build dependencies for $DIST"
248+
case $DIST in
249+
Debian|Ubuntu)
250+
check_pkg_deb_installed "build-essential zlib1g-dev cython"
251+
;;
252+
*)
253+
debug "Avoid check build dependencies, unknow platform $DIST"
254+
;;
255+
esac
256+
}
257+
216258
function run_prepare() {
217259
info "Check enviromnent"
218260
if [ "X$ANDROIDSDK" == "X" ]; then
@@ -289,6 +331,7 @@ function run_prepare() {
289331
test -d $PACKAGES_PATH || mkdir -p $PACKAGES_PATH
290332
test -d $BUILD_PATH || mkdir -p $BUILD_PATH
291333
test -d $LIBS_PATH || mkdir -p $LIBS_PATH
334+
test -d $JAVACLASS_PATH || mkdir -p $JAVACLASS_PATH
292335
test -d $LIBLINK_PATH || mkdir -p $LIBLINK_PATH
293336

294337
# create initial files
@@ -346,7 +389,7 @@ function run_source_modules() {
346389
debug "Read $module recipe"
347390
recipe=$RECIPES_PATH/$module/recipe.sh
348391
if [ ! -f $recipe ]; then
349-
error "Recipe $module does not exit"
392+
error "Recipe $module does not exist"
350393
exit -1
351394
fi
352395
source $RECIPES_PATH/$module/recipe.sh
@@ -388,6 +431,20 @@ function run_get_packages() {
388431

389432
for module in $MODULES; do
390433
# download dependencies for this module
434+
# check if there is not an overload from environment
435+
module_dir=$(eval "echo \$P4A_${module}_DIR")
436+
if [ "$module_dir" ]
437+
then
438+
debug "\$P4A_${module}_DIR is not empty, linking $module_dir dir instead of downloading"
439+
directory=$(eval "echo \$BUILD_${module}")
440+
if [ -e $directory ]; then
441+
try rm -rf "$directory"
442+
fi
443+
try mkdir -p "$directory"
444+
try rmdir "$directory"
445+
try ln -s "$module_dir" "$directory"
446+
continue
447+
fi
391448
debug "Download package for $module"
392449

393450
url="URL_$module"
@@ -429,7 +486,7 @@ function run_get_packages() {
429486
# download if needed
430487
if [ $do_download -eq 1 ]; then
431488
info "Downloading $url"
432-
try $WGET $url
489+
try $WGET $filename $url
433490
else
434491
debug "Module $module already downloaded"
435492
fi
@@ -536,6 +593,9 @@ function run_distribute() {
536593
try mkdir -p libs/$ARCH
537594
try cp -a $BUILD_PATH/libs/* libs/$ARCH/
538595

596+
debug "Copy java files from various libs"
597+
cp -a $BUILD_PATH/java/* src
598+
539599
debug "Fill private directory"
540600
try cp -a python-install/lib private/
541601
try mkdir -p private/include/python2.7
@@ -579,6 +639,7 @@ function run_biglink() {
579639
}
580640

581641
function run() {
642+
check_build_deps
582643
run_prepare
583644
run_source_modules
584645
run_get_packages
@@ -639,9 +700,9 @@ while getopts ":hvlfxm:d:s" opt; do
639700
f)
640701
DO_CLEAN_BUILD=1
641702
;;
642-
x)
643-
DO_SET_X=1
644-
;;
703+
x)
704+
DO_SET_X=1
705+
;;
645706
\?)
646707
echo "Invalid option: -$OPTARG" >&2
647708
exit 1
94.3 KB
Loading

0 commit comments

Comments
 (0)