Ошибка «не удалось разрешить проект» при включении проекта зависимости от другого для сборки Android с Gradle - PullRequest
0 голосов
/ 18 апреля 2019

Я не могу заставить Gradle распознать зависимость для проекта Android.Мне удалось сократить это до минимальный , и я все еще получаю ошибки.

Как включить простую библиотечную зависимость в другой проект?

Это структура папок очень простая:

 - build.gradle
 - settings.gradle
 + myproject
   - build.gradle
 + mylibrary
   - build.gradle

Ошибка «Не удалось разрешить проект»"/" Невозможно найти подходящий вариант проекта "

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 Ответ

1 голос
/ 18 апреля 2019

Для библиотеки Android применяемый плагин должен быть com.android.library вместо просто android, попробуйте заменить

apply plugin: 'android'

в вашей библиотеке build.gradle на

apply plugin: 'com.android.library'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...