2015年10月4日日曜日

Android Studioのバージョンアップに伴うビルドエラー(Gradle x.x requires Android Gradle plugin x.x.x ...)

Android Studioをバージョンアップすると、バージョンアップ前に作成していたプロジェクトのビルドでエラーが発生することがあります。
これは、Android Studioのバージョンアップの際に、ビルドシステムのGradleもバージョンアップされているからです。

今回は、以下のようなエラーが発生した時の対処方法です。

【エラー】
Gradle x.x requires Android Gradle plugin x.x.x (or newer) but project is using version x.x.x.
Please use Android Gradle plugin x.x.x or newer.

Fix plugin version and sync project


【対処】
メッセージにあるリンク箇所(Fix plugin version and sync project)をクリックするとAndroid Gradle pluginのクラスパス設定が修正されて、プロジェクトの同期が再実施されます。

Android Gradle pluginのクラスパス設定は、build.gradleのdependenciesに記載されています。
-----
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
-----

上記は、Android Gradle plugin 1.3.0が設定されている例です。