#android #gradle
#Android #gradle
Вопрос:
Кажется, я не могу заставить Gradle распознавать зависимость для проекта Android. Мне удалось свести это к минимуму, и я все еще получаю ошибки.
Как я могу включить простую зависимость библиотеки в другой проект?
Это структура папок очень проста:
- build.gradle
- settings.gradle
myproject
- build.gradle
mylibrary
- build.gradle
Ошибка «Не удалось разрешить проект» / «Не удалось найти соответствующий вариант project»
command: gradle build
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':mylibrary:preReleaseBuild'.
> Could not resolve all task dependencies for configuration ':mylibrary:releaseRuntimeClasspath'.
> Could not resolve project :mylibrary.
Required by:
project :mylibrary
> Unable to find a matching variant of project :mylibrary:
- Variant 'debugApiElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found incompatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Variant 'debugBundleElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' but no value provided.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'android-bundle'.
- Variant 'debugMetadataElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found incompatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Metadata'.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Variant 'debugRuntimeElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found incompatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
- Variant 'releaseApiElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found compatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'java-api'.
- Variant 'releaseBundleElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' but no value provided.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-runtime' and found incompatible value 'android-bundle'.
- Variant 'releaseMetadataElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found compatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Metadata'.
- Required org.gradle.usage 'java-runtime' but no value provided.
- Variant 'releaseRuntimeElements' capability gradle-test2:mylibrary:unspecified:
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found compatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
Содержимое моих файлов таково:
./build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
ext {
compileSdkVersion = 28
buildToolsVersion = '28.0.3'
supportLibVersion = '28.0.0'
applicationId = 'com.example'
minSdkVersion = 16
targetSdkVersion = 26
versionCode = 1
versionName = '1.0'
}
./settings.gradle
include ':myproject', ':mylibrary'
./myproject/build.gradle
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
implementation project(':mylibrary')
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId rootProject.ext.applicationId
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
buildTypes {
release {}
debug {}
}
}
./mylibrary/build.gradle
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId rootProject.ext.applicationId ".mylibrary"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
buildTypes {
release {}
debug {}
}
}
Ответ №1:
Для библиотеки Android применяемый плагин должен быть com.android.library
вместо just android
, попробуйте заменить ваш
apply plugin: 'android'
в вашей библиотеке build.gradle
, чтобы
apply plugin: 'com.android.library