Android Studio Gradle 无法解析符号 'applicationVariants'。

5

我正在尝试解决Gradle的一个烦人问题,即不允许库有不同的min/target sdk版本。解决方法是将以下内容添加到build.gradle文件中。

android.applicationVariants.all{ variant ->
    // This is an annoying hack to get around the fact that the Gradle plugin does not support
    // having libraries with different minSdkVersions. Play Services has a min version of 9 (Gingerbread)
    // but Android Maps Utils supports 8 (Froyo) still
    variant.processManifest.doFirst {
        File manifestFile = file("${buildDir}/exploded-bundles/ComGoogleMapsAndroidAndroidMapsUtils03.aar/AndroidManifest.xml")
        if (manifestFile.exists()) {
            println("Replacing minSdkVersion in Android Maps Utils")
            String content = manifestFile.getText('UTF-8')
            content = content.replaceAll(/minSdkVersion="8"/, 'minSdkVersion=\"9\"')
            manifestFile.write(content, 'UTF-8')
            println(content)
        }
    }
}

然而,当我这样做时,出现了一个错误,提示无法解析applicationVariants。我该如何解决?

3
如果你在使用Android Studio,那么IDE会给出很多不正确的错误提示。 如果成功构建了就忽略它们。看着我的构建文件,我也会得到关于"applicationVariants"的那个错误,但仍能构建成功。 - ashishduh
哦,你说得对。把它变成一个答案! - Tyler
这对我来说很好用。你们能添加一个答案吗?@styler1972 - Jared Burrows
1个回答

1
显然,这是一个Android Studio的bug,它告诉我有错误,但实际上并没有。构建和忽略工作正常。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接