在升级到gradle 3时获取app build.gradle同步问题。+

时间:2018-04-08 17:05:23

标签: android gradle android-gradle

我正在更新一个项目,其中包含许多不同的库和风味。我能够解决项目中的所有库,但是在更新应用程序build.gradle时我遇到了一个问题。以下是错误和谜语。我显然误解了文档,无法找到正确的解决方案。如何在app build.gradle级别解决此同步问题?

错误

Unable to resolve dependency for ':app@magicDebug/compileClasspath': Could not resolve project :vnfmdata.

Could not resolve project :vnfmdata.
Required by:
    project :app
 > Project :app declares a dependency from configuration 'implementation' to configuration 'regularDebug' which is not declared in the descriptor for project :vnfmdata.

App build.gradle

android {
    ...
    flavorDimensions flavor.default
    productFlavors {
        ...
        magic {
            ...
            flavorDimensions flavor.default
            // missingDimensionStrategy flavor.regular, flavor.regular
            // matchingFallbacks = [flavor.regular]
            dependencies {
                ...
                implementation project(':vnfmdata')
                // implementation project(path: ':vnfmdata', configuration: 'regularDebug') // pre gradle 3.0
                ...
            }
        }
    }
}

___下面的两个图书馆同步正常___

vnfmdata build.gradle

android {
    ...
    flavorDimensions flavor.no_meridian, flavor.regular
    productFlavors {
        regular {
            dimension flavor.regular
            // Forces regular's flavor to point on LocationService meridian's flavor
            // because their flavors' name are different
            matchingFallbacks = [flavor.meridian]
        }
        no_meridian {
            dimension flavor.no_meridian
            // Will automatically point on LocationService no_meridian's flavor
            // because they both have the same name
        }
    }
    buildTypes {
        release {}
    }
    ...
}

dependencies {
    ... 
    implementation project(':vnlocationservice')
    ...
}

vnlocationservice build.gradle

android {
    ...
    /** Flavors **/
    flavorDimensions flavor.meridian, flavor.no_meridian
    productFlavors {
        no_meridian {
            dimension flavor.no_meridian
        }
        meridian {
            dimension flavor.meridian
            dependencies {
                implementation project(':third:Sas-Android')
                implementation deps.support.compat_v26
                implementation deps.play.ads
                implementation deps.play.location
                implementation deps.localytics
                implementation 'com.arubanetworks.meridian:meridian:+@aar'
            }
        }
    }
    buildTypes {
        release {}
    }
    ...
}

dependencies {
    ...
}

1 个答案:

答案 0 :(得分:1)

您的模块目前没有维度,因此您只应使用一个维度,例如应用程序的build.gradle flavorDimensions flavor.default

(参见documentation的这一部分,看看使用flavorDimensions时的多重输出。)

<强> vnfmdata

...
//With only one dimension, you can omit 'dimension' into your flavors
flavorDimensions flavor.default

productFlavors {
    regular {
        dimension flavor.default
        ...
    }
    no_meridian {
        dimension flavor.default
    }
}

<强> vnlocationservice

...
//With only one dimension, you can omit 'dimension' into your flavors
flavorDimensions flavor.default

productFlavors {
    no_meridian {
        dimension flavor.default
    }
    meridian {
        dimension flavor.default
        dependencies {
            ...
        }
    }
}