There are places both here on StackOverflow and on other forums where people say the output directory for the "final.so" file in an NDK build can be specified thusly:
MY_APP_PATH_FOR_OUTPUT := $(call my-dir)
NDK_APP_OUT := $(MY_APP_PATH_FOR_OUTPUT)/../../buildresults/android
But when I do this there is no change in output location of the final product (MyLibrary.so). It does put intermediate files ("local/armeabi/*") in that directory, but I need the final output to go there.
What's the way one is supposed to accomplish this?
Note: What I'm talking about is the very final build step that ndk-build labels "[armeabi] Install". I'm building a .so file and want it to go into the directory I specify during that step.
Thanks.
You can use NDK_APP_LIBS_OUT instead (it's undocumented but it works...). You have to directly pass it to ndk-build though:
ndk-build(.cmd) NDK_APP_LIBS_OUT=src/main/jniLibs
Related
When you use make the idea is you have a Makefile that you start the building off with. With ndk-build it according to the docs just runs $GNUMAKE -f <ndk>/build/core/build-local.mk but like is there a file in my project I need to have or what files is is looking for.
Yes, typically it expects to find your project makefile as jni/Android.mk, but you have lots of freedom if you need.
I was converting android-ndk-command-line applications to Android Studio's applications in this book.enter image description here
But I couldn't find any other code as well as 'LOCAL_C_INCLUDES' parameters in Android.mk file.enter image description here
So, I could not change directory paths. How can I add useful paths in my application?
Android Make Examples:
https://github.com/googlesamples/android-ndk/tree/android-mk
So, I could not change directory paths. How can I add useful paths in my application?
You can set any variables you want in mk file, including a directory path.
MY_DIR_PATH := $(LOCAL_PATH)/..
LOCAL_C_INCLUDES += $(MY_DIR_PATH)/includes
LOCAL_SRC_FILES += \
$(MY_DIR_PATH)/src/sourcefile.cpp \
$(MY_DIR_PATH)/src/core/sourcefile.c \
$(MY_DIR_PATH)/src/fs/sourcefile.cc
IF you are writing from scratch or converting examples from a book, I HIGHLY recommend using CMakeLists instead of Android.mk. Also, don't use file globs, just add every file path by hand into these build scripts.
set ( TRUNK_SOURCE_DIR ../../../../Source)
set ( PLUGIN_SRC_DIR ../../../../Source/plugins)
set ( GAME_SRC_DIR ../../../Source)
I've used Android.mk scripts for years, and the build times are terrible. It would take 4 minutes to rebuild with zero changes to source. With CMake it's a couple seconds.
CMake Examples:
https://github.com/googlesamples/android-ndk
I have a .bbappend file within a custom Yocto Project layer (and separate repo).
I would like to place information about my custom layer (e.g. git stuff for my custom repo/layer) within a file that this .bbappend modifies.
Any commands which are run from this .bbappend are run as if from the .bb file to which it appends (the .bb is in another layer and repo as recommended).
I thought there might be some hope for running VAR := "stuff ${OTHER_VAR} more", which some documentation says is "immediate variable expansion" which is "expanded at time of parsing this line". Unfortunately, it looks like the appending happens before the parsing.
I like the compartmentalized aspect of .bbappend but haven't found a way to refer to the .bbappend itself or if there is some other way to get the git info from the original layer. Any thoughts?
You can demonstrate the immediate expansion with the following demo. Edit
meta-yocto/recipes-core/busybox/busybox_%.bbappend which ships as part of the standard Yocto Project reference setup and add:
SOMEVAR := "${#bb.warn("${FILE}")}"
If you then run "bitbake -p" to reparse the metadata, it will show:
WARNING: /meta-yocto/recipes-core/busybox/busybox_%.bbappend
showing that it was run at the time the file was parsed. This is why you will sometimes see tricks like:
FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:
which is also in that bbappend. This adds a directory in that layer into the search path for files, which can then override the main recipe from the layer.
This is the way I install the config files:
file(GLOB ConfigFiles ${CMAKE_CURRENT_SOURCE_DIR}/configs/*.xml
${CMAKE_CURRENT_SOURCE_DIR}/configs/*.xsd
${CMAKE_CURRENT_SOURCE_DIR}/configs/*.conf)
install(FILES ${ConfigFiles} DESTINATION ${INSTDIR})
But I need to convert one of the xml files before installing it. There is an executable that can do this job for me:
./Convertor a.xml a-converted.xml
How can I automatically convert the xml file before installing it? It should be a custom command or target that installing depends on it, I just don't know how to make the install command depend on it though. Any advice would be appreciated!
Take a look at the SCRIPT version of install:
The SCRIPT and CODE signature:
install([[SCRIPT <file>] [CODE <code>]] [...])
The SCRIPT form will invoke the given CMake script files during
installation. If the script file name is a relative path it will be
interpreted with respect to the current source directory. The CODE
form will invoke the given CMake code during installation. Code is
specified as a single argument inside a double-quoted string.
For example:
install(CODE "execute_process(\"./Convertor a.xml a-converted.xml\")")
install(FILES a-converted.xml DESTINATION ${INSTDIR})
Be sure to checkout the entry for execute_process in the manual. Also be aware that macro expansion inside the CODE parameter can be a bit tricky to get right. Check the generated cmake_install.cmake in your build directory where the generated code will be placed.
I think that your specific case would work better if you were to use a custom command and target like so:
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/a-converted.xml
COMMAND ./Convertor a.xml a-converted.xml
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Convertor
)
add_custom_target(run ALL
DEPENDS ${CMAKE_BINARY_DIR}/a-converted.xml
COMMENT "Generating a-converted.xml" VERBATIM
)
install(
FILES ${CMAKE_BINARY_DIR}/a-converted.xml
DESTINATION ${INSTDIR}
)
Note: I don't have all the details, so the directories are probably
not exactly what you'd want in your environment, although it's
a good idea to generate files in the ${CMAKE_BINARY_DIR} area.
That way you can be sure that the file a-converted.xml is built at the time you want to install it. Especially, these two rules make sure that if you make changes to the file, it gets recompiled.
I can't seem to find much about this, so maybe it isn't possible... or I am searching with the wrong keywords.
Anyway, I have a directory of source. Let's say that there is a folder within Source called Tests and another called Products. I have the usual hierarchy of CMakeLists.txt files so that I can build all the source in each directory and subdirectory, etc... What I want to know is if it is possible to pass a command line argument with cmake so that it will only build the tests folder or the source folder.
e.g. something like cmake TEST ..
Thanks
Of course you can use flags.
if(TEST)
include needed folders
else()
do something else
endif()
And call cmake like this:
cmake -DTEST=1 ..
You can create them as different targets. CMake will configure all of them, but then you can run make test or make product. An example would be:
project(myProject)
add_subdirectory(tests)
add_subdirectory(products)
add_executable(test EXCLUDE_FROM_ALL ${TEST_SRC_FILES})
add_executable(product EXCLUDE_FROM_ALL ${PRODUCT_SRC_FILES})
In each subdirectory you would have a CMakeLists.txt that builds the source file variables. The EXCLUDE_FROM_ALL means that just typing make won't build either tests or products, but you can decide if you want that to happen or not.
To build, you can do make test or make product and it will build only that target (and any dependencies).