解决Flutter 打包提示Android resource linking failed 、attr/fontVariationSettings not found、attr/ttcIndex not found的问题
代码写完了,用安卓真机可以直接调试,但是执行flutter build apk -t lib/main_prod.dart 的时候,提示如下信息
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':adhara_socket_io:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/Users/**/.gradle/caches/transforms-2/files-2.1/8b6ccf1247153bdb61a5468cf8f65720/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/Users/**/.gradle/caches/transforms-2/files-2.1/8b6ccf1247153bdb61a5468cf8f65720/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex not found.
* 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
……………这里是分割线……………
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':generateReleaseRFile'.
> This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
The following AndroidX dependencies are detected: androidx.annotation:annotation:1.1.0
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':javaPreCompileRelease'.
> This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
The following AndroidX dependencies are detected: androidx.annotation:annotation:1.1.0
* 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
原因分析:
看到Execution failed for task ‘:adhara_socket_io:verifyReleaseResources’. 。
根据提示信息,应该是adhara_socket_io这个插件的问题,找到这个这个查看,根据网上搜索的方法,应该是compileSdkVersion 的版本低于28
解决方案:
打开adhara_socket_io的build.gradle,找到 compileSdkVersion ,看到是27,直接改为28就好了: