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

sty*_*972 5 android gradle android-studio

我试图解决Gradle的一个烦人的问题,它不允许库有不同的最小/目标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)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我收到一个错误,即applicationVariants无法解析.我该如何解决?

sty*_*972 1

显然,这是一个 Android Studio 错误,它告诉我在没有错误的地方有错误。构建和忽略效果很好。