【发布时间】: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