【问题标题】:Flutter Android set compileSdkVersion in local.properties fileFlutter Android 在 local.properties 文件中设置 compileSdkVersion
【发布时间】:2022-08-09 02:56:40
【问题描述】:

如果我在 build.gradle 中设置compileSdkVersion 33,就可以了。 但它是一种硬代码,所以我尝试将它设置在local.properties 文件中。

由于我已经在该文件中设置了flutter.minSdkVersion=23,我认为flutter.compileSdkVersion=33 的工作方式相同,但事实并非如此。

细节:

local.properties 文件:

flutter.compileSdkVersion=33

build.gradle 文件:

def flutterCompileSdkVersion = localProperties.getProperty(\'flutter.compileSdkVersion\')
if (flutterCompileSdkVersion == null) {
    flutterCompileSdkVersion = flutter.compileSdkVersion
}

...

compileSdkVersion flutterCompileSdkVersion // error here
compileSdkVersion 33 // this works

错误信息:

FAILURE: Build failed with an exception.

* Where:
Script \'/Users/vietstone-ng/Library/flutter/packages/flutter_tools/gradle/flutter.gradle\' line: 461

* What went wrong:
A problem occurred evaluating root project \'android\'.
> A problem occurred configuring project \':app\'.
   > String index out of range: -6

* Try:
Run with --stacktrace option to get the stack trace. 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 FAILED in 785ms

无论如何要在 local.properties 文件中设置 compileSdkVersion 吗?

    标签: android flutter gradle


    【解决方案1】:

    我能够以这种方式使用 local.properties 设置它:

    // in YourProject/android/app/build.gradle
    ...
    android {  
        compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
        ...
    }
    

    以下没有工作

      android {
        compileSdkVersion flutter.compileSdkVersion
        ...
    

    最初由 Maldus here 回答

    【讨论】:

      猜你喜欢
      • 2022-08-24
      • 1970-01-01
      • 2019-12-02
      • 2022-06-22
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多