1

I am trying to compile Crypto++ library on Android using JNI. I have cloned the project of https://github.com/morgwai/ndktutorial. I imported the project into android studio, I am able to call the JNI class and read the Crypto++, but when the library gets called I get an inside error which says "memory" no such file or directory pointing to #include <memory>.

Here is my 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'
}

Also here is the error I get when I compile:

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

Thank you in advance.

jww
  • 83,594
  • 69
  • 338
  • 732
  • Android Studio and Gradle are not officially supported build systems. We have not investigated them because Android Studio support for JNI was so bad in the past. Basically, we threw our hands in the air out of frustration. You also have to be careful of other people's warez because they seem to pick random flags and options at times. We recently caught [CVE-2016-7420](http://www.openwall.com/lists/oss-security/2016/09/15/11) because of random Eclipse and CMake options. Its why we had to relase Crypto++ 5.6.5 so soon after Crypto++ 5.6.4. – jww Oct 14 '16 at 21:32
  • Also be careful of random GitHub's. Wei Dai's GitHub is at [http://github.com/weidai11/cryptopp](http://github.com/weidai11/cryptopp), and that's where you should clone the library from. We support Android and JNI, but you have to build it from the command line. Its going to be tough on Windows because there are no scripts available. Also see [Android (Command Line)](https://www.cryptopp.com/wiki/Android_(Command_Line)) on the Crypto++ wiki. – jww Oct 14 '16 at 21:39
  • Regarding the error ***"Error:(10, 18) memory: No such file or directory"***, it sounds like either (1) your SYSROOT is not set; or (2) your have not selected a C++ runtime library. Crypto++'s `setenv-android.sh` sets up both for you. I'm guessing it is more fallout from the lack of Android Studio support for JNI. The [Android wiki page](https://www.cryptopp.com/wiki/Android_(Command_Line)) has a few suggestions, but they are band-aides until Android Studio provides first class support. – jww Oct 14 '16 at 21:42
  • Finally, we need to see a compile command, and not just the error. Please provide what your compile command looks like on one CPP file. For example, here's what it looks like when compiling `cryptlib.cpp` on the command line for `armeabi`: `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`. – jww Oct 14 '16 at 21:58
  • Here's another question that might be helpful: [Android studio SDK location error](http://stackoverflow.com/q/27594858). According to the NDK folks, `ANDROID_NDK_ROOT` and `ANDROID_SDK_ROOT` are supposed to be set. Our scripts follow the NDK teams recommendations. In the past, it appeared Android Studio and Gradle ignored them. If you find you are setting them but the tools are ignoring them, then you should file a bug report against Android Studio and Gradle. Nothing gets fixed unless you file the bug reports. – jww Oct 15 '16 at 12:46
  • Here's another question that might help: [JNI and Gradle in Android Studio](http://stackoverflow.com/q/21096819). As you can see, its an absolute mess. Its probably best to use `ndk-build` from the command line until Android Studio sorts out the mess. – jww Oct 15 '16 at 12:52
  • Got it, will do try with ndk-build one more time. If it does not work, I will switch to eclipse or some other way far from JNI, thank you so much for your help! I appreciate it. – Mohammed Elbadry Oct 17 '16 at 03:24

1 Answers1

0

Add

APP_STL = c++_shared

to your Application.mk

unDEFER
  • 91
  • 4