如果我在构建中设置compileSdkVersion 33
。Gradle,没事的。但这是硬代码,所以我试着在local.properties
文件中设置它。
由于我已经在该文件中设置了flutter.minSdkVersion=23
,我认为flutter.compileSdkVersion=33
的工作原理相同,但它不是。
细节:
本地。属性文件:
flutter.compileSdkVersion=33
构建。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
是否有办法在本地设置compileSdkVersion。属性文件吗?
我可以使用local设置它。
// in YourProject/android/app/build.gradle
...
android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
...
}
android {
compileSdkVersion flutter.compileSdkVersion
...
最初由Maldus在这里回答