【问题标题】:Error: <memory> no such file or directory on Android with JNI错误:<memory> 在带有 JNI 的 Android 上没有这样的文件或目录
【发布时间】:2016-10-14 15:44:50
【问题描述】:

我正在尝试使用 JNI 在 Android 上编译 Crypto++ 库。我已经克隆了https://github.com/morgwai/ndktutorial 的项目。我将项目导入 android studio,我可以调用 JNI 类并读取 Crypto++,但是当调用该库时,我得到一个内部错误,上面写着“内存”没有指向 #include &lt;memory&gt; 的此类文件或目录。

这是我的 build.gradle:

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.3"

        defaultConfig {
            applicationId "com.moham.myapplication"
            minSdkVersion.apiLevel 22
            targetSdkVersion.apiLevel 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles.add(file('proguard-android.txt'))
            }

        }
        ndk {
            moduleName "crypt_user.cpp"
        }
    }
}

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

这也是我编译时遇到的错误:

MYPATH\Android\sdk\ndk-bundle\platforms\android-23\arch-arm64\usr\include\stdcpp.h
Error:(10, 18) memory: No such file or directory
compilation terminated.
Error:Execution failed for task ':app:compileCrypt_userArm64-v8aDebugSharedLibra
ryCrypt_userMainCpp'.
> A build operation failed.
      C++ compiler failed while compiling crypt_user.cpp.
  See the complete log at: file:///D:/MyApplication/app/build/tmp/compileCrypt_u
serArm64-v8aDebugSharedLibraryCrypt_userMainCpp/output.txt

提前谢谢你。

【问题讨论】:

  • Android Studio 和 Gradle 不是官方支持的构建系统。我们没有对它们进行调查,因为过去 Android Studio 对 JNI 的支持非常糟糕。基本上,我们出于沮丧将双手举在空中。您还必须小心其他人的warez,因为他们似乎有时会选择随机标志和选项。由于随机的 Eclipse 和 CMake 选项,我们最近发现了 CVE-2016-7420。这就是为什么我们必须在 Crypto++ 5.6.4 之后这么快就发布 Crypto++ 5.6.5。
  • 还要小心随机的 GitHub。 Wei Dai 的 GitHub 位于 http://github.com/weidai11/cryptopp,您应该从那里克隆该库。我们支持 Android 和 JNI,但您必须从命令行构建它。它在 Windows 上会很困难,因为没有可用的脚本。另请参阅 Crypto++ wiki 上的 Android (Command Line)
  • 关于错误 "Error:(10, 18) memory: No such file or directory",听起来像 (1) 你的未设置 SYSROOT;或 (2) 您尚未选择 C++ 运行时库。 Crypto++ 的setenv-android.sh 为您设置了两者。我猜这更多是由于缺乏对 JNI 的 Android Studio 支持。 Android wiki page 有一些建议,但在 Android Studio 提供一流的支持之前,它们只是临时帮助。
  • 最后,我们需要看到一个编译命令,而不仅仅是错误。请提供您的编译命令在一个 CPP 文件上的样子。例如,下面是在命令行上为armeabi 编译cryptlib.cpp 时的样子:arm-linux-androideabi-g++ -DNDEBUG -g2 -Os -fPIC -pipe -march=armv5te -mtune=xscale -msoft-float -funwind-tables -fexceptions -frtti --sysroot=/opt/android-ndk-r10e/platforms/android-21/arch-ar‌​m -I/opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/ -c cryptlib.cpp
  • 这是另一个可能有帮助的问题:Android studio SDK location error。根据 NDK 人员的说法,应该设置 ANDROID_NDK_ROOTANDROID_SDK_ROOT。我们的脚本遵循 NDK 团队的建议。过去,Android Studio 和 Gradle 似乎忽略了它们。如果您发现您正在设置它们但工具忽略了它们,那么您应该针对 Android Studio 和 Gradle 提交错误报告。除非您提交错误报告,否则什么都不会得到修复。

标签: android android-studio gradle java-native-interface crypto++


【解决方案1】:

添加

APP_STL = c++_shared

到您的 Application.mk

【讨论】:

    猜你喜欢
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    相关资源
    最近更新 更多