LoginSignup
0
0

More than 3 years have passed since last update.

51歳から(現52)のプログラミング 備忘 Support Library API追加

Last updated at Posted at 2020-02-10

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以上にする。

0
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
0
0