16
10

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 5 years have passed since last update.

ビルドタイプを追加すると依存モジュールでもそのビルドタイプが要求されてしまう問題の解決法

Posted at

背景

複数のモジュールに依存しているプロジェクトで、メインとなる app モジュールに staging というビルドタイプを追加してプロジェクトを Gradle Sync すると、次のようなエラーが発生しました。

Unable to resolve dependency for ':app@staging/compileClasspath': Could not resolve project :your-another-module. Open File Show Details

原因と解決法

依存している your-another-module というモジュールに staging という名前のビルドタイプが存在しないことが原因のエラーのようです。

これは Android Gradle Plugin 3.0 での変更点で、以下に記述があります。

Android Plugin for Gradle 3.0.0 への移行 | Android Studio

matchingFallbacks

matchingFallbacks を使用して、特定のビルドタイプが存在しなかった時に使用するビルドタイプを定義できます。

build.gradle
android {
    buildTypes {
        release {
            ...
        }
        debug {
            ...
        }
        staging {
            matchingFallbacks = ['debug']
        }
    }
}

このように定義しておくと、 stating ビルドタイプが依存モジュールに存在しない場合に debug ビルドタイプが使用されます。

matchingFallbacks には複数のフォールバック先を指定することが出来るため、たとえば

build.gradle
staging {
    matchingFallbacks = ['qa', 'debug']
}

のように指定できます。この場合、依存モジュールに staging ビルドタイプがあればそれが使用され、なければ qa, debug の順に存在が確認され存在するものが使用されます。

参照

このエラーの原因がわからず、検索の仕方が悪かったのか、ロシア語の以下のサイトを見つけるまで解決できずに悩んでました..

16
10
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
16
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?