I was using Eclipse successfully to build Botan using the directions linked to from this question, however, Android Studio is supposed to replace Eclipse for Android development, so I'm trying to get it to build in Android Studio now, but it fails with a missing header file <iosfwd>. I'm getting the following error:
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/User1/Development/android-ndk-r10d/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/User1/application1/android/workspace/app/build/intermediates/ndk/debug/Android.mk APP_PLATFORM=android-19 NDK_OUT=/Users/User1/application1/android/workspace/app/build/intermediates/ndk/debug/obj NDK_LIBS_OUT=/Users/User1/application1/android/workspace/app/build/intermediates/ndk/debug/lib APP_ABI=all
Error Code:
2
Output:
In file included from /Users/User1/application1/android/workspace/app/src/main/jni/botan/botan_all.cpp:8:0:
/Users/User1/application1/android/workspace/app/src/main/jni/botan/botan_all.h:11:18: fatal error: iosfwd: No such file or directory
#include <iosfwd>
^
compilation terminated.
make: *** [/Users/User1/application1/android/workspace/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/app//Users/User1/application1/android/workspace/app/src/main/jni/botan/botan_all.o] Error 1
Where should I be getting the header file <iosfwd> from and how do I instruct Android Studio to locate it?
Update
I found the following makefile: .../workspace/app/src/main/jni/botan/Android.mk
# jni/botan/Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := botan
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := botan_all.cpp
LOCAL_CPPFLAGS := -DBOTAN_USE_GCC_INLINE_ASM=0
include $(BUILD_SHARED_LIBRARY)
I tried adding the line after LOCAL_CPPFLAGS:
LOCAL_C_INCLUDES := $(ANDROID_STL_INC)
But the build seems unaffected, I get the same error, so I then tried to edit LOCAL_CPPFLAGS to be:
LOCAL_CPPFLAGS := SEE_IF_THIS_BREAKS_THE_BUILD
To see if my edits are being seen, but again, the exact same original failure on header iosfwd. So it appears my edits are not part of the build.
How can I get Android Studio to give more information so I can figure out how it gets to the build step that fails. Presently, when I build, it pauses, then gives window with the error message, but without showing all the intermediate steps to get it there, which might show which makefiles got it to that point.
The C++ runtime is not included with
--sysrootbecause it depends on the C++ runtime you want to use.I use STLport because GNU has toxic licensing terms. So here's how STLport looks from the command line and in Eclipse (I know your question is about Android Studio, but this shows how you have to handle the C++ runtime).
So my build script for libraries like Botan (I've actually built and tested it on Android) and Crypto++ have the following:
Later, the
Makefileuses the environmental variables set in the script:And here's how it looks under Eclipse: Compile native C++ shared object with Android NDK. The answer shows the important parts (including
Application.mkandAndroid.mk) of a sample project that provides my C++ shared object, depends on the Crypto++ shared object, and useslibstlport_shared.so.I don't really have an answer for this because I don't use Android Studio. But it might be helpful to add the following to your build file. It seems to be the standard way of specifying a C++ runtime under Android Studio:
Also see the following:
One important note (from my experience with cross-compiling for Android). Be sure
-mfloat-abi=softfpis a compiler option for ARMv7a targets; and-msoft-floatis a compiler option for ARMv7 targets. That's important for ABI compatibility.If
-mfloat-abi=softfpis omitted, then floats will be passed incorrectly and the float value that Botan (or other libraries) receive will be0.0f. OpenSSL suffers this defect - all entropy estimates from Java callers are0.0f.