Guide to Cross‑Compiling OpenSSL 1.1.0e for Android, iOS, and Linux with JNI Integration
This tutorial explains how to build and integrate OpenSSL 1.1.0e for modern Android, iOS, and Linux environments, providing shell scripts for each platform, detailed configuration steps, and examples of using the resulting static libraries in C, JNI, and Java code.
Due to project requirements the author revisits OpenSSL 1.1.0e, noting that the traditional porting method no longer works with the latest Mac, NDK, and iOS 10.3 SDKs.
Porting to Android
A shell script is provided that downloads the source, prepares output directories, creates per‑architecture toolchains, sets environment variables, configures OpenSSL, builds static libraries, and copies the results. The script supports arm, armv7, x86, arm64‑v8a, x86_64, mips, and mips64 architectures.
#!/bin/sh
if [ ! -f "openssl-1.1.0e.tar.gz" ]; then
wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
fi
if [ ! -d "openssl-1.1.0e" ]; then
tar zxf openssl-1.1.0e.tar.gz
fi
# env setup, toolchain creation, compile function, and calls for each arch …
echo "done"Porting to iOS
Because existing scripts fail on the newest toolchain, a new script is written that builds OpenSSL for i386, x86_64 (mac), and arm64, armv7, x86_64, i386 (iOS). It sets the minimum deployment target to iOS 8.0, adjusts compiler flags, and uses lipo to create universal static libraries.
#!/bin/sh
# similar download steps …
mkdir "out/openssl/ios"
_compileIOS "arm64" "iPhoneOS" "iphoneos-cross"
# other architecture calls …
lipo -create … -output out/openssl/ios/libssl.a
lipo -create … -output out/openssl/ios/libcrypto.a
echo "done"Linux compilation and JNI usage
A simple Linux build script compiles OpenSSL with ./config . After building, libssl.a and libcrypto.a are ready for static linking and JNI.
#!/bin/sh
if [ ! -f "openssl-1.1.0e.tar.gz" ]; then
wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
fi
if [ ! -d "openssl-1.1.0e" ]; then
tar zxf openssl-1.1.0e.tar.gz
fi
cd openssl-1.1.0e/
./config
make clean
make -j4
cd ..
echo "done"Example C functions demonstrate AES encryption/decryption using OpenSSL APIs, followed by a JNI header and Java wrapper class that expose encode and decode methods. Build commands for the native shared library and Java execution are also included.
#include
JNIEXPORT jstring JNICALL Java_com_sample_AES_encode(JNIEnv*, jclass, jstring, jstring);
JNIEXPORT jstring JNICALL Java_com_sample_AES_decode(JNIEnv*, jclass, jstring, jstring);
// Java class
package com.sample;
public class AES {
static { System.loadLibrary("sample"); }
public static native String encode(String key, String text);
public static native String decode(String key, String text);
}Finally, shell scripts show how to compile the native library with g++ linking against OpenSSL and JNI headers, and how to run the Java test program.
Hujiang Technology
We focus on the real-world challenges developers face, delivering authentic, practical content and a direct platform for technical networking among developers.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.