Support Library APIの追加
ネイティブのActionBarはAPIレベル21以降。Support Library の Toolbar ならAPIレベル7以降をサポートできる。
Projectのbuild.gradleファイル内にGoogle Mavenリポジトリを組み込む
allprojects{
repositories{
google()
// もし、gradle versionが4.1以下なら、代わりに以下を使う
// maven{
// url 'https://maven.google.com'
// }
}}
次に、サポートライブラリを使用するモジュールごとに、build.gradle内のdependenciesブロックにライブラリ(v4 core-utils)を追加
build.gradle
dependencies{
...
implementation "com.android.support:support-core-utils:28.0.0"
// implementation "com.android.support:appcompat-v7:28.0.0"
// versionを省略記載するとバグるかも
サポートライブラリを使用して、既存アプリの以前のバージョンまで広げる場合、manifestのタグに以前のバージョン番号を設定する。これでアプリがAndroid APIレベル14以降を搭載するデバイスにインスツールできるようになる。
manifest
<uses-sdk
android:minSdkVertion="14"
android:targetSdkVersion="23" />
でも、これよりもbuild.gradle内でminSdkVersionの設定のほうが優先されるよ
build.gradle
apply plugin:'com.android.application'
android{
...
defaultConfig{
minSdkVersion 16
...
}
...
}
サポートライブラリを複数追加する場合、指定したライブラリで必要となる最新のSDKバージョンを最小SDKバージョンとして設定する必要あり。
例)V14 preferenceサポートライブラリと、V17 Leanbackライブラリの両方をアプリに組み込む場合、最小SDKバージョンを17以上にする。