libc++_shared.so from library that uses Oboe is clashing with another library
- Dominant language
- C++
- Stars
- 4.1k
- Forks
- 639
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 8
Description
Android version(s): N/A (didn't get that far)
Android device(s): N/A (as above)
Oboe version: 1.5.0
App name used for testing: A closed-source app, sorry
**Short description**
This is a build issue.
I've made an Android **library** which uses Oboe (from prefab), called `MidiPlayer`. As advised in [GettingStarted.md](https://github.com/google/oboe/blob/master/docs/GettingStarted.md), I'm using libc++_shared.so.
I also have an Android **app**. In the app, I include both `MidiPlayer` and a totally unrelated 3rd party library. I get the following error:
```
More than one file was found with OS independent path 'lib/arm64-v8a/libc++_shared.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake
```
Unhelpfully, that link is wrong. But I think it's supposed to point [here](https://developer.android.com/studio/releases/gradle-plugin#cmake-imported-targets), however this is irrelevant (I don't have a jniLibs directory).
The issue is that by following the advice in GettingStarted.md, I end up with a copy of `libc++_shared.so` in the package. Specifically, when I look in my .gradle folder I see a folder called `jetified-midiplayer-` which contains a jni directory, and for each platform folder it contains `libc++_shared.so`. This appears to be clashing with other Android libraries which do the same thing. How am I supposed to do this? Should I just use the `c++_static` Android STL? I figure that's bad form because it increases the size of my app. It also goes against the advice in GettingStarted.md.
**Detailed description**
Disclaimer: I'm not experienced with C or C++. I am just trying to follow instructions.
My **library** (`MidiPlayer`) has a build.gradle that looks something like this:
```
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
versionCode project.versionCode
versionName project.versionName
...
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
version "3.10.2"
}
}
buildFeatures {
prefab true
}
}
dependencies {
...
implementation 'com.google.oboe:oboe:1.5.0'
}
```
My `CMakeLists.txt` looks like this:
```
cmake_minimum_required(VERSION 3.4.1)
add_library (nativeMidiSynth SHARED path/to/source1.cpp path/to/source2.cpp)
find_package (oboe REQUIRED CONFIG)
target_link_libraries(nativeMidiSynth log oboe::oboe)
```
I then publish this Android library to a maven repository. Over in my app (separate codebase), I pull this and the clashing library ([`pdfium`](https://github.com/barteksc/PdfiumAndroid), a dependency of [`android-pdf-viewer`](https://github.com/barteksc/AndroidPdfViewer)) in with:
```
dependencies {
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
implementation "com.example:midiplayer:0.1.0"
}
```
Then, when building I see the error mentioned above. By searching through my `.gradle` directory I found that these are the two packages that contain `libc++_shared.so`. For example, my MidiPlayer's `jni\arm64-v8a` directory (in `C:\Users\chris\.gradle\caches\transforms-2\files-2.1\cb0f0382d7f01637cf539290e3e3d990\jetified-midiplayer-1.3.1`) contains 3 files:
- `libc++_shared.so`
- `libnativeMidiSynth.so` - my native library which uses oboe
- `liboboe.so`
pdfium's `jni\arm64-v8a` directory (in `C:\Users\chris\.gradle\caches\transforms-2\files-2.1\d99f523756be4de3c5d148ea12d9cbab\jetified-pdfium-android-1.9.0`) contains these files:
- `libc++_shared.so`
- `libjniPdfium.so`
- `libmodft2.so`
- `libmodpdfium.so`
- `libmodpng.so`
So how do I, you know, _share_ this library? Why does it cause a clash?
Contributor guide
Assessment
This issue has not been assessed yet.