ユーザーは、ミドルウェアより低い minSdkVersion を使用できません。たとえばユーザーのアプリを API 21 で実行する必要がある場合、API 24 向けにビルドすることはできません。ユーザーより低い API レベル向けにライブラリをビルドするのは問題ありません。たとえば API 16 向けにビルドしても、API 21 ユーザーと互換性を維持できます。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# Advice for middleware vendors\n\nDistributing middleware built with the NDK raises some additional issues that\napp developers do not need to worry about. Prebuilt libraries impose some of\ntheir implementation choices on their users.\n\nChoosing API levels and NDK versions\n------------------------------------\n\nYour users cannot use a [minSdkVersion](/ndk/guides/sdk-versions#minsdkversion) lower than yours. If your users' apps\nneed to run on API 21, you cannot build for API 24. It is okay to build your\nlibrary for a *lower* API level than your users. You can build for API\n16 and remain compatible with your API 21 users.\n\nNDK versions are largely compatible with each other, but occasionally there are\nchanges that break compatibility. If you know that all of your users are using\nthe same version of the NDK, it's best to use the same version that they do.\nOtherwise, use the newest version.\n\nUsing the STL\n-------------\n\nIf you're writing C++ and using the STL, your choice between `libc++_shared` and\n`libc++_static` affects your users if you distribute a shared library. If you\ndistribute a shared library, you must either use `libc++_shared` or ensure that\nlibc++'s symbols are not exposed by your library. The best way to do this is to\nexplicitly declare your ABI surface with a [version script](/ndk/guides/this%20also%20helps%0Akeep%20your%20implementation%20details%20private).\n\nAnother, less robust option is to use `-Wl,--exclude-libs,libc++_static.a\n-Wl,--exclude-libs,libc++abi.a` when linking. This is less robust because it\nwill only hide the symbols in the libraries that are explicitly named, and no\ndiagnostics are reported for libraries that are not used (a typo in the library\nname is not an error, and the burden is on the user to keep the library list up\nto date). This approach also does not hide your own implementation details.\n\nDistributing native libraries in AARs\n-------------------------------------\n\n| **Note:** This section describes how to distribute C/C++ *APIs* to users. If your native libraries are implementation details of your *Java* API, see the [Java\n| middleware with JNI libraries](#java_middleware_with_jni_libraries) section.\n\nThe Android Gradle plugin can import [native dependencies](/studio/build/dependencies#using-native-dependencies) distributed in\n[AARs](/studio/projects/android-library). If your users are using the Android Gradle plugin, this will be the\neasiest way for them to consume your library.\n\nNative libraries can be packaged into an AAR [by\nAGP](/studio/releases/gradle-plugin#4.1-prefab-publish). This will be the\neasiest option if your library is already built by [externalNativeBuild](/reference/tools/gradle-api/current/com/android/build/api/dsl/ExternalNativeBuild).\n\nNon-AGP builds can use [ndkports](https://android.googlesource.com/platform/tools/ndkports/), or perform manual packaging by following the\n[Prefab](https://google.github.io/prefab/) documentation to create the `prefab/` subdirectory of their AAR.\n\nJava middleware with JNI libraries\n----------------------------------\n\nJava libraries that include JNI libraries (in other words, AARs that contain\n`jniLibs`) need to be careful that the JNI libraries they include will not\ncollide with other libraries in the user's app. For example, if the AAR includes\n`libc++_shared.so`, but a different version of `libc++_shared.so` than the app\nuses, only one will be installed to the APK and that may lead to unreliable\nbehavior.\n| **Warning:** [Bug 141758241](https://issuetracker.google.com/141758241): Older versions of the Android Gradle plugin do not currently diagnose this error condition. One of the identically named libraries will be arbitrarily chosen for packaging in the APK.\n\nThe most reliable solution is for Java libraries to include no more than **one**\nJNI library (this is good advice for apps too). All dependencies including the\nSTL should be statically linked into the implementation library, and a version\nscript should be used to enforce the ABI surface. For example, a Java library\n`com.example.foo` that includes the JNI library `libfooimpl.so` should use the\nfollowing version script: \n\n LIBFOOIMPL {\n global:\n JNI_OnLoad;\n local:\n *;\n };\n\nThis example uses `registerNatives` via `JNI_OnLoad` as described in [JNI Tips](/training/articles/perf-jni#native-libraries)\nto ensure that the minimal ABI surface is exposed and library load time is\nminimized."]]