如何解决Flutter 构建 APK 导致“找不到资源 android:attr/fontVariationSettings”
我正在尝试使用 Android Studio 在 Flutter 中创建签名的 APK,理论上我已经准备好创建签名的 APK“https://flutter.dev/docs/deployment/android”的所有步骤,但是出现错误总是弹出来阻止创建 apk。
C:\Users\CryptoBrain\Desktop\app-Flutter\my_app>flutter build apk
You are building a fat APK that includes binaries for android-arm,android-arm64,android-x64.
If you are deploying the app to the Play Store,it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle,run:
flutter build appbundle --target-platform android-arm,android-x64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI,run:
flutter build apk --target-platform android-arm,android-x64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Running Gradle task 'assembleRelease'...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':clipboard_manager:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> 1 exception was raised by workers:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
C:\Users\CryptoBrain\.gradle\caches\transforms-2\files-2.1\6c261a14fef7a6c9650e745991e1078b\core-1.1.0\res\values\values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVar
iationSettings not found.
C:\Users\CryptoBrain\.gradle\caches\transforms-2\files-2.1\6c261a14fef7a6c9650e745991e1078b\core-1.1.0\res\values\values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcInde
x 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
BUILD FAILED in 10m 59s
Running Gradle task 'assembleRelease'... 665,6s (!)
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin clipboard_manager...
Running Gradle task 'assembleAarRelease'... 59,7s
√ Built build\app\outputs\repo.
Building plugin majascan...
Running Gradle task 'assembleAarRelease'... 36,6s
√ Built build\app\outputs\repo.
Building plugin shared_preferences...
Running Gradle task 'assembleAarRelease'... 1,4s
Exception in thread "main" java.lang.NullPointerException
at org.gradle.wrapper.BootstrapMainStarter.findLauncherJar(BootstrapMainStarter.java:34)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:25)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
The plugin shared_preferences could not be built due to the issue above.
C:\Users\CryptoBrain\Desktop\app-Flutter\my_app>
我已经尝试使用不同版本的 clipboard_manager 有 4 个,但它们都给出了相同的错误。
还将 com.android.tools.build:gradle:3.5.0 更改为 com.android.tools.build:gradle:3.6.1 和我在的 distributionUrl:https://services.gradle.org /distributions/gradle-5.6.4-all.zip
这是我使用的代码:
pubspec.yaml
name: app_name
description: my flutter app
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
flutter_screenutil: ^0.5.3
carousel_pro: ^0.0.13
flutter_sparkline: ^0.1.0
font_awesome_flutter: ^8.4.0
shimmer: ^0.0.6
rxdart: ^0.21.0
bmnav: ^0.3.4
carousel_slider: ^1.3.0
percent_indicator: ^1.0.15
flutter_spinkit: ^4.1.1+1
http: 0.12.0+4
shared_preferences: ^0.5.12+4
pin_code_fields: ^3.0.0
url_launcher: ^5.4.5
provider: ^4.0.1
clipboard_manager: ^0.0.4
aes_crypt: ^0.1.1
mvc_pattern: ^5.1.1
encrypt: any
majascan: ^0.3.7
flutter_launcher_icons: ^0.7.5
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file,see the
# following page: https://dart.dev/tools/pub/pubspec
flutter_icons:
image_path: "assets/image/logo.png"
ios: true
android: true
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application,so that you can use the icons in
# the material Icons class.
uses-material-design: true
fonts:
- family: gainers
fonts:
- asset: assets/icon/ic_gainers.ttf
- family: message
fonts:
- asset: assets/icon/ic_message.ttf
- family: tab
fonts:
- asset: assets/icon/ic_tab.ttf
- family: wallet
fonts:
- asset: assets/icon/ic_wallet.ttf
- family: tab1
fonts:
- asset: assets/icon/ic_tab1.ttf
- family: tab2
fonts:
- asset: assets/icon/ic_tab2.ttf
- family: tab3
fonts:
- asset: assets/icon/ic_tab3.ttf
- family: tab4
fonts:
- asset: assets/icon/ic_tab4.ttf
- family: tab5
fonts:
- asset: assets/icon/ic_tab5.ttf
- family: loser
fonts:
- asset: assets/icon/ic_loser.ttf
- family: Sans
fonts:
- asset: assets/font/OpenSans-Bold.ttf
weight: 800
- asset: assets/font/OpenSans-Semibold.ttf
weight: 600
- asset: assets/font/OpenSans-Regular.ttf
weight: 400
- asset: assets/font/OpenSans-Light.ttf
weight: 200
- family : Popins
fonts:
- asset: assets/font/Poppins-Regular.ttf
weight: 400
- asset: assets/font/Poppins-SemiBold.ttf
weight : 600
- family : Berlin
fonts:
- asset: assets/font/BRLNSDB.TTF
weight: 700
- family : Lemon
fonts:
- asset: assets/font/Lemon-Regular.ttf
weight: 400
- family : Gotik
fonts:
- asset: assets/font/GOTHIC.TTF
weight: 400
- asset: assets/font/GOTHICB.TTF
weight : 600
- family : Pragmatica
fonts:
- asset: assets/font/pragmatica_bold.ttf
weight: 500
assets:
- assets/font/BRLNSDB.TTF
- assets/font/GOTHIC.TTF
- assets/font/GOTHICB.TTF
- assets/font/Lemon-Regular.ttf
- assets/font/OpenSans-Bold.ttf
- assets/font/OpenSans-Light.ttf
- assets/font/OpenSans-Regular.ttf
- assets/font/OpenSans-Semibold.ttf
- assets/font/Poppins-Regular.ttf
- assets/font/Poppins-SemiBold.ttf
- assets/font/pragmatica-bold.ttf
- assets/font/pragmatica.ttf
- assets/font/pragmatica_bold.ttf
- assets/icon/ic_gainers.ttf
- assets/icon/ic_loser.ttf
- assets/icon/ic_message.ttf
- assets/icon/ic_tab.ttf
- assets/icon/ic_tab1.ttf
- assets/icon/ic_tab2.ttf
- assets/icon/ic_tab3.ttf
- assets/icon/ic_tab4.ttf
- assets/icon/ic_tab5.ttf
- assets/icon/ic_wallet.ttf
- assets/image/
- assets/image/market/
- assets/image/logo.png
# To add assets to your application,add an assets section,like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants",see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies,see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application,add a fonts section here,# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name,and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,# see https://flutter.dev/custom-fonts/#from-packages
文件 app/build.gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.flutter.app"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now,so `flutter run --release` works.
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
文件 android/build.gradle
buildscript {
ext.kotlin_version = '1.4.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我该如何解决这个问题?
解决方法
在android/app/build.gradle里面配置下,解决问题
android{
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
}
,
我也遇到过这种错误,但我知道另一种方式。
步骤 01:在另一个 Android Studio 中打开您的 Flutter Android 应用。如果你不知道怎么做?只需在 flutter 应用程序的 android 部分打开 build.gradle
。然后在顶角,您会看到在 Android Studio 中打开以供编辑。
步骤 02:Android Studio 的新窗口打开后。让 Gradle Build 完成。完成后,转到 Android Studio 顶部的 Build 选项卡
第 03 步:它将打开一个对话框,您将弄清楚下一步要做什么。真是方便又简单的方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。