Flutter兼容性问题:Could not get unknown property ‘flutter‘ for extension ‘android‘
项目背景
部们有两个项目,一个原生项目,一个Flutter项目,现在要把Flutter项目融入进来,于是技术选型是采用原生+Flutter混编方式,因为Flutter项目用了第三方插件gal,于是引入进来以后报错了:
Build file 'C:\Users\ws\AppData\Local\Pub\Cache\hosted\pub.dev\gal-2.3.2\android\build.gradle' line: 18A problem occurred evaluating project ':gal'.
> Could not get unknown property 'flutter' for extension 'android' of type com.android.build.gradle.LibraryExtension.* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
解决方案
在宿主工程根目录下的build.gradle文件(不是.android/build.gradle文件)加入如下代码:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {dependencies {classpath 'com.android.tools.build:gradle:8.12.0'}
}plugins {id 'com.android.application' version '8.10.0' apply falseid 'com.android.library' version '8.10.0' apply falseid 'org.jetbrains.kotlin.android' version '2.1.0' apply falseid "org.jetbrains.kotlin.kapt" version "2.1.0" apply falseid "com.google.gms.google-services" version '4.3.15' apply falseid "com.google.firebase.crashlytics" version '2.9.5' apply falseid "com.google.firebase.firebase-perf" version "1.4.2" apply falseid "io.github.JailedBird.ARouterPlugin" version('1.0.2') apply falseid "com.huawei.agconnect" version('1.9.1.301') apply false//    id "com.alibaba" version('1.0.2') apply false
//    id "com.sensorsdata.analytics.android" version '3.5.2' apply false
}// 解决gal插件报错:
// A problem occurred evaluating project ':gal'.
//> Could not get unknown property 'flutter' for extension 'android' of type com.android.build.gradle.LibraryExtension.
ext.flutter = [compileSdkVersion: 35,minSdkVersion    : 24,targetSdkVersion : 35,ndkVersion       : "27.0.12077973"
]apply from: 'config.gradle'subprojects {...
}
感谢大家的支持,如有错误请指正,如需转载请标明原文出处!
