'Why does Prefab NDK Dependencies not work?
I have some native code that depends on OpenSSL. In the beginning, I tried manually compiling OpenSSL for Android, but it simply wouldn't find the definitions. Then I decided to move on and try using Prefabs instead. I followed the example Android NDK Prefab example, but it just doesn't work.
My CMakeLists contains the following
find_package(openssl REQUIRED CONFIG)
target_link_libraries(
testproject
openssl::openssl)
My build.gradle:
android {
compileSdk 31
defaultConfig {
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
prefab true
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.android.ndk.thirdparty:openssl:1.1.1l-beta-1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
But whenever I compile, I get
Could not find a package configuration file provided by "openssl" with any
of the following names:
opensslConfig.cmake
openssl-config.cmake
Looking into the downloaded data, I see the openSSL folder under cmake only contains opensslConfigVersion.cmake and not opensslConfig.cmake, as it does with curl, for example.
What is going on? Why is this not working? Any help is appreiciated.
Solution 1:[1]
The curl-ssl example in the [ndk samples](gitclo https://github.com/android/ndk-samples)
only builds because it allows C++ and STL.
But openssl is C only.
The maven repo ndk thirdparty
links to the sources for the prefab package for openssl and curl among others,
i.e. ndkports.
There is no reference to C++ there for openssl.
It seems the problem is by prefab.
I found this issues: OpenSSL forces c++_shared – why?
Judging from this and other issues there is a high chance that prefab might just not fit your and my project as of yet.
You don't get an according curl message, because curl depends on openssl,
which makes the latter build first.
If you remove openssl you get:
Error: curl depends on unknown dependency openssl
I first did have no ndkVersion defined, as you.
Only afterward I got more error messages:
... //openssl/crypto. Rejected the following libraries:
C/C++: prefabandroid.arm64-v8a: User is targeting armeabi-v7a but library is for arm64-v8a
Removing armeabi-v7a from
ndk.abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
I got
... //openssl/ssl. Rejected the following libraries:
C/C++: prefabandroid.arm64-v8a: User requested no STL but library requires libc++
C/C++: prefabandroid.armeabi-v7a: User is targeting arm64-v8a but library is for armeabi-v7a
Another sign that prefab is ealily getting confused.
And because it was not built finally:
Could not find a package configuration file provided by "openssl" with any
of the following names:
··
opensslConfig.cmake
openssl-config.cmake
The file refers to
app/.cxx/cmake/debug/prefab/arm64-v8a/prefab/lib/aarch64-linux-android/cmake/openssl/opensslConfig.cmake
This has links that point to ~/.gradle.
So the include and link directories are somewhere deep down in ~/.gradle and not under the project directory.
One can include native code directly via cmake. The ndkports are a starting point for to configuration.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roland Puntaier |
