Skip to content

Commit

Permalink
Merge pull request #50 from calabash/feature/align-sdk-versions-in-ma…
Browse files Browse the repository at this point in the history
…nifests-and-build-script

Align targetSdkVersion in manifests and build script
  • Loading branch information
jmoody authored Dec 14, 2017
2 parents 06d98cf + 4a1f7f1 commit 2bd4e33
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 22 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
language: android

sudo: required
dist: trusty
group: deprecated-2017Q4

before_install:
- sudo apt-get -qq update
- sudo apt-get install ant
Expand All @@ -10,10 +14,10 @@ script:
android:
components:
# The BuildTools version used by your project
- build-tools-19.1.0
- build-tools-22.0.1

# The SDK version used to compile your project
- android-19
- android-22

# Specify at least one system image,
# if you need to run emulator(s) during your tests
Expand All @@ -23,7 +27,7 @@ android:
notifications:
email:
recipients:
- joshua.moody@xamarin.com
- josmoo@microsoft.com
- v-ownibl@microsoft.com
on_success: change
on_failure: always
115 changes: 103 additions & 12 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
#!/usr/bin/env bash

set -e

source bin/log.sh

CALABASH_ANDROID_SERVER_VERSION=$(cat version | tr -d "\n")
ANDROID_API_LEVEL=19

SERVER_MANIFEST="server/AndroidManifest.xml"
BACKEND_MANIFEST="server/instrumentation-backend/AndroidManifest.xml"


# $1 is a path to an AndroidManifest.xml
# $2 is the manifest key to inspect
function sdk_version_from_manifest {
if [ ! -e "${1}" ]; then
error "Expected "${1}" to exist."
exit 1
fi

local version=$(
perl -lne "print $& if /${2}=\"\d+\"/" "${1}" | cut -d= -f2 | tr -d \"
)

if [ "${version}" = "" ]; then
error "Could not find key/value pair in file"
error " key: '${2}'"
error "file: ${1}"
exit 1
fi

echo -n $version
}

# $1 is a path to an AndroidManifest.xml
function target_sdk {
if [ ! -e "${1}" ]; then
error "Expected "${1}" to exist."
exit 1
fi

local version=$(sdk_version_from_manifest "${1}" "android:targetSdkVersion")
echo -n $version
}

# $1 is a path to an AndroidManifest.xml
function min_sdk {
if [ ! -e "${1}" ]; then
error "Expected "${1}" to exist."
exit 1
fi

local version=$(sdk_version_from_manifest "${1}" "android:minSdkVersion")
echo -n $version
}

function verify_tool {
command -v $1 > /dev/null
Expand All @@ -11,16 +62,45 @@ function verify_tool {
fi
}

banner "Inspecting Manifest Versions"

SERVER_API_LEVEL=$(target_sdk "${SERVER_MANIFEST}")
BACKEND_API_LEVEL=$(target_sdk "${BACKEND_MANIFEST}")

if [ "${SERVER_API_LEVEL}" != "${BACKEND_API_LEVEL}" ]; then
error "Expected android:targetSdkVersion to be the same in these files:"
echo -e "* ${BACKEND_API_LEVEL}\t<= ${BACKEND_MANIFEST}"
echo -e "* ${SERVER_API_LEVEL}\t<= x${SERVER_MANIFEST}"
exit 1
fi

ANDROID_API_LEVEL=$SERVER_API_LEVEL

SERVER_MIN_VERSION=$(min_sdk "${SERVER_MANIFEST}")
BACKEND_MIN_VERSION=$(min_sdk "${BACKEND_MANIFEST}")

if [ "${SERVER_MIN_VERSION}" != "${BACKEND_MIN_VERSION}" ]; then
error "Expected android:minSdkVersion to be the same in these files:"
error "* ${BACKEND_MIN_VERSION}\t<= ${BACKEND_MANIFEST}"
error "* ${SERVER_MIN_VERSION}\t<= ${SERVER_MANIFEST}"
exit 1
fi

info "android:targetSdkVersion=${SERVER_API_LEVEL}"
info " android:minSdkVersion=${SERVER_MIN_VERSION}"

banner "Expecting ANDROID env variables"

cd server

verify_tool ant

if [ -z ${ANDROID_TOOLS_DIR+x} ]; then
if [ -z ${ANDROID_HOME+x} ]; then
echo "\$ANDROID_HOME not set. Please specify an android home directory and \
error "\$ANDROID_HOME not set. Please specify an android home directory and \
rerun:"
echo "ANDROID_HOME=/path/to/android_home ./build.sh"
exit 2
error "ANDROID_HOME=/path/to/android_home ./build.sh"
exit 1
fi

if [ -d "${ANDROID_HOME}/build-tools" ]; then
Expand All @@ -29,19 +109,30 @@ if [ -z ${ANDROID_TOOLS_DIR+x} ]; then
elif [ -d "${ANDROID_HOME}/platform-tools" ]; then
export ANDROID_TOOLS_DIR="${ANDROID_HOME}/platform-tools"
else
echo "Unable to find android build tools in ${ANDROID_HOME}"
echo "For full instuctions see: https://github.com/calabash/calabash-androi\
error "Unable to find android build tools in ${ANDROID_HOME}"
error "For full instuctions see: https://github.com/calabash/calabash-androi\
d/wiki/Building-calabash-android"
exit 4
exit 1
fi
elif [ ! -d "${ANDROID_TOOLS_DIR}" ]; then
echo "Tools dir '${ANDROID_TOOLS_DIR}' does not exist"
echo "Please specify a valid tools dir and try again:"
echo "ANDROID_TOOLS_DIR=/path/to/tools_dir ./build.sh"
exit 3
error "Tools dir '${ANDROID_TOOLS_DIR}' does not exist"
error "Please specify a valid tools dir and try again:"
error "ANDROID_TOOLS_DIR=/path/to/tools_dir ./build.sh"
exit 1
fi

CMD="ant clean package -debug -Dtools.dir=${ANDROID_TOOLS_DIR}\
-Dandroid.api.level=${ANDROID_API_LEVEL} -Dversion=${CALABASH_ANDROID_SERVER_VERSION}"
echo "${CMD}"

shell "${CMD}"

$CMD

banner "Done"

info "Built server ${CALABASH_ANDROID_SERVER_VERSION} with command:"

shell "${CMD}"

info "android:targetSdkVersion=${SERVER_API_LEVEL}"
info " android:minSdkVersion=${SERVER_MIN_VERSION}"
16 changes: 12 additions & 4 deletions bin/log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@

function info {
if [ "${TERM}" = "dumb" ]; then
echo "INFO: $1"
echo -e "INFO: $1"
else
echo "$(tput setaf 2)INFO: $1$(tput sgr0)"
echo -e "$(tput setaf 2)INFO: $1$(tput sgr0)"
fi
}

function shell {
if [ "${TERM}" = "dumb" ]; then
echo -e "SHELL: $1"
else
echo -e "$(tput setaf 6)SHELL: $1$(tput sgr0)"
fi
}

function error {
if [ "${TERM}" = "dumb" ]; then
echo "ERROR: $1"
echo -e "ERROR: $1"
else
echo "$(tput setaf 1)ERROR: $1$(tput sgr0)"
echo -e "$(tput setaf 1)ERROR: $1$(tput sgr0)"
fi
}

Expand Down
4 changes: 2 additions & 2 deletions server/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
android:noHistory="true"
android:excludeFromRecents="true"/>
</application>
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="21"/>
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="22"/>
<instrumentation android:targetPackage="#targetPackage#" android:name="sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner" />
<instrumentation android:targetPackage="#targetPackage#" android:name="sh.calaba.instrumentationbackend.ClearAppData" />
<instrumentation android:targetPackage="#targetPackage#" android:name="sh.calaba.instrumentationbackend.ClearAppData2" />
Expand Down
2 changes: 1 addition & 1 deletion server/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<property name="dx" location="${tools.dir}/dx${bat}" />
<property name="aapt" location="${tools.dir}/aapt" />

<property name="android.lib" location="${env.ANDROID_HOME}/platforms/android-${android.api.level}/android.jar"/>
<path id="android.antlibs">
<pathelement path="${env.ANDROID_HOME}/tools/lib/ant-tasks.jar" />
Expand Down

0 comments on commit 2bd4e33

Please sign in to comment.