1

I want to use c++ STL in android, but when I include STL (ex: hash_map), then run that occur error.

I use android studio 1.0.2 and android ndk r10d

This is my build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.ndktest"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

        ndk {
            moduleName 'JNI'
            stl 'stlport_shared'
        }

    }
    productFlavors {
        arm {
            ndk {
                abiFilters "armeabi", "armeabi-v7a"
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

Error Message:

WARNING [Project: :app] Current NDK support is deprecated. Alternative will be provided in the future. WARNING [Project: :app] Current NDK support is deprecated. Alternative will be provided in the future. :app:preBuild :app:compileArmDebugNdk In file included from C:/Users/Sheng/Developer/android/SDK_Libs/android-ndk/sources/cxx-stl/stlport/stlport/stl/_algobase.h:46:0, from C:/Users/Sheng/Developer/android/SDK_Libs/android-ndk/sources/cxx-stl/stlport/stlport/stl/_vector.h:34, from C:/Users/Sheng/Developer/android/SDK_Libs/android-ndk/sources/cxx-stl/stlport/stlport/stl/_hashtable.h:34, from C:/Users/Sheng/Developer/android/SDK_Libs/android-ndk/sources/cxx-stl/stlport/stlport/stl/_hash_map.h:34, from C:/Users/Sheng/Developer/android/SDK_Libs/android-ndk/sources/cxx-stl/stlport/stlport/hash_map:38, from C:\Users\Sheng\tmp\NDKTEST\app\src\main\jni\maps.h:5, from C:\Users\Sheng\tmp\NDKTEST\app\src\main\jni\maps.cpp:1: C:/Users/Sheng/Developer/android/SDK_Libs/android-ndk/sources/cxx-stl/stlport/stlport/stl/_cstdlib.h: In function 'long int abs(long int)': C:/Users/Sheng/Developer/android/SDK_Libs/android-ndk/sources/cxx-stl/stlport/stlport/stl/_cstdlib.h:131:25: error: declaration of C function 'long int abs(long int)' conflicts with inline long abs(long __x) { return _STLP_VENDOR_CSTD::labs(__x); } ^ more...

How can I solve? Thanks.

Elirex
  • 63
  • 1
  • 9
  • http://stackoverflow.com/questions/13675523/android-ndk-including-stl for background on headers and on android.mk , application.mk then http://ph0b.com/android-studio-gradle-and-ndk-integration/ on how to config build-ndk with android studio IMO - dont use default gradle calls to "defaultConfig.ndk" – Robert Rowntree Jan 21 '15 at 16:31
  • Did you trying adding "gnustl_shared" instead of stlport_shared, I encountered the same error using "stlport_shared" in my Applicataion.mk , then i change it to gnustl_shared and it worked out perfectly for me. – Aagman Sep 28 '17 at 05:58

0 Answers0