如何在Flutter项目的build.gradle中添加Android插件?

问题描述 投票:0回答:2

android/app/build.gradle
中,没有“plugins {}”块。相反,有一些“应用插件”:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

现在,我想添加另一个Android插件,我该怎么做?我尝试编写“plugins {}”块,但这不起作用。我也尝试过

apply plugin: 'my.plugin.name'
,但这也会导致错误。

有没有办法可以将自定义 Android 插件添加到 Flutter 项目中?

这就是我想要的:我的项目中需要适用于 Android 的 google 地图 SDK,这需要这个插件:

'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'

我知道谷歌地图上有一个flutter包,但它不支持热图,所以我必须使用原生。

android flutter gradle plugins
2个回答
0
投票

它们的书写方式相同。编写 apply plugin:'PUT-YOUR-PLUGIN-HERE" 并避免在插件之前放置 'id'


0
投票

最近flutter改变Gradle结构。现在您可以在 setting.gradle 文件中添加您的插件

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    plugins {
        id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
        **// Add your plugin here.**
    }
}

include ":app"

apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle"
© www.soinside.com 2019 - 2024. All rights reserved.