LoginSignup
2
0

More than 3 years have passed since last update.

背景

Androidのbuild.gradleのminSdkVersionを16以下に設定し、HMSライブラリを導入すると、ビルド時に次のようなエラーが出てきます。

Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library [com.huawei.hms:hwid:5.2.0.300] xxxxxxxxxxxxxxxxxxxxxxx\AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
        or increase this project's minSdk version to at least 17,
        or use tools:overrideLibrary="com.huawei.android.hms.hwid" to force usage (may lead to runtime failures)

minSdkVersionを17以上に引き上げるか、tools:overrideLibraryで強制ビルドするか、どれかにしろと怒られました。

一番簡単な解決策は当然minSdkVersionを17以上に引き上げることですが、サービスの事情でminSdkVersionを変えられない場合、tools:overrideLibraryで対応するしかありません。しかし、"may lead to runtime failures"という警告文で、もしユーザーのAndroid API レベルが16以下だったら、動作中にクラッシュが起きるのではないかと心配するエンジニアが多くいるのではありませんか。

そこで、tools:overrideLibraryという解決策について考察してみました。

考察

HMSアプリの動作条件

当たり前ですが、HMSアプリはHMSが入っている端末でしか動作しません。もっと正しい言い方ですと、HMS Coreアプリが入っている端末でしか動作しないということです。

image.png

HMS Coreアプリのインストール条件

HMS CoreはAppGalleryからダウンロードできます。AppGalleryで提供されているバージョンは常に最新版になっています。

ちなみに、現時点(2021-3-24)の最新バージョンは5.2.0.303です。

また、オフィシャルサイトでは、HMS Core 2.xが非推奨となっており、2021年12月31日をもってサポートが終了すると発表されました。

つまり、HMS対応はHMS Core 3.0以上のみ考えればよいということです。
そこで、HMS Core アプリのバージョン3.0~5.0のminSdkVersionをまとめてみました。

HMS Core アプリのバージョン minSdkVersion 対応キット数
3.0 19 9個
4.0 19 22個
5.0 19 33個

HMS Core 3.0~5.0のminSdkVersionは19になっています。
つまりHMSが入っている端末のAndroidのAPIレベルが必ず17以上であることが保証されています。

結論

"runtime failures"の条件はユーザーのAndroid APIレベルが16以下であることです。ところが、HMS Coreが入っている端末のAndroid APIレベルが必ず19以上になるので、tools:overrideLibraryで対応しても、"runtime failures"が起きるはずがないという結論が導けます。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0