Build command failed:fatal error: 'string' file not found

I am trying to build and run the existing Android NDK project with latest Gradle. But I am getting below error while running the application.

Build command failed.
Error while executing process D:\rapiscan\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\rapiscan\codebase\NGC\NextGenConsole\app\.externalNativeBuild\cmake\debug\x86 --target UiDataProvider}
[1/4] Building CXX object UiDataProvider/CMakeFiles/UiDataProvider.dir/UiCmdHandler.cpp.o
[2/4] Building CXX object UiDataProvider/CMakeFiles/UiDataProvider.dir/UiDataProvider.cpp.o
[3/4] Building CXX object UiDataProvider/CMakeFiles/UiDataProvider.dir/UiMessageGenerator.cpp.o
FAILED: D:\rapiscan\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=i686-none-linux-android23 --gcc-toolchain=D:/rapiscan/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64  -DUiDataProvider_EXPORTS -IUiDataProvider -ID:/rapiscan/codebase/NGC/NextGenConsole/malibu/UiDataProvider -ID:/rapiscan/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/arm-linux-androideabi -ID:/rapiscan/codebase/NGC/NextGenConsole/malibu/Common -pthread -O0 -fno-limit-debug-info  -fPIC   -std=gnu++14 -MD -MT UiDataProvider/CMakeFiles/UiDataProvider.dir/UiDataProvider.cpp.o -MF UiDataProvider\CMakeFiles\UiDataProvider.dir\UiDataProvider.cpp.o.d -o UiDataProvider/CMakeFiles/UiDataProvider.dir/UiDataProvider.cpp.o -c D:\rapiscan\codebase\NGC\NextGenConsole\malibu\UiDataProvider\UiDataProvider.cpp
In file included from D:\rapiscan\codebase\NGC\NextGenConsole\malibu\UiDataProvider\UiDataProvider.cpp:1:

D:/rapiscan/codebase/NGC/NextGenConsole/malibu/UiDataProvider/UiDataProvider.h:5:10: fatal error: 'string' file not found

`#include <string>`


1 error generated.

Below is the ndk configuration specified in app build.gradle

ndk {

            ndk {  
                abiFilters 'armeabi-v7a', 'arm64-v8a','x86'
            }
           externalNativeBuild {
                cmake {
                    arguments  '-DCMAKE_BUILD_TYPE=Debug',"-DPROJECT_DIR:STRING=${mb_sdk_path}",'-DANDROID_PLATFORM=android-23',  '-DANDROID_TOOLCHAIN=clang', '-DANDROID_ARM_NEON=TRUE', "-DPATH_TO_MALIBU:STRING=${mb_sdk_path}" ,"-DANDROID_STL=c++_static",
                    "-DTARGET_PLATFORM=Windows","-DUNIX=FALSE"
                    cppFlags "-std=c++14 -stdlib=libc++ -frtti -fexceptions"
                }
            }
        }

and below is the build.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.novoda:bintray-release:0.9'
    }
}

Upvotes: 2

Views: 11330

Answers (2)

Hpsaturn
Hpsaturn

Reputation: 2742

I had the same problem with last version of gradle and cmake in my project, but I detected that only occurs when the Build Variants is wrong, for example the target is debug-armeabi-v7a but you are in a release compiling, please review the right variant target.

My settings:
NDK 19.1.5304403
CMake 3.10.2

build.gradle:

defaultConfig {
    ...
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    ...
    externalNativeBuild {
        cmake {
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    ...

NOTE: sometimes too you should remove the hidden directory rm -rf app/.externalNativeBuild for it works

Upvotes: 2

Dan Albert
Dan Albert

Reputation: 10519

Using -stdlib=libc++ with CMake is either redundant or broken on every NDK version. What you want is -DANDROID_STL=c++_shared (or -DANDROID_STL=c++_static for the static library, or nothing at all for the static library on NDK r18+ since that's the default).

Passing -stdlib=libc++ may cause the compiler to look in the wrong location on older NDK releases, and is the default on r19+.

Upvotes: 0

Related Questions