flutter 版本升级问题
2022-06-24 本文已影响0人
职场过客
升级flutter版本到2.8.0,运行报错:
错误一:gradle\caches\transforms-2\files-2.1\1d0ad49d90f8984462d07510174740fe\core-1.7.0\res\values\values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.
具体代码
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Multiple task action failures occurred:
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.core:core-ktx:1.7.0.
AAR metadata file: C:\Users\.gradle\caches\transforms-2\files-2.1\bac36abaa397e24c797fa6fd6ff183e0\jetified-core-ktx-1.7.0\META-INF\com\android\build\gradle\aar-metadata.properties.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.core:core:1.7.0.
AAR metadata file: C:\lisir\.gradle\caches\transforms-2\files-2.1\e596bd84a87a4cbdcf9d545f7eacbd1e\core-1.7.0\META-INF\com\android\build\gradle\aar-metadata.properties.
* 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
解决方法一
compileSdkVersion 31
以及
defaultConfig {
applicationId "com.example.app"
minSdkVersion 23
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
解决方法二:网上说是,可以在工程中app/build.gradle中的dependencies上面添加以下代码解决:
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
}
}
感觉很麻烦
错误二:Duplicate class androidx.lifecycle.DefaultLifecycleObserver found in modules lifecycle-common-2.4.0.jar (androidx.lifecycle:lifecycle-common:2.4.0) and lifecycle-common-java8-2.2.0.jar (androidx.lifecycle:lifecycle-common-java8:2.2.0)
具体代码
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class androidx.lifecycle.DefaultLifecycleObserver found in modules lifecycle-common-2.4.0.jar (androidx.lifecycle:lifecycle-common:2.4.0) and lifecycle-common-java8-2.2.0.jar (androidx.lifecycle:lifecycle-common-java8:2.2.0)
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
* 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.gradle中添加依赖
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.lifecycle:lifecycle-common-java8:2.4.0'
}