Android AAR构建流程能否包含libssl.so.1.1?
Hey there, let's break down what's going on here and how to get that missing .so.1.1 file into your AAR.
Why libssl.so.1.1 is Missing
First off, the core issue ties to how Android's build tools handle shared libraries, combined with OpenSSL 1.1.0's default output behavior:
- OpenSSL 1.1.0 generates two SSL-related files:
libssl.so.1.1(the actual compiled shared library) andlibssl.so(a symbolic link pointing to the versioned.so.1.1file). - By default, Android build tools like Gradle's NDK plugin filter out shared libraries with version suffixes (like
.so.1.1) when packaging AARs. They prioritize unversioned.sofiles, which align with Android's standard library loading expectations.
How to Include libssl.so.1.1 in Your AAR
Here are a few practical fixes to ensure the versioned library gets packed properly:
1. Manually Copy the Versioned Library to JNI Libs Directory
- Navigate to your OpenSSL build output directory for each target Android architecture (e.g.,
armeabi-v7a,arm64-v8a). - Locate
libssl.so.1.1and copy it into the correspondingsrc/main/jniLibs/<architecture>/directory of your Android library module. - Rebuild your AAR—Gradle will now include this file since it’s in the standard JNI libs location.
2. Adjust Gradle Configuration to Include Versioned .so Files
Modify your module's build.gradle (or build.gradle.kts) to explicitly include files with version suffixes:
android { sourceSets { main { jniLibs.srcDirs += 'path/to/your/openssl/build/outputs' jniLibs.include '**/*.so', '**/*.so.*' // Include both unversioned and versioned .so files } } }
This tells Gradle to pick up all .so files (including versioned ones) from your OpenSSL build directory.
3. Tweak OpenSSL Build to Generate Unversioned .so Directly
If you don’t strictly need the versioned file, adjust the OpenSSL build process to output libssl.so as the primary library (instead of a symlink):
- When configuring OpenSSL for Android, add the
--libdir=libflag to override the versioned output:
./Configure android-arm64 no-ssl2 no-ssl3 --prefix=/path/to/installation --libdir=lib make && make install
This generates libssl.so directly as the compiled library, eliminating the need to include the versioned file altogether.
Final Check
After applying any of these fixes, unpack your generated AAR (rename it to .zip and extract) to verify that libssl.so.1.1 is present in the jniLibs directory for each target architecture.
内容的提问来源于stack exchange,提问作者Sean

