aboutsummaryrefslogtreecommitdiffstats
path: root/packaging/android/android-build-wrapper.sh
blob: 16d50ce82eb97ed2ef065b4904f0c96397b8feff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash -eu

# run this in the top level folder you want to create Android binaries in
#
# it seems that with Qt5.7 (and later) and current cmake there is an odd bug where
# cmake fails reporting :No known features for CXX compiler "GNU". In that
# case simly comment out the "set(property(TARGET Qt5::Core PROPERTY...)"
# at line 101 of
# Qt/5.7/android_armv7/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake
# or at line 95 of
# Qt/5.8/android_armv7/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake
# or at line 105 of
# Qt/5.9/android_armv7/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake
# (this script tries to do this automatically)

exec 1> >(tee ./build.log) 2>&1

USE_X=$(case $- in *x*) echo "-x" ;; esac)

# these are the current versions for Qt, Android SDK & NDK:
source subsurface/packaging/android/variables.sh

# avoid timeouts on Travis when downloads take a long time
SLOW_PROG=""
if [ -n "${TRAVIS:-}" ]; then
	source subsurface/scripts/travis-wait.sh
	set -x # make debugging Travis easier
	SLOW_PROG="travis_wait"
	# since we are running on Travis, let's just get our minimal Qt install
	mkdir -p Qt/"${LATEST_QT}"
	$SLOW_PROG wget -q https://storage.googleapis.com/travis-cache/Qt-"${LATEST_QT}"-android.tar.xz
	tar -xJ -C Qt/"${LATEST_QT}" -f Qt-"${LATEST_QT}"-android.tar.xz
fi

PLATFORM=$(uname)

pushd $(dirname "$0")/../../
export SUBSURFACE_SOURCE=$PWD
popd

if [ "$PLATFORM" = Linux ] ; then
	QT_BINARIES=qt-opensource-linux-x64-${LATEST_QT}.run
	NDK_BINARIES=${ANDROID_NDK}-linux-x86_64.zip
	SDK_TOOLS=sdk-tools-linux-${SDK_VERSION}.zip
else
	echo "only on Linux so far"
	exit 1
fi

# make sure we have the required commands installed
MISSING=
for i in git cmake autoconf libtool java wget unzip; do
	command -v $i >/dev/null ||
		if [ $i = libtool ] ; then
			MISSING="${MISSING}libtool-bin "
		elif [ $i = java ] ; then
			MISSING="${MISSING}openjdk-8-jdk "
		else
			MISSING="${MISSING}${i} "
		fi
done
if [ "$MISSING" ] ; then
	echo "The following packages are missing: $MISSING"
	echo "Please install via your package manager."
	exit 1
fi

# first we need to get the Android SDK and NDK
if [ ! -d "$ANDROID_NDK" ] ; then
	if [ ! -f "$NDK_BINARIES" ] ; then
		$SLOW_PROG wget -q https://dl.google.com/android/repository/"$NDK_BINARIES"
	fi
	unzip -q "$NDK_BINARIES"
fi

if [ ! -d "$ANDROID_SDK"/build-tools/"${ANDROID_BUILDTOOLS_REVISION}" ] ; then
	if [ ! -d "$ANDROID_SDK" ] ; then
		if [ ! -f "$SDK_TOOLS" ] ; then
			$SLOW_PROG wget -q https://dl.google.com/android/repository/"$SDK_TOOLS"
		fi
		mkdir "$ANDROID_SDK"
		pushd "$ANDROID_SDK"
		unzip -q ../"$SDK_TOOLS"
		yes | tools/bin/sdkmanager --licenses > /dev/null 2>&1 || echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > licenses/android-sdk-license
		cat licenses/android-sdk-license
		echo ""
	else
		pushd "$ANDROID_SDK"
		tools/bin/sdkmanager tools platform-tools 'platforms;'"${ANDROID_PLATFORMS}" 'build-tools;'"${ANDROID_BUILDTOOLS_REVISION}"
	fi
	popd
fi

# download the Qt installer including Android bits and unpack / install
QT_DOWNLOAD_URL=https://download.qt.io/archive/qt/${QT_VERSION}/${LATEST_QT}/${QT_BINARIES}
if [ ! -d Qt/"${LATEST_QT}"/android_armv7 ] ; then
	if [ -d Qt ] ; then
		# Over writing an exsisting installation stalls the installation script,
		# rename the exsisting Qt folder and notify then user.
		mv Qt Qt_OLD
		echo "Qt installation found, backing it up to Qt_OLD."
	fi
	if [ ! -f "${QT_BINARIES}" ] ; then
		$SLOW_PROG wget -q "${QT_DOWNLOAD_URL}"
	fi
	chmod +x ./"${QT_BINARIES}"
	./"${QT_BINARIES}" --platform minimal --script "$SUBSURFACE_SOURCE"/qt-installer-noninteractive.qs --no-force-installations
fi

# patch the cmake / Qt5.7.1 incompatibility mentioned above
sed -i 's/set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)/# set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)/' Qt/"${LATEST_QT}"/android_armv7/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake

if [ ! -d subsurface/libdivecomputer/src ] ; then
	pushd subsurface
	git submodule init
	git submodule update --recursive
	popd
fi

if [ ! -f subsurface/libdivecomputer/configure ] ; then
	pushd subsurface/libdivecomputer
	autoreconf --install
	autoreconf --install
	popd
fi

# and now we need a monotonic build number...
if [ ! -f ./buildnr.dat ] ; then
	BUILDNR=0
else
	BUILDNR=$(cat ./buildnr.dat)
fi
BUILDNR=$((BUILDNR+1))
echo "${BUILDNR}" > ./buildnr.dat

echo "Building Subsurface-mobile for Android, build nr ${BUILDNR}"

rm -f ./subsurface-mobile-build-arm/build/outputs/apk/*.apk
rm -df ./subsurface-mobile-build-arm/AndroidManifest.xml

if [ "$USE_X" ] ; then
	bash "$USE_X" "$SUBSURFACE_SOURCE"/packaging/android/build.sh -buildnr "$BUILDNR" arm "$@"
else
	bash "$SUBSURFACE_SOURCE"/packaging/android/build.sh -buildnr "$BUILDNR" arm "$@"
fi

ls -l ./subsurface-mobile-build-arm/build/outputs/apk/*.apk