Create Android application which uses "guardianproject/openssl-android" libraries(.so) - android

I have built the libcrypto.so and libssl.so from this (https://github.com/guardianproject/openssl-android) project. Then I created a new android project and added the new libs to the jni/ folder.
Which additional header files do I need to add to the project to use openSSL functions? If I add the include/openssl/folder from guardianproject (which consist of header files) it doesn't compile, is there are some config file in guardianproject?

openssl-android just provides the native openssl libraries libcrypto.so and libssl.so, it does not provide any Java implementation. If you want to use this openssl in native code, you would add the folder relative/path/to/include/openssl/ to LOCAL_C_INCLUDES in your Android.mk. You probably want to add openssl-android as a git submodule to your project.

Related

Using shared library with Conan.io within Android

I have a pre-built shared library (architecture ARM) which I exported as a conan package:
conan export-pkg .. ext/stable --force -pr android_19_arm_clang
Next I want to use this library in my Android project. I have Conan and CMake setup like this.
conanfile.txt:
[requires]
LibraryName/0.1#ext/stable
CMakeLists.txt
...
conan_basic_setup(NO_OUTPUT_DIRS)
...
target_link_libraries( # Specifies the target library.
myOwnAndroidLib-lib
android
${CONAN_LIBS}
)
...
Since the the pre-built library is a ".so" library I have to put it into the jniLibs Folder of my Android project. This part is missing in the conan/Android docs. How can I instrument conan to place the *.so files in the jniLibs folder?
Thank you
If you want to copy pre-built packages to a specific folder when building, you should use the feature imports:
https://docs.conan.io/en/latest/using_packages/conanfile_txt.html#imports
https://docs.conan.io/en/latest/reference/conanfile_txt.html#imports

aes_ctr_128_encrypt in Android using boringSSL

I am trying to implement aes_ctr128_encrypt in android using BoringSSL as defined by google.
I built the application with CMAKE and Gninja by following the link
https://boringssl.googlesource.com/boringssl/+/master/BUILDING.md
Now I have crypto and ssl folders in the build folder but there is no AES definition in any of the files as AES.h was in the include folder in root directory.
Anyhow, The binaries thus generated with CMAKE are also giving .a files and not .so files. How can I use those .a files in my project to access the aes_ctr_128_encrypt?

Linking with native SO file present in included library project of Android

I am working on a project in which it has dependency on another library project. Library project has both java files and native SO files.
Accessing JAVA source files (APIs) from the Android project java source doesn't have any problem. But, my native code is dependent on native SO files present in the included library project of android as well.
Library Project Android Project
--------------- ---------------
src/Java files <-- Java files
libs/.so files <-- libs/.so files
.so files are part of the included library project. How can my current Android project native code try to use .so files of the included library project. Currently I am getting linking error of undefined reference to all the functions which are part of the library/libs/.so files.
Please let me know if any one has faced/resolved similar type of issue.
You probably have both projects imported into your Eclipse. But ndk-build knows nothing about Eclipse. If the library comes with its own .mk file that defines PREBUILT_SHARED_LIBRARY, it would be even better. One such example is OpenCV which includes sdk/native/jni/OpenCV.mk file.
But you can simply add path to the .so files to your Android.mk, e.g. put the following lines in the end of your file:
include $(CLEAR_VARS)
LOCAL_MODULE:=LibraryProjectSO
LOCAL_SRC_FILES:=/LibraryProject/libs/library.so
include $(PREBUILT_SHARED_LIBRARY)
Now you can add LibraryProjectSO to the list of LOCAL_SHARED_LIBRARIES.

NDK - How to use a generated .so library in another project

I have used ndk successfully to build & use a .so file in one project. I need to use this library in another project. I would rather not copy the source there, but just use the library.
Trying to copy & paste the whole libs/armeabi/libcommon.so to the project root does not work, I think because libs/armeabi is an android generated path.
So what would be the best way to do it?
I am using Eclipse-Galileo & ndk5.
There is a much simpler way to do all of this.
Let's say that your prebuilt library is called "libprebuilt.so"
In the project folder of the new project you want to only include the prebuilt library, do something like:
mkdir -p jni/libprebuilt
cp libprebuilt.so jni/libprebuilt
Then, just create a jni/libprebuilt/Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprebuilt
LOCAL_SRC_FILES := libprebuilt.so
include $(PREBUILT_SHARED_LIBRARY)
Then when you do ndk-build, it will copy this library in to libs/armeabi/ ... that's all!
I figured out a way to do this, so posting it here in case someone else runs into it.
The code to be shared (including the Java JNI wrapper, native code, .so library), should be in a separate project. Convert this to a Library project by right-click on project name --> properties --> Android properties --> check mark "Is Library". This project cannot be executed now but can be referenced by other projects.
In the project which will use the shared object, add a reference to the Libarray project by right-click on project name --> properties --> Android properties --> Library/"Add". This should show up the Library project created in the previous step. Select it.
Now the .so can be referred to easily between different projects.
There is a package name inside all JNI (Java Native Interface) functions names (like JNIEXPORT void JNICALL Java_com_myapp_myclass_funct). So i guess you should rename these funkcions in library a recompile it. Or maybe use it as external package in your app.

Creating a product SDK: How do I add a native lib (.so) and a jar with the SDK I am creating?

I am creating a widget that we will provide to developer end users and it consists of a .jar and a native library (.so) built using the NDK. The JAR has a JNI interface to the dynamic library.
It's very clear on how to include an external .jar in a project but not how to include a dependent dynamic library.
How do I package up and build the .jar and .so? What are the best practices here?
I can create the JAR file using the JDK's jar command. Do I need to run dx.bat on the jar to convert to Dalvik bytecode?
I need to create a sample project showing the widget in action. How do I include this .jar and .so in a sample project that demonstrates how to use the widget?
I spent some time on this, and i just can't understand why isn't this written on wikitude documentation.... anyway follow this changes!
go to windows/preferences/android/build
uncheck the first and the second option
extract files from wikitudesdk.jar with winrar as if it is an archive, search libarchitect.so and copy it in /libs/libs/armeabi/
add wikitudesdk.jar to your build path
You should use the standard build tools included with the SDK for this. If you include the .jar files you need in the /lib directory of your project, the ant build process will convert the included class files to Dalvik bytecode format and include them in your classes.dex file for the app. Add a build.properties file to your project root as well, with one line:
external.libs.dir=lib
Depending on the version of your SDK and configuration of it, you may need to place the jar in libs rather than lib.
As for the .so, I presume that it's properly compiled using the Android NDK, or using a build script that uses the proper compiler and compiler flags that are required to successfully link the shared object on Android. If this is the case, you can include the .so file in libs/armeabi and they will be added in the jar as well. Furthermore, the dynamic library loader will know to look in this location in the .jar when you actually try to load the library from Java code.
Using ADT 12, I accomplished this by doing the following:
1) Export JAR from your library with the SO file using Eclipse. Make sure you exclude AndroidManifest.xml. This will include source code and other data, so if you are distributing, you'll want to strip these unnecessary bits out using any ZIP utility.
2) Create a directory in your App's source tree (I use "lib" directory) and copy your library JAR to it.
3) Right-click project in Eclipse and select "Configure Build Path". Add JAR and point it to JAR inside your App source tree.
4) In your Eclipse preferences, select Android/Build section and uncheck "Automatically refresh Resources and Assets folder on build". You will notice an option below that says "Force error when external jars contain native libraries." There is an ADT bug, which will supposedly be fixed in R17, which uses the wrong setting. Once it is fixed, you will use the "Force error" one (make sure it unchecked).
5) Once you build your app APK, you will have a libs/armeabi/libXXXX.so file. This will not be automatically unpacked on install. You will need to write code to extract it from your APK file into your data directory, then use System.load on the .so file in your data directory.
I have bidirectional JNI calls going from the dynamically loaded file, and even use dlopen() on it to do my custom plugin registration stuff.
Add the below lines to android.mk.
include $(BUILD_PACKAGE)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := alias:libs/your.jar
include $(BUILD_MULTI_PREBUILT)

Categories

Resources