Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Android native libraries through Gradle #1152

Merged
merged 23 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1cbd8ed
gitignore gradle 'externalNativeBuild' files
matteblair Sep 6, 2016
6f8c405
Update Gradle build dependencies in Android SDK and demo
matteblair Sep 6, 2016
9e7353f
Add 'externalNativeBuild' configuration to Android SDK Gradle script
matteblair Sep 6, 2016
578563a
Remove NDK toolchain checks and debugging config from android.cmake
matteblair Sep 6, 2016
f0de40c
Remove android.toolchain.cmake, no longer needed
matteblair Sep 7, 2016
991ddc9
Move cpp compile flags into Android SDK build.gradle
matteblair Sep 7, 2016
3a81038
Update Makefile for gradle cmake Android build
matteblair Sep 7, 2016
1fa6600
Remove mindk installation on travis
matteblair Sep 7, 2016
eb78365
Add NDK download step to travis
matteblair Sep 7, 2016
43f52a1
Add step to download Android CMake package on Travis
matteblair Sep 7, 2016
3afa794
Increase Gradle JVM heap size to 2048MB
matteblair Nov 10, 2016
0cc0176
Update Android target API to 25
matteblair Nov 10, 2016
5725dfb
Remove custom Android debug configs
matteblair Nov 10, 2016
f053534
Remove custom library output locations for Android
matteblair Nov 10, 2016
b86b23f
Move Android sources into standard locations
matteblair Nov 10, 2016
44784e1
Use 'sudo: enabled' travis config
matteblair Nov 11, 2016
d77bc87
Update Android dependencies for Travis
matteblair Sep 7, 2016
5fe223a
Copy a license file for Android components on travis
matteblair Dec 8, 2016
e2625e1
Clean up travis apt packages for Android
matteblair Dec 8, 2016
54f4b13
Add 'slim' and 'full' configurations for Android SDK
matteblair Dec 8, 2016
b3a4c1a
Update CI scripts for new Android build commands
matteblair Dec 9, 2016
4380917
Add '-g' cpp flag to android debug builds
matteblair Dec 21, 2016
52b16fe
Update Android build instructions in README
matteblair Dec 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ proguard/
# Log Files
*.log

*.externalNativeBuild

### Xcode ###
*.pbxuser
Expand Down
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: android

sudo: enabled

branches:
only:
- master
Expand All @@ -16,10 +18,10 @@ matrix:
env: PLATFORM=android
addons:
apt:
sources: [ 'kubuntu-backports', 'george-edison55-precise-backports' ]
packages: [ 'cmake', 'lib32z1-dev', 'lib32stdc++6', 's3cmd' ]
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'libstdc++6', 's3cmd' ]
android:
components: [ 'tools', 'build-tools-24.0.2', 'extra-android-m2repository', 'android-24' ]
components: [ 'tools', 'build-tools-25.0.0', 'extra-android-m2repository', 'android-25' ]
jdk: oraclejdk8

before_install:
Expand All @@ -41,5 +43,3 @@ script:
after_success:
- source ./scripts/travis/script_deploy_android_snapshot.sh
- source ./scripts/travis/script_deploy_android_demo.sh

sudo: false
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ endif()

include(${PROJECT_SOURCE_DIR}/toolchains/utils.cmake)

# cmake output configuration
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# platform lookup
set(SUPPORTED_TARGETS darwin ios android raspberrypi linux tizen ios.framework)

Expand Down Expand Up @@ -59,6 +54,13 @@ endif()
# setting up cache variable platform
set(PLATFORM ${varplatform} CACHE INTERNAL "platform" FORCE)

# cmake output configuration
if(NOT ${PLATFORM_TARGET} STREQUAL android)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

# cmake inclusions and definitions
set(CMAKE_TARGET_FILE ${PROJECT_SOURCE_DIR}/toolchains/${PLATFORM_TARGET}.cmake)

Expand Down
99 changes: 6 additions & 93 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ all: android osx ios
.PHONY: check-ndk
.PHONY: cmake-osx
.PHONY: cmake-xcode
.PHONY: cmake-android
.PHONY: cmake-ios
.PHONY: cmake-ios-framework
.PHONY: cmake-ios-framework-sim
.PHONY: cmake-rpi
.PHONY: cmake-linux
.PHONY: install-android

ANDROID_BUILD_DIR = build/android
ANDROID_BUILD_DIR = android/tangram/build
OSX_BUILD_DIR = build/osx
OSX_XCODE_BUILD_DIR = build/xcode
IOS_BUILD_DIR = build/ios
Expand Down Expand Up @@ -71,45 +70,6 @@ ifdef RELEASE
BUILD_TYPE = -DCMAKE_BUILD_TYPE=Release
endif

ifdef ANDROID_ARCH
ANDROID_BUILD_DIR = build/android-${ANDROID_ARCH}
ifeq ($(ANDROID_ARCH), x86)
ANDROID_TOOLCHAIN = x86-clang3.6
endif
ifeq ($(ANDROID_ARCH), x86_64)
ANDROID_TOOLCHAIN = x86_64-clang3.6
ANDROID_API_LEVEL = android-21
endif
ifeq ($(ANDROID_ARCH), armeabi)
ANDROID_TOOLCHAIN = arm-linux-androideabi-clang3.6
endif
ifeq ($(ANDROID_ARCH), armeabi-v7a)
ANDROID_TOOLCHAIN = arm-linux-androideabi-clang3.6
endif
ifeq ($(ANDROID_ARCH), arm64-v8a)
ANDROID_TOOLCHAIN = aarch64-linux-android-clang3.6
ANDROID_API_LEVEL = android-21
endif
ifeq ($(ANDROID_ARCH), mips)
ANDROID_TOOLCHAIN = mipsel-linux-android-clang3.6
endif
ifeq ($(ANDROID_ARCH), mips64)
ANDROID_TOOLCHAIN = mips64el-linux-android-clang3.6
ANDROID_API_LEVEL = android-21
endif
else
ANDROID_ARCH = armeabi-v7a
ANDROID_TOOLCHAIN = arm-linux-androideabi-clang3.6
endif

#$(info ANDROID_ARCH is ${ANDROID_ARCH})
#$(info ANDROID_TOOLCHAIN is ${ANDROID_TOOLCHAIN})
#$(info ANDROID_BUILD_DIR is ${ANDROID_BUILD_DIR})

ifndef ANDROID_API_LEVEL
ANDROID_API_LEVEL = android-15
endif

ifndef TANGRAM_CMAKE_OPTIONS
TANGRAM_CMAKE_OPTIONS = \
-DBENCHMARK=0 \
Expand All @@ -126,19 +86,6 @@ UNIT_TESTS_CMAKE_PARAMS = \
-DAPPLICATION=0 \
-DCMAKE_BUILD_TYPE=Debug

ANDROID_CMAKE_PARAMS = \
${BUILD_TYPE} \
${CMAKE_OPTIONS} \
-DPLATFORM_TARGET=android \
-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_DIR}/android.toolchain.cmake \
-DMAKE_BUILD_TOOL=$$ANDROID_NDK/prebuilt/darwin-x86_64/bin/make \
-DANDROID_ABI=${ANDROID_ARCH} \
-DANDROID_STL=c++_static \
-DANDROID_TOOLCHAIN_NAME=${ANDROID_TOOLCHAIN} \
-DANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL} \
-DLIBRARY_OUTPUT_PATH_ROOT=../../android/tangram \
-DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE

IOS_CMAKE_PARAMS = \
${BUILD_TYPE} \
${CMAKE_OPTIONS} \
Expand Down Expand Up @@ -211,12 +158,10 @@ clean: clean-android clean-osx clean-ios clean-rpi clean-tests clean-xcode clean
clean-tizen-arm clean-tizen-x86

clean-android:
rm -rf ${ANDROID_BUILD_DIR}
rm -rf android/build
rm -rf android/tangram/build
rm -rf android/tangram/libs
rm -rf android/tangram/.externalNativeBuild
rm -rf android/demo/build
rm -rf android/demo/libs

clean-osx:
rm -rf ${OSX_BUILD_DIR}
Expand Down Expand Up @@ -257,33 +202,17 @@ clean-ios-framework-sim:
clean-ios-framework-universal:
rm -rf ${IOS_FRAMEWORK_UNIVERSAL_BUILD_DIR}

android: android-demo-apk
android: android-demo
@echo "run: 'adb install -r android/demo/build/outputs/apk/demo-debug.apk'"

android-tangram-apk:
android-sdk:
@cd android/ && \
./gradlew tangram:assembleDebug
./gradlew tangram:assembleFullRelease

android-demo-apk: android-native-lib
android-demo:
@cd android/ && \
./gradlew demo:assembleDebug

android-native-lib: android/tangram/libs/${ANDROID_ARCH}/libtangram.so

android/tangram/libs/${ANDROID_ARCH}/libtangram.so: install-android

install-android: ${ANDROID_BUILD_DIR}/Makefile
@cd ${ANDROID_BUILD_DIR} && \
${MAKE} && \
${MAKE} install

${ANDROID_BUILD_DIR}/Makefile: check-ndk cmake-android

cmake-android:
@mkdir -p ${ANDROID_BUILD_DIR}
@cd ${ANDROID_BUILD_DIR} && \
cmake ../.. ${ANDROID_CMAKE_PARAMS}

osx: ${OSX_BUILD_DIR}/Makefile
@cd ${OSX_BUILD_DIR} && \
${MAKE}
Expand Down Expand Up @@ -394,11 +323,6 @@ benchmark:
cmake ../../ ${BENCH_CMAKE_PARAMS} && \
${MAKE}

check-ndk:
ifndef ANDROID_NDK
$(error ANDROID_NDK is undefined)
endif

format:
@for file in `git diff --diff-filter=ACMRTUXB --name-only -- '*.cpp' '*.h'`; do \
if [[ -e $$file ]]; then clang-format -i $$file; fi \
Expand All @@ -408,14 +332,3 @@ format:
### Android Helpers
android-install:
@adb install -r android/demo/build/outputs/apk/demo-debug.apk

android-debug:
@cd android/demo && \
cp -a ../tangram/libs . && \
mkdir -p jni && \
cp ../tangram/jni/*.mk jni && \
python2 $$ANDROID_NDK/ndk-gdb.py --verbose --start

android-debug-attach:
@cd android/demo && \
python2 $$ANDROID_NDK/ndk-gdb.py --verbose
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,26 @@ make ios-framework-universal [RELEASE=1|DEBUG=1]
The universal framework will be available in the configuration build type in `/build/ios-framework-universal/`.

### Android ###
To build for Android you'll need to have installed both the [Android SDK](http://developer.android.com/sdk/installing/index.html?pkg=tools) and the [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html). Please verify that you have version r10e of the NDK installed. Set an `ANDROID_HOME` environment variable with the root directory of your SDK and an `ANDROID_NDK` environment variable with the root directory of your NDK.
To build for Android you'll need to use [Android Studio](https://developer.android.com/studio/index.html) version **2.2** or newer on Mac OS X, Ubuntu, or Windows 10. Using the Android Studio SDK Manager, install or update the 'CMake', 'LLDB', and 'NDK' packages from the 'SDK Tools' tab. Once dependencies are installed, you can execute Android builds from either the command line or the Android Studio interface.

Build an APK of the demo application and optionally specify an architecture (default is armeabi-v7a):
To build the demo application for the ARMv7 architecture (covers most Android devices), run:

```bash
make android [ANDROID_ARCH=[x86|armeabi-v7a|armeabi]]
make android
```

Then install to a connected device or emulator. You can (re)install and run the APK with a small script:
Or open the project in Android Studio and press the 'Run' button (^R). More options are provided through Gradle.

The Gradle project in the `android/` directory contains two modules: a library module called `tangram` containing the Tangram Android SDK and an application module called `demo`, containing a demo application that uses the `tangram` module. The `tangram` module has two `buildTypes`, `debug` and `release`, and two `productFlavors`, `slim` and `full`. The `slim` flavor includes native libraries for just the ARMv7 architecture, the `full` flavor includes all supported architectures (ARMv6, ARMv7, ARM64, and x86).

To build the library or demo application from the `android/` folder using Gradle, use the conventional syntax, e.g.:

```bash
./android/run.sh
./gradlew tangram:assembleFullRelease
```

Android Studio supports debugging both the Java and C++ parts of tangram-es on a connected device or emulator. Choose one of the 'debug' build variants, set your desired breakpoints, and press the 'Debug' button (^D).

### Raspberry Pi ###
To build on Rasberry Pi you will need a C++ toolchain with support for C++14. GCC 4.9 (or higher) is known to work (refer [here](https://community.thinger.io/t/starting-with-the-raspberry-pi/36) for instructions on getting GCC 4.9).

Expand Down
4 changes: 4 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ allprojects {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}

dependencies {
Expand Down
26 changes: 9 additions & 17 deletions android/demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '24.0.2'
compileSdkVersion 25
buildToolsVersion '25.0.0'

defaultConfig {
minSdkVersion 15
targetSdkVersion 24
targetSdkVersion 25
}

sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['../../scenes']
}

aaptOptions.ignoreAssetsPattern "!*.ttf"

buildTypes {
debug {
// applicationIdSuffix ".debug"
debuggable true
jniDebuggable true
}
}

aaptOptions.ignoreAssetsPattern "!*.ttf"
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific issues here with the debug configuration? Based on b859576, it seems it was only temporary.

dependencies {
compile project(":tangram")
debugCompile project(path: ':tangram', configuration: 'slimDebug')
releaseCompile project(path: ':tangram', configuration: 'slimRelease')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should'nt the demo app be marked debuggable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point about the "debuggable" flags, I'm not sure of the impact of these flags on either the library or demo module under the new build system, but I can try both and see.

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:debuggable="true" >
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" >
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2048m
Loading