无法在Android NDK中包含iostream

时间:2016-03-29 12:14:03

标签: android android-ndk

我尝试将cpp文件与android项目一起使用。我可以毫无错误地使用c函数。我在jni文件夹中添加了Core.cppCore.h。在我只添加#include <iostream>和android studio给出iostream: No such file or directory错误之后。我有Application.mk这一行APP_STL:=stlport_stati c。如何在Android Studio中使用cpp文件?

我在Android Studio 1.5.1

上使用Xubuntu 14.04

我没有Android.mk和我的build.gradle文件:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = '23.0.0'
        compileOptions.encoding = 'windows-1251' // write your encoding here

        defaultConfig.with {
            applicationId = "com.example.example"
            minSdkVersion.apiLevel = 19
            targetSdkVersion.apiLevel = 21
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file('proguard-android.txt'))
        }
    }

    android.ndk {
        moduleName = "hello-jni"
    }

    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
        create("arm7") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("arm8") {
            ndk.abiFilters.add("arm64-v8a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
        create("x86-64") {
            ndk.abiFilters.add("x86_64")
        }
        create("mips") {
            ndk.abiFilters.add("mips")
        }
        create("mips-64") {
            ndk.abiFilters.add("mips64")
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.madgag.spongycastle:core:1.51.0.0'
}

1 个答案:

答案 0 :(得分:1)

您需要修改build.gradle以指定要链接到的C ++库。

android.ndk {
    moduleName = "hello-jni"
    stl        = "stlport_static"
}

使用实验性NDK支持here (hello-thirdparty)here (endless-tunnel)查看build.gradle文件的一些示例。