[cmake-developers] cmake's built-in support for android using nvidia nsight tegra

Peter List pem.list at gmail.com
Sun Aug 23 16:44:59 EDT 2015


TLDR: How do I tell cmake to include "Ant Build" in my vcxproj, so that it
will package my project into an APK?  I can generate vcxproj that builds a
Tegra-Android *.so file, but it does not build me an APK, and my vcxproj is
missing the "Ant Build" property section.  As a reference, if I use Visual
Studio 2010 to create a new project > Nsight Tegra > Android Native
Application, then it has an "Ant Build" property section, and it does build
me an APK, and I can run this on my Android device from Visual Studio using
ctrl+F5. thank you for any leads
---
Long Version

CMake recently added built-in support for cross-compiling Windows to
Android:

http://www.cmake.org/cmake/help/v3.1/manual/cmake-toolchains.7.html#cross-compiling-using-nvidia-nsight-tegra

I am attempting to use the built-in CMake Android support.  I actually
don't care if it's Nsight Tegra or what, but since it's officially built-in
to CMake then I feel like maybe that's simpler and more standard (less
hacky) than alternatives like ( https://github.com/taka-no-me/android-cmake ).
I don't mind that it's for Windows Visual Studio 2010 only.

So I installed AndroidWorks and now I have two copies of the Android SDK &
JDK such as (C:\Programs\NVPACK\android-ndk-r10e\) and
(C:\Programs\Android\android-ndk-r10e).  But that's not my question.

I also noticed that I can only generate CMake Android with Visual Studio
2010, even though the release notes say "2010 or newer".  But that's not my
question.

I'm able to use Visual Studio 2010 to create a new project > Nsight Tegra >
Android Native Application.  I can build the project and run it on my
Android device (actually it's a Kindle Fire HD 6) from inside Visual Studio
2010 using Ctrl+F5.

I'm able to use CMake to generate a similar project "pemDemos".  Here are
some relevant parts of my CMakeLists.txt.  I got the android.bat idea from
here ( http://bit.ly/1hTZuRB ).

[BEGIN CMakeLists.txt]
project(pemDemos)
cmake_minimum_required(VERSION 2.8.6)
aux_source_directory(. SRC_LIST)
add_definitions("-std=c++11")
set(dirSDLmain ${CMAKE_CURRENT_SOURCE_DIR}/../../SDL2-2.0.3/libs/armeabi)
set(dirSDL ${CMAKE_CURRENT_SOURCE_DIR}/../../SDL2-2.0.3/libs/armeabi)
set(ANDROID_SDK "C:/Programs/NVPACK/android-sdk-windows")
set(ANDROID_NDK "C:/Programs/NVPACK/android-ndk-r10e")

# this is how we get our NDK *.so binaries into an APK
execute_process(COMMAND ${ANDROID_SDK}/tools/android.bat create project
--path ${CMAKE_CURRENT_BINARY_DIR}/android
--target android-19 --name PemApp
--package com.pem.PemApp --activity PemActivity)

include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
set(SRC_LIST "${SRC_LIST}"
"${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
set(SRC_LIST "${SRC_LIST}"
"${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.h")
set(SRC_LIST "${SRC_LIST}"
"${CMAKE_CURRENT_BINARY_DIR}/android/AndroidManifest.xml")
LINK_LIBRARIES(android)

# ???
https://stackoverflow.com/questions/19207721/build-android-ndk-project-with-cmake
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -ffor-scope -fno-rtti
-fno-exceptions -pipe -ffunction-sections -fdata-sections -ffast-math
-Wnon-virtual-dtor -Wreorder -Wsign-promo -fvisibility=hidden
-fvisibility-inlines-hidden -Wstrict-null-sentinel -Os -funroll-all-loops
-fpeel-loops -ftree-vectorize")
set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--as-needed -Wl,--gc-sections
-Wl,--no-undefined -Wl,--strip-all
-Wl,-rpath-link=${ANDROID_NDK_SYSROOT}/usr/lib/
-L${ANDROID_NDK_SYSROOT}/usr/lib/")

LINK_DIRECTORIES(${dirSDLmain})
LINK_DIRECTORIES(${dirSDL})
LINK_LIBRARIES(SDL2)
add_library(${PROJECT_NAME} SHARED ${SRC_LIST})
[END CMakeLists.txt]

My cmake command is:

cd build-android
cmake -G"Visual Studio 10 2010" -DCMAKE_SYSTEM_NAME="Android" ..\pemDemos

This generates a visual studio solution that is similar to the "Android
Native Application".  I am able to build for target (Debug, Tegra-Android)
in Visual Studio, and it builds two .so files (libpemDemos.so,
stripped_libpemDemos.so) (aside I'm not sure what the stripped_* file is
for).

However, when I attempt to run it from Visual Studio with Ctrl+F5, it gives
the error - Cannot find the package to deploy.  Make sure it has been
built.  [path]\build-Android\Debug\pemDemos.apk.

Upon closer inspection, I notice that my working Android Native Application
vcxproj > properties has a section for Ant Build.  But my pemDemos.vcxproj
does not.  So how do I tell cmake to include this "Ant Build" portion in my
vcxproj?

At this point I could probably go off and try to figure out how to package
this .so in my APK such that it will call my main(), SDL_main(), or
android_main().  I made some progress in packaging an APK with these
commands:

cd [path]\build-android\android\
mkdir libs\armeabi-v7a
cp ..\Debug\*.so libs\armeabi-v7a
cp ..\..\..\SDL2-2.0.3\libs\armeabi\*.so libs\armeabi-v7a
ant debug
cd [path]\build-android\android\bin
adb devices
adb start-server
adb -s [device ID] install PemApp-debug.apk
adb -s [device ID] install -r PemApp-debug.apk
# aapt dump badging PemApp-debug.apk | grep package
# aapt dump badging PemApp-debug.apk | grep launchable-activity
# can also find -n from CMakeLists.txt: --package foo --activity bar =>
foo/foo.bar
adb -s [device ID] shell am start -n
com.pem.PemApp/com.pem.PemApp.PemActivity

I haven't got this working yet.  However, I'm hoping I can just tell cmake
to do it for me by making it part of the Visual Studio 2010 vcxproj?
That's how it worked when I did new project > "Android Native Application".

thank you for any help on this
---
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20150823/f2e393b1/attachment.html>


More information about the cmake-developers mailing list