Androidアプリ開発で、minSDKVersionが14のアプリでminSDKVersionが16のライブラリを使おうとしたら、以下のようなエラーが出ました。
Execution failed for task ':NPK:processReleaseManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 16 declared in library AndroidManifest.xml as the library might be using APIs not available in 14
Suggestion: use a compatible library with a minSdk of at most 14,
or increase this project's minSdk version to at least 16,
or use tools:overrideLibrary="com.mopub.mobileads" to force usage (may lead to runtime failures)
今回はこの対処法についてのメモ。
アプリのminSDKVersionよりも高いAPI Levelのライブラリを使う場合の対処法
エラーの内容的には、"com.mopub.mobileads"がminSDK 16なので、minSDK14のアプリでは利用できないよっていうエラーです。
色々調べた結果、以下のサイトが見つかりました。
こちらのサイトの内容と、エラーログでの提案を参考に、AndroidManifest.xmlを以下のように編集したらエラーが解決しました。
//AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.app.test"> <uses-sdk tools:overrideLibrary="com.mopub.mobileads" /> ... </manifest>
"uses-sdk tools:overrideLibrary"の記述だけだとエラーが出るので、xmlns:tools="http://schemas.android.com/tools" を定義するのがポイントです。
アプリのminSDKよりも高いAPI Levelのライブラリは使用できないと思っていたので驚きでした。
AndroidManifest.xml にoverrideLibraryとして該当するライブラリを指定することによって、
オーバーライドしてくれるっぽいですね。
developer.android.com
overrideLibraryを複数定義する場合
ちなみにoverrideLibraryを1つではなく、複数定義したい場合は以下のような記述になります。
//AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.app.test"> <uses-sdk tools:overrideLibrary="com.example.lib1, com.example.lib2,com.example.lib2, com.example.lib4" /> ... </manifest>
最初、単純にoverrideLibraryを2行追加したのですが、overrideLibraryは既に定義されているっていうエラーが出てしまいました。
以下を参考にしました↓