No such <iosfwd> file when building Botan under Android Studio?
I have successfully used Eclipse to build Botan using the directions linked to this question , however Android Studio is supposed to replace Eclipse for Android Development, m trying to get it to build in Android Studio now, but the header file is missing with an error <iosfwd>
. I am 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 can I get the header file <iosfwd>
and how can I instruct Android Studio about its location?
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 a line after LOCAL_CPPFLAGS
:
LOCAL_C_INCLUDES := $(ANDROID_STL_INC)
But the assembly seems to be unaffected, I get the same error, so I tried to edit LOCAL_CPPFLAGS
like:
LOCAL_CPPFLAGS := SEE_IF_THIS_BREAKS_THE_BUILD
To see if my changes see, but again, the same original glitch in the header iosfwd
. So my edits are not part of the build.
How can I get Android Studio to provide more information so that I can understand how this turns out in the build step that is failing. Currently when I build it pauses, then gives an error message box but doesn't show all the intermediate steps to get it there, which might show which makefiles got it up to that point.
source to share
Where should I get the header file and how can I instruct Android Studio about its location?
The C ++ runtime is not included in --sysroot
as it depends on the C ++ runtime you want to use.
$ cd /opt/android-ndk-r10
$ find . -name iosfwd
./sources/cxx-stl/gnu-libstdc++/4.6/include/iosfwd
./sources/cxx-stl/gnu-libstdc++/4.8/include/iosfwd
./sources/cxx-stl/llvm-libc++/libcxx/include/iosfwd
./sources/cxx-stl/stlport/stlport/iosfwd
./sources/cxx-stl/stlport/stlport/using/iosfwd
I use STLport because GNU has toxic licensing terms. So this is what STLport looks like from the command line and in Eclipse (I know your question is about Android Studio, but this shows how you should handle C ++ runtime).
So my build script is for libraries like Botan (I actually built and tested it on Android) and Crypto ++ has this:
# If more than one library is using STLport, then all libraries in the
# APK ***must*** use the shared version.
# STLPORT_LIB=libstlport_static.a
STLPORT_LIB=libstlport_shared.so
if [ "$_ANDROID_ARCH" == "arch-arm" ]; then
if [ "$_ANDROID_ARMV7A" -ne 0 ]; then
STLPORT_ABI=armeabi-v7a
else
STLPORT_ABI=armeabi
fi
elif [ "$_ANDROID_ARCH" == "arch-x86" ]; then
STLPORT_ABI=x86
elif [ "$_ANDROID_ARCH" == "arch-mips" ]; then
STLPORT_ABI=mips
fi
export ANDROID_STL_INC="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/stlport/"
export ANDROID_STL_LIB="$ANDROID_NDK_ROOT/sources/cxx-stl/stlport/libs/$STLPORT_ABI/$STLPORT_LIB"
Later Makefile
uses the environment variables set in the script:
# Android cross-compile configuration. Works in conjunction with IS_CROSS_COMPILE.
# See http://www.cryptopp.com/wiki/Android_(Command_Line).
ifeq ($(IS_ANDROID),1)
# CPP, CXX, AR, RANLIB, LD, etc are set in 'setenv-android.sh'
CXXFLAGS = -DNDEBUG -g2 -Os -pipe -fPIC
CXXFLAGS += -DCRYPTOPP_DISABLE_ASM $(ANDROID_FLAGS)
CXXFLAGS += --sysroot=$(ANDROID_SYSROOT) -I$(ANDROID_STL_INC)
LDLIBS += $(ANDROID_STL_LIB)
endif
And this is how it looks under Eclipse: Compile native C ++ shared object with Android NDK . The answer shows the important parts (including Application.mk
and Android.mk
) an exemplary project that provides a common object of my C ++, based on the total object Crypto ++ and uses libstlport_shared.so
.
... how can I train Android Studio to find it ...
I don't actually have an answer because I am not using Android Studio. But it would be helpful to add the following file to the assembly file. This seems to be the standard way of specifying the C ++ runtime in Android Studio:
ndk {
moduleName "MyNativeModule"
stl "stlport_shared"
ldLibs "log", "z", "m"
cFlags "-I/some/include/path"
}
Also see the following:
One important note (from my Android cross-compilation experience). Make sure -mfloat-abi=softfp
is is a compiler option for ARMv7a targets; and -msoft-float
is a compiler for ARMv7 targets. This is important for ABI compatibility.
If -mfloat-abi=softfp
omitted, floats will be passed incorrectly, and the float value that Botan (or other libraries) will receive will be 0.0f
. OpenSSL suffers from this defect - all entropy estimates from Java subscribers 0.0f
.
source to share