PR

AndroidStudioで新規プロジェクトのビルドができない問題の解決法

Androidアプリ

エラーが出てビルドできないんですけど…

こうした悩みを解決します。

立プロ

新卒でメーカーに入り、10年間組み込みの現場で設計を行う。
今は個人事業主として自作の組み込み機器開発や、エージェント様に紹介いただき業務委託を行っています。
C,C#,JavaScript, Vue, PHP, VBA, GAS, Kotlinなど、扱う言語が増えゆく日々。

立プロをフォローする

エラー発生する理由

最初にプロジェクトを立ち上げるときにAPIレベルの設定をしますが、いざ立ち上がったプロジェクトは最新のAPIレベルに対応した構成になってるんですね。

なので、下位のAPIレベルに設定してプロジェクトを立ち上げると、プロジェクト構成とAPIレベルが合わないとエラーが出るわけです。

エラー内容

バージョンの差異はあれど下位APIレベルでプロジェクトを作りビルドすると下記のようなエラーが出ると思います。

簡単に言うと、APIレベル33以降を推奨してるのにそれ以下で設計しないで、と言われてます。

6 issues were found when checking AAR metadata:

  1.  Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that depend on it to compile against version 33 or later of the
 Android APIs.
      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33.

Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).

  2.  Dependency 'androidx.appcompat:appcompat:1.6.1' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs.
      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33.

Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).

  3.  Dependency 'androidx.activity:activity:1.6.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs.
      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33.

Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).

  4.  Dependency 'androidx.core:core:1.9.0' requires libraries and applications that  depend on it to compile against version 33 or later of the Android APIs.
      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33.

Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).

  5.  Dependency 'androidx.core:core-ktx:1.9.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs.
      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33.

Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).

  6.  Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs.
      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33.

Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).

解決方法

APIレベル33にすればいいじゃん、ちゃんちゃん…とできればよいのですが、Android OSの都合でアプリのAPIレベルを常に最新状態を保つのが正解ではないことがあります。

Android OSとAPIレベルの関係はAndroidデベロッパー公式を参照ください。
API レベルとは

とりあえず1番目のエラーから対処しましょう。

エラー1

日本語にすると↓

依存関係 'androidx.appcompat:appcompat-resources:1.6.1' は、それに依存するライブラリやアプリケーションがAndroid APIのバージョン33以降にコンパイルされる必要があります。

:appは現在、android-32にコンパイルされています。

推奨されるアクション: このプロジェクトを、例えば33などのより新しいcompileSdkVersionを使用するように更新してください。

ライブラリまたはアプリケーションのcompileSdkVersionを更新すること(新しいAPIを使用できるようにすること)は、targetSdkVersionを更新すること(新しいランタイム動作を有効にすること)やminSdkVersionを更新すること(アプリがインストール可能なデバイスを決定すること)とは別に行うことができることに注意してください。
  1.  Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that depend on it to compile against version 33 or later of the Android APIs.
      :app is currently compiled against android-32.

      Recommended action: Update this project to use a newer compileSdkVersion of at least 33, for example 33.

Note that updating a library or application's compileSdkVersion (which allows newer APIs to be used) can be done separately from updating targetSdkVersion (which opts the app in to new runtime behavior) and minSdkVersion (which determines which devices the app can be installed on).

‘androidx.appcompat:appcompat-resources:1.6.1’ が対応していないということなので、appcompatのバージョンを下げます。

build.gradleのdependenciesに書かれています。

implementation 'androidx.appcompat:appcompat:1.6.1'
↓
implementation 'androidx.appcompat:appcompat:1.5.1'

1.6.1を1.5.1に下げました。

下げたらコード上部にSync Nowが表示されるのでクリックするのを忘れずに!

Sync Nowを忘れるとアプリの実行もデバッグもできなくなりますからね。

appcompatのリリース情報はリンクを参照ください。

Androidアプリを開発する際に便利なライブラリの1つである「AndroidX AppCompat」は、Googleが提供するサポートライブラリの1つです。AppCompatライブラリは、古いバージョンのAndroid OSでも新しいAPIやUIデザインを使えるようにするためのライブラリで、主にAndroidのバージョン5.0(APIレベル21)以降で利用されます。例えば、アクションバーのサポート、ツールバーの使用、アプリケーションのテーマの変更など、多くの機能を提供しています。AppCompatライブラリは、開発者がユーザーによりよいUI体験を提供するのを助けるために非常に重要な役割を果たしています。

これで無事ビルドできて、アプリが動きました!

まとめ

APIレベルを最新でない状態でプロジェクトを作成した場合、build.gradleのdependenciesにある

implementation ‘androidx.appcompat:appcompat:1.6.1’

のバージョンを下げましょう

コメント

タイトルとURLをコピーしました