构建Flutter应用/APK时遇attr/scaleType资源重复定义错误求助
Flutter构建APK时资源重复定义错误排查求助
构建APK或运行Flutter应用时持续遇到资源重复定义错误,提示Duplicate value for resource 'attr/scaleType' with config 'DEFAULT' and product '',该属性在jetified-ui_legacy-9.2.1和jetified-camera-view-1.2.3库中重复定义。项目未主动引入任何相机相关库,尝试更换多个Kotlin版本仍无法解决,以下是相关配置信息,请求协助排查:
报错日志
/Users/username/.gradle/caches/transforms-3/cf10bc8dfd22519fd63f47c2693208ec/transformed/jetified-ui_legacy-9.2.1/res/values/values.xml:890:4: Duplicate value for resource 'attr/scaleType' with config 'DEFAULT' and product ''. Resource was previously defined here: /Users/username/.gradle/caches/transforms-3/30f3f4898430fda189929c76ff99a8c3/transformed/jetified-camera-view-1.2.3/res/values/values.xml:6:4: . FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mergeReleaseResources'. > A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable > Resource compilation failed. Check logs for details.
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" apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' android { compileSdkVersion 33 compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.xxx.xxx" minSdkVersion 21 targetSdkVersion 33 versionCode 16 versionName '2.1.9' } 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.debug minifyEnabled false shrinkResources false } } buildToolsVersion '29.0.3' } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation platform('com.google.firebase:firebase-bom:26.6.0') implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.mercadopago.android.px:checkout:4.+' implementation('com.braintreepayments.api:drop-in:5.2.1'){ exclude group: "org.jfrog.cardinalcommerce.gradle", module: "cardinalmobilesdk" } implementation("org.jfrog.cardinalcommerce.gradle:cardinalmobilesdk:2.2.7-2") }
项目根目录build.gradle配置
buildscript { ext.kotlin_version = '1.8.0' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.15' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1' } } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } tasks.register("clean", Delete) { delete rootProject.buildDir }
gradle-wrapper.properties中distributionUrl配置
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
内容的提问来源于stack exchange,提问作者Jay
相关产品推荐
相关产品推荐

