【问题标题】:Android resource compilation failed: inner element must either be a resource reference or emptyAndroid资源编译失败:内部元素必须是资源引用或为空
【发布时间】:2018-11-18 19:43:12
【问题描述】:

我在编辑我的 gradle 文件后尝试同步时不断收到此错误:

Android 资源编译失败输出: C:\Users\user\Desktop\Git\app_name\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:797: 错误:内部元素必须是资源引用或 空。

下面是我编辑的gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "app_id"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 2
        versionName "0.1.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    jcenter()
    maven {
        url "https://jitpack.io"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.facebook.stetho:stetho:1.5.0'
    implementation 'com.facebook.stetho:stetho-js-rhino:1.3.1'

    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    implementation "android.arch.persistence.room:runtime:1.1.1"

    implementation 'com.google.firebase:firebase-database:16.0.5'

    annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

apply plugin: 'com.google.gms.google-services'

我已尝试清理、失效和重新启动以及删除构建文件夹

【问题讨论】:

  • 看起来您在 values.xml 的某处有一个 <item></item> 元素,其标签之间的值无效。

标签: android android-gradle-plugin


【解决方案1】:

错误信息说明了一切:

values.xml:797:错误:内部元素必须是资源 参考或空。

编译问题与您的资源文件values.xml 有关。此文件的资源值无效。


请查看此安卓resources guide

【讨论】:

    【解决方案2】:

    当我升级我的 android studio 和其他东西时,我遇到了那个错误。我搜索了很多,终于找到了。只是我不得不更改值中的 id

    <item name="name" type="id">ID</item>
    

    <item name="ID" type="id"/>
    

    在那之后一切都成真了,我希望它对你有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-11
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多