0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AndroidStudio 警告・エラー対処メモ

Last updated at Posted at 2020-12-30

ある時点でビルド・実行できていた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.gradlebuildToolsVersionで指定されていたバージョンのAndroid SDK Build-Toolsがインストールされていない。

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

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

  2. build.gradlebuildToolsVersionを既にインストールされているものに変更

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'.

対処

app/build.gradle
    dataBinding {
        enabled = true
    }
  • 変更後
app/build.gradle
    buildFeatures {
        dataBinding true
    }

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

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

対処

  • 変更前
app/build.gradle
    kotlin {
        experimental {
            coroutines 'enable'
        }
    }
  • 変更後
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.

対処

  • 変更前
app/build.gradle
apply plugin: 'kotlin-android-extensions'
  • 変更後
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)
(...)

対処

以下の設定を追加。

app/build.gradle
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
0
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?