Skip to content
Brian Gesiak edited this page Feb 24, 2016 · 14 revisions

Install required software

You need Ubuntu 15.10 64-bit to run the prebuilt version. (Other versions of Linux are not supported at this time)

If you don't have Android SDK's ADB, sudo apt-get install android-tools-adb

Install Android NDK - version r10e Linux 64-bit

Configure NDK and linker

run export ANDROID_NDK_HOME=/path/to/ndk

Install and run SwiftAndroid

Extract the downloaded file:

tar xf swift_android_2015-12-12.tar.xz

Write a simple Hello World program, and save it as hello.swift.

Now, try building the executable:

swiftandroid/bin/swiftc-android hello.swift

Run the resulting executable

Push the executable and all its dependent libraries to the Android device.

There's a script that will do this for you: run

swiftandroid/bin/swift-android-push hello

to push hello and the libraries to /data/local/tmp

Run the executable, passing LD_LIBRARY_PATH to where the executable and libraries are saved

adb shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/hello

Extra setup

Add swift to the PATH:

export PATH=$PATH:/path/to/swiftandroid/bin

Fix include paths in Bionic module:

swift androidfix

Building APKs

Install Android SDK

follow instructions on Google site. Basically

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386
sudo apt-get install openjdk-7-jdk`

Then download and install the Android SDK from http://developer.android.com/sdk/installing/index.html?pkg=tools

After installing, export the location of the Android SDK:

export ANDROID_HOME=/path/to/android-sdk-linux

Install Gradle plugin

see the README of the gradle plugin. Basically,

git clone https://github.com/SwiftAndroid/swift-android-gradle.git
cd swift-android-gradle
./gradlew install

Make sure you have Clang installed

sudo apt-get install clang

Try building the sample APK:

git clone https://github.com/SwiftAndroid/swift-android-samples.git`
cd swift-android-samples/swifthello
./gradlew installDebug

Building and running the test suite from source

You must have all the build prerequisites for Swift installed.

  1. On an Ubuntu 15.10 machine, git checkout the SwiftAndroid fork in the same directory as your Swift repository. It needs to be in the same position relative to swift-llvm, swift-clang, etc.
  2. Clone libiconv-libicu-android and run the build.sh script. This step is necessary because Android doesn't ship with libicu, which is used by Swift.
  3. From within your Swift checkout, run:
$ utils/build-script \
  -R \ # Build in ReleaseAssert mode.
  -T \ # Run all tests.
  --skip-test-linux \ # Don't bother testing Linux.
  --android \ # Build for Android.
  --android-ndk=/home/modocache/android-ndk-r10e \ # Path to an Android NDK.
  --android-ndk-version=21 \ # Android NDK version. Only 21+ is supported for now.
  --android-icu-uc /home/modocache/GitHub/apple/libiconv-libicu-android/armeabi-v7a \ # Path to libicuuc.so.
  --android-icu-uc-include /home/modocache/GitHub/apple/libiconv-libicu-android/armeabi-v7a/icu/source/common \ # Path to include files for libicu uc module.
  --android-icu-i18n /home/modocache/GitHub/apple/libiconv-libicu-android/armeabi-v7a \ # Path to libicui18n.so.
  --android-icu-i18n-include /home/modocache/GitHub/apple/libiconv-libicu-android/armeabi-v7a/icu/source/i18n/ \ # Path to include files for libicu i18n module.
  --android-deploy-device-path /data/local/tmp # Temporary directory on your Android device where tests are run.

Your Android device must be connected and available via adb devices in order to successfully run the tests.

You may encounter the following error when running tests:

--
Exit Code: 255

Command Output (stderr):
--
/home/modocache/GitHub/apple/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/armv7-none-linux-androideabi-ld: 2: exec: arm-linux-androideabi-ld.bfd: not found
clang-3.8: error: unable to execute command: No such file or directory
clang-3.8: error: linker command failed due to signal (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 255 (use -v to see invocation)

--

You should be able to work around this error by symlinking the ld from your Android NDK:

$ ln -s \
    $ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld.gold \
    /usr/bin/armv7-none-linux-androideabi-ld.gold

Issues, problems?

Please report any issues to the issue tracker