Flutter 构建 APK 导致“找不到资源 android:attr/fontVariationSettings”

如何解决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 中打开以供编辑

enter image description here

步骤 02:Android Studio 的新窗口打开后。让 Gradle Build 完成。完成后,转到 Android Studio 顶部的 Build 选项卡

enter image description here

第 03 步:它将打开一个对话框,您将弄清楚下一步要做什么。真是方便又简单的方法。

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res