Как добавить модуль с двумя вариантами зависимости?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как добавить модуль с двумя вариантами зависимости?

Сообщение Anonymous »

У меня есть два модуля, например Common и Feature, я хочу, чтобы Feature зависел от Common, поэтому я добавляю его в build.gradle следующим образом:

Код: Выделить всё

implementation project(path: ':Common')
Внутри common есть две папки: одна предназначена для некоторых функций и классов, которые должны оставаться общими для всех вариантов, а другая — с различными службами push-уведомлений (google и huawei).

Проблема, с которой я столкнулся, заключается в том, что когда я пытаюсь построить проект, я получаю эту ошибку:

Код: Выделить всё

Could not determine the dependencies of task ':feature:...'.
> Could not resolve all task dependencies for configuration ':feature:...'.
> Could not resolve project :common.
Required by:
project :feature:... > project :common
> The consumer was configured to find a library for use during runtime, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.2.2', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :comomon:
- googleDebugRuntimeElements
- huaweiDebugRuntimeElements
All of them match the consumer attributes:
- Variant 'googleDebugRuntimeElements' capability App:common:unspecified declares a library for use during runtime, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.2.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Unmatched attributes:
- Provides attribute 'com.android.build.api.attributes.ProductFlavor:pushService' with value 'google' but the consumer didn't ask for it
- Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'googleDebug' but the consumer didn't ask for it
- Provides attribute 'pushService' with value 'google' but the consumer didn't ask for it

Я попробовал добавить это в Feature build.gradle:

Код: Выделить всё

flavorDimensions += "pushService"

productFlavors {
google {
dimension "pushService"
}
}
и после этого все работает, но я не хочу добавлять это к каждой функции внутри моего проекта, может быть, есть лучшие решения для этого случая? Я хочу использовать только файлы из общей части общего модуля

Подробнее здесь: https://stackoverflow.com/questions/790 ... dependency
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»