As a proof of concept, I’m trying to compile and utilize the power of this library for an android app. I'm using the android studio. What I've done so far was:
Linked my build.gradle to the Android.MK file that was present in the sources
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
Set ProductFlavors in order to avoid trying to make a build for architectures that are not supported by the library (i might be wrong here already)
productFlavors {
dev { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
develx86 { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
production { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
productionx86 { ndk.abiFilters 'x86', 'armeabi', 'armeabi-v7a' }
}
At this point, I've noticed that some files like cpu-miner.c are missing some includes highlighting them as missing, specifically
#include <curl/curl.h>
#include <openssl/sha.h>`
So I went to the official websites of these two libraries and downloaded the sources, created two corresponding folders and places all the files there. In OpenSSL
there was an h.in file - a config as I understand. I was able to get a configured one from here (might also be a place where I made a mistake)
APP_ABI:= armeabi armeabi-v7a x86
to exclude some of the architectures I don't support.At this point, I have some problems - one of them is that I can't actually build my JNI stuff with NDK-build - sched.h
doesn't get resolved (even if I increase API version to 20). This results in errors like:
JNI/cpu-miner.c:473:2: error: use of undeclared identifier 'cpu_set_t'
cpu_set_t set;
jni/cpu-miner.c:474:12: error: use of undeclared identifier 'set'
CPU_ZERO(&set);
So the questions are:
sched.h
? As soon as I fix the library build will it be enough to just generate java interface to my c files and start using them or there are additional steps to consider?
Please feel free to ask for any additional details if you require any, thank you in advance.
Disclaimer: I'm the a.NET dev so please be more specific about android/C things where applicable.
Disclaimer 2: This program is being made for educational purposes as a proof of concept.
Android is based on Linux Kernel so it's definitely possible to compile & run C/C++ programs on Android. C is quite cross-platform , so a C Program written in Windows can Run on Linux ( and android ) and vice versa. Special Note : You might be wondering why i included C++ where we should be only focusing on C.
libc++ LLVM's libc++ is the C++ standard library that has been used by the Android OS since Lollipop, and as of NDK r18 is the only STL available in the NDK. Note: For full details of the expected level of C++ library support for any given version, see the C++14 Status, C++17 Status, and C++20 Status pages.
C++ can be used for Android App Development using the Android Native Development Kit(NDK). However, an app cannot be created totally using C++ and the NDK is used to implement parts of the app in C++ native code. This helps in using C++ code libraries for the app as required.
It looks like cpu_set_t
didn't make it into the NDK headers until android-21.
NDK r14 (unreleased, but should be out next week) has completely redone the headers so that you'll have access to the struct definitions and constants (whether or not the APIs you'll need will be available before android-21 is a different question). To use them, grab the r14 beta and follow the instructions for unified headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With