Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem] 如何使用 settings.gradle.kts 接入? #2137

Open
nesteiner opened this issue Sep 22, 2024 · 3 comments
Open

[Problem] 如何使用 settings.gradle.kts 接入? #2137

nesteiner opened this issue Sep 22, 2024 · 3 comments

Comments

@nesteiner
Copy link

在文档那里,接入部分

setBinding(new Binding([gradle: this]))
evaluate(new File(
        settingsDir.parentFile,
        'flutter_module/.android/include_flutter.groovy'
))
include ':flutter_module'
project(':flutter_module').projectDir = new File('../flutter_module')

这是 settings.gradle 的代码,但是我用的是 settings.gradle.kts ,我试着

val flutterModulePath = File(settingsDir.parentFile, "flutter_module/.android/include_flutter.groovy")
apply {
    from(flutterModulePath)
}

可是我发现 kts 无法 evaluate groovy 文件,这可怎么办呐

@jiyuren
Copy link

jiyuren commented Sep 24, 2024

可以把这些代码写到一个单独的build-flutter.gradle 文件里,然后引用它试试, apply(from = "build-flutter.gradle")

@fanpeihua
Copy link

可以把这些代码写到一个单独的build-flutter.gradle 文件里,然后引用它试试, apply(from = "build-flutter.gradle")

这个方式的确可以解决

@nesteiner
Copy link
Author

额,出了点小问题,他说

A problem occurred evaluating script.
> Could not find method include() for arguments [:flutter] on build of type org.gradle.invocation.DefaultGradle.

然后这是自动生成的 include_flutter.groovy,我把它粘贴到 build-flutter.gradle 中了

def scriptFile = getClass().protectionDomain.codeSource.location.toURI()
def flutterProjectRoot = new File(scriptFile).parentFile.parentFile

gradle.include ":flutter"
gradle.project(":flutter").projectDir = new File(flutterProjectRoot, ".android/Flutter")

def localPropertiesFile = new File(flutterProjectRoot, ".android/local.properties")
def properties = new Properties()

assert localPropertiesFile.exists(), "❗️The Flutter module doesn't have a `$localPropertiesFile` file." +
        "\nYou must run `flutter pub get` in `$flutterProjectRoot`."
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
gradle.apply from: "$flutterSdkPath/packages/flutter_tools/gradle/module_plugin_loader.gradle"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants