AndroidStudio 警告・エラー対処メモ

ある時点でビルド・実行できていた`android`プロジェクトで、各種バージョンを最新化した際に発生した警告・エラーに対処した時のメモ。

## 環境

| 項目 | 変更前 | 変更後 |
|:-----------|:------------|:-------------|
| Android Studio | 4.0.1 | 4.1.1 |
| gradle | 6.1.1 | 6.5 |
| buildToolsVersion | 30.0.2 | 30.0.3 |
| kotlin | 1.3.72 | 1.4.21 |
| retrofit2 | 2.5 | 2.9 |

## ビルド時のエラー: Failed to install the following Android SDK packages as some licences have not been accepted.

```
Failed to install the following Android SDK packages as some licences have not been accepted.
   build-tools;30.0.2 Android SDK Build-Tools 30.0.2
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
```

**原因**
単純に、`build.gradle`の`buildToolsVersion`で指定されていたバージョンの`Android SDK Build-Tools`がインストールされていない。

**対処**
以下のいずれかで対処。

1. `build.gradle`の`buildToolsVersion`で指定されているバージョンの`Android SDK Build-Tools`をインストール

1. `build.gradle`の`buildToolsVersion`を既にインストールされているものに変更

```gradle:app/build.gradle
android {
    compileSdkVersion 30
    buildToolsVersion '30.0.3'  // '30.0.2'
```

## ビルド時の警告: DSL element 'android.dataBinding.enabled' is obsolete

```
DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
```

**対処**

- 参考URL
  - [Databinding  |  Android デベロッパー  |  Android Developers](https://developer.android.com/jetpack/androidx/releases/databinding)
- 変更前

```gradle:app/build.gradle
    dataBinding {
        enabled = true
    }
```

- 変更後

```gradle:app/build.gradle
    buildFeatures {
        dataBinding true
    }
```

## ビルド時の警告: -Xcoroutines has no effect

```
w: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
```

**対処**

- 変更前

```gradle:app/build.gradle
    kotlin {
        experimental {
            coroutines 'enable'
        }
    }
```

- 変更後

```gradle:app/build.gradle
    kotlin {
        experimental {
//            coroutines 'enable'
        }
    }
```

## ビルド時の警告: The 'kotlin-android-extensions' Gradle plugin is deprecated.
`kotlin`のバージョンを **1.3.72** から **1.4.21** に上げた事で発生。

```
The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.
```

**対処**

- 変更前

```gradle:app/build.gradle
apply plugin: 'kotlin-android-extensions'
```

- 変更後

```gradle:app/build.gradle
//apply plugin: 'kotlin-android-extensions'
```

## 実行時のエラー
`retrofit2`のバージョンを **2.5** から **2.9** に上げた事で発生。

API26の仮想デバイスで実行時

```
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.helloapp, PID: 1234
    java.lang.RuntimeException: Unable to instantiate application (...)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:971)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5765)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
(...)
```

API30の仮想デバイスで実行時

```
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.helloapp, PID: 1234
    java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)
        at okhttp3.internal.Util.<clinit>(Util.java:87)
        at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)
        at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313)
        at okhttp3.HttpUrl.get(HttpUrl.java:917)
        at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:506)
(...)
```

**対処**

以下の設定を追加。

```gradle:app/build.gradle
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
```