【问题标题】:Gradle build error while importing project: "Error: The file name must end with .xml"导入项目时 Gradle 构建错误:“错误:文件名必须以 .xml 结尾”
【发布时间】:2018-08-04 22:08:31
【问题描述】:

我正在尝试在 Android Studio 中克隆我的朋友最近推送到 GitHub 的存储库。他在资源目录中放了一个 png 文件,当我尝试构建它时,控制台显示:

/.../app/src/main/res/picture100/empty.png: Error: The file name must end with .xml

我在谷歌上搜索了很多解决方案,但发现在大多数类似情况下,控制台消息显示“文件名必须以 .xml 或 .png 结尾”,所以请注意我的消息中有 没有“或 .png”,因为它只是 gradle 不允许在资源文件中使用的 png 文件。

我已与朋友确认我们使用的是同一版本的 Gradle(4.1) 和 Android Plugin(3.0.0)。

build.gralde:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.xyzhang.testapp"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

由于 gradle 构建失败,符号 R 将永远无法解析。它显示为红色。

如何解决这个问题?

【问题讨论】:

  • 您是否尝试删除该 picture100 文件夹并将您的 png 放入可绘制文件夹中?!我猜当你从版本控制中获得它时,表明该文件夹是资源文件夹的设置不会被更新甚至推送到 git。

标签: android android-studio gradle import build.gradle


【解决方案1】:
/.../app/src/main/res/picture100/empty.png: Error: The file name must end with .xml

好像您在 res 文件夹中创建了 picture100 文件夹。 Android 不允许您在 res 目录中创建此类文件夹。所以你必须删除它。

或者如果您希望继续使用 picture100 文件夹,那么您必须将 xml 文件放入此文件夹中。

您可以在 drawablemipmap 中使用图像文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-10
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 2015-08-12
    相关资源
    最近更新 更多