无法在Android NDK中包含iostream [英] Can not include iostream in Android NDK

查看:501
本文介绍了无法在Android NDK中包含iostream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Android项目中使用cpp文件.我可以使用c函数而不会出现错误.我在jni文件夹中添加Core.cppCore.h.在我仅添加#include <iostream>之后,android studio给出了iostream: No such file or directory错误.我在这行APP_STL:=stlport_stati c中有Application.mk.如何在Android Studio中使用cpp文件?

I try to use cpp file with android project. I can use c functions without error. I add Core.cpp and Core.h in jni folder. After I only add #include <iostream> and android studio gives iostream: No such file or directory error. I have Application.mk with this line APP_STL:=stlport_static . How can I use cpp files in Android Studio ?

我在Xubuntu 14.04上使用Android Studio 1.5.1

我没有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'
}

推荐答案

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

You need to modify your build.gradle to specify what C++ library to link to.

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

使用实验性NDK支持查看build.gradle文件的一些示例此处(您好,第三方)此处(无尽隧道).

See some examples of build.gradle files using the experimental NDK support here (hello-thirdparty) and here (endless-tunnel).

这篇关于无法在Android NDK中包含iostream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆