3

According to OVERVIEW.html in the NDK docs, you set the environment variable "NDK_LIBS_OUT" to make the libraries go somewhere other than $PROJECT/libs.

In my case, Gradle seems to want the shared libraries to go to $PROJECT/src/main/jniLibs, so I set NDK_LIBS_OUT to be that directory. This works.

Now how would I go about setting this up in Android.mk or Application.mk? I don't want to have to set this environment variable every time, especially if I hand off the build scripts to someone else.

sciencectn
  • 1,405
  • 1
  • 16
  • 25
  • I don't believe you can do that. Environments are only inherited from parent to children, not from children to parent. So to do it from that file and have it take effect elsewhere, you'd probably have to add something else which scanned the file to extract this and set it in the parent. – Chris Stratton Apr 13 '14 at 23:58

2 Answers2

3

as Chris said, you can't manipulate this variable from *.mk files.

What you can do is reproducing this behavior from the Android.mk, by moving or copying the libs once they're built:

all: jniLibs/$(TARGET_ARCH_ABI) jniLibs/$(TARGET_ARCH_ABI): libs/$(TARGET_ARCH_ABI) $(call host-mkdir,$@) $(call host-cp,$<,$@)

Otherwise, if modifying gradle build scripts is an option, you can set this inside build.gradle so gradle will look for libs that are inside libs folder instead of jniLibs:

android { sourceSets.main { jniLibs.srcDir 'src/main/libs' } }

ph0b
  • 14,353
  • 4
  • 43
  • 41
  • The first one seemed good...the problem is Android.mk doesn't seem to specify each library output as a Makefile target. There's some really weird syntax involved. So when it gets to the dependencies `libs/$(TARGET_ARCH_ABI)` it gets confused, because there apparently wasn't a defined rule for how to make each dependency. Maybe `include $(CLEAR_VARS)` wipes them? – sciencectn Apr 18 '14 at 19:22
1

If you want to automate your make file, the best option is to use CMake. Using CMake to organize the source code is pretty cool, because you can quickly generate from it Visual Studio solution files on Windows and make files on Linux, and therefore build and test the code on different platforms without maintaining two separate build scripts.

Your cosscompile file will look like:

include(CMakeForceCompiler)
set(toolchain_path /opt/ndk/toolchains)
# Target system
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_VERSION 1)

# Compiler to build for the target
set(CMAKE_C_COMPILER /opt/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc)
set(CMAKE_FIND_ROOT_PATH /opt/ndk/toolchains)

so, you only have to make the setups and you are good to go.

Community
  • 1
  • 1
Sophia Taylor
  • 248
  • 2
  • 8