【问题标题】:Can not include iostream in Android NDK不能在 Android NDK 中包含 iostream
【发布时间】:2016-03-29 12:14:02
【问题描述】:

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

我在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 和 Android.mk(如果您使用它)。
  • 我更新了我的问题

标签: android android-ndk


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-05
    • 2013-06-16
    • 1970-01-01
    • 2018-05-11
    • 2012-04-20
    • 2010-12-23
    • 2013-10-11
    • 1970-01-01
    相关资源
    最近更新 更多