索引 40 处的非法字符 <:>:com.recognize.app-mergeDebugResources-33:/values/values.xml)

问题描述 投票:0回答:4

由于此错误,我无法编译我的应用程序

com.android.aaptcompiler.ResourceCompilationException:
Resource compilation failed
(Failed to compile values resource file C:\Users\hesam\AndroidStudioProjects\RecognizeProject\app\build\intermediates\incremental\debug\mergeDebugResources\merged.dir\values\values.xml. 
Cause: java.nio.file.InvalidPathException: Illegal char <:> at index 40: com.recognize.app-mergeDebugResources-33:/values/values.xml).

我不知道发生了什么事...

build.gradle(模块)

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    id 'com.google.firebase.firebase-perf'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.recognize"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:30.0.1')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-database'
    implementation 'com.google.firebase:firebase-storage'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-perf'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'io.github.yanndroid:oneui:2.4.0'
    implementation 'com.mikhaellopez:circularimageview:4.3.0'
    implementation 'com.github.bumptech.glide:glide:4.13.0'
    implementation 'io.github.chaosleung:pinview:1.4.4'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        classpath 'com.google.firebase:perf-plugin:1.4.1'
    }
}

plugins {
    id 'com.android.application' version '7.2.0' apply false
    id 'com.android.library' version '7.2.0' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我不知道我还应该在这里放什么其他信息。 有可能是因为某个图书馆的原因吗?

我最近添加了这个库(在添加这个库之前构建工作,但我添加了更多的东西,比如字符串到strings.xml,新的Java类,布局等),但我不知道这是否是它的错,因为在问题中GitHub 没人遇到这个问题....

java android gradle build.gradle aapt
4个回答
10
投票

我在开发库时面临同样的问题,经过几次尝试,我发现这与 attrs 有关。 库项目的 attrs.xml 文件中有一个属性“colorScheme”:

<declare-styleable name="GridColorPicker">
   <attr name="colorScheme" format="string" />
   <attr name="selectorColor" format="color" />
</declare-styleable>

但是在生成的 \merged.dir alues alues.xml 文件中搜索后,它里面还有另一个“colorScheme”:

<enum name="standard" value="0"/>
<enum name="wide" value="1"/>
<enum name="icon_only" value="2"/>
</attr>
<attr format="reference" name="colorScheme">
<enum name="dark" value="0"/>
<enum name="light" value="1"/>
<enum name="auto" value="2"/>

所以我将我的“colorScheme”更改为一种独特的,问题就解决了。

我认为您可以联系该库的作者或分叉该库并自己尝试这些步骤。


1
投票

我的 attrs.xml 文件是

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="state_error"  />   <======HERE WAS THE PROBLEM
    <declare-styleable name="ValueEditor">
       <attr name="nameShown" format="string"/>
       <... other definitions />
    </declare-styleable>
</resources>

名称为 state_error 的 attr 导致了问题。 一定是来自某些复制粘贴源代码,因为当我删除它时,问题就消失了。

问题发生在每个 实现 'com.google.android.material:material:1.6.0-alpha02' 比那个还大


0
投票

当我将属性命名为“字体”时,我得到了这个:

<declare-styleable name="Scale">
    <attr name="name" />
    <attr name="colour" />
    <attr name="direction" format="string" />
    <attr name="font" format="string" /> // **AARGH!
    <attr name="fontSize" format="float" />
    <attr name="every" format="float" />
    <attr name="radius" format="float" />
</declare-styleable>

将其重命名为 fontName 修复了它:

<attr name="fontName" format="string" /> // Nice

0
投票

我也刚刚遇到了这个问题。从所有搜索来看,它似乎最常出现在 attrs.xml 中

为了真正找到问题所在,请执行以下步骤。

  1. 备份您的 attrs.xml
  2. 清除它,所以只有:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
  1. 编译。如果您收到不同的错误,您可以肯定它是在 attrs 中。
  2. 将你的属性加回一半。例如。所有以 A-M 开头的属性
  3. 编译。如果错误再次出现,您就知道它位于上半部分。如果没有,它就在下半部分。
  4. 如果出现错误:删除一半的属性(比如 G-M)。如果您不添加额外的(例如 N-R)。
  5. 继续执行此操作,直到将范围缩小到添加一行导致问题的位置,然后将其删除即可解决问题。
  6. 重命名该属性。
© www.soinside.com 2019 - 2024. All rights reserved.