每次我尝试运行项目或尝试重建它时,都会抛出错误:链接资源失败。请参见屏幕截图:
所有的drawable仍然显示这一点。 并且我的java文件的所有R都是红色的,当悬停时它显示一条消息无法解析符号' R' 请参见屏幕截图:
我打开的每个java文件都会出现错误。
我尝试了无效缓存和清理项目但没有任何工作。到处搜索,但没有找到解决方案。
提前致谢!
编辑:build.gradle(模块:app)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
的build.gradle(项目:weMate)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.shivamtiwari.wemate"
minSdkVersion 17
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:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
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'
}
尝试gradlew assembleDebug后:
Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.
E:\MCA\AndroidProject\weMate>gradlew assembleDebug
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_account.xml:27: AAPT: error: resource drawable/uploaddisplay (aka com.shivamtiwari.wemate:drawable/uploaddisplay) not fo
und.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:9: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not fo
und.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:21: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:33: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:51: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool.xml:64: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not f
ound.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_car_pool_list.xml:8: AAPT: error: resource drawable/list_row_selector (aka com.shivamtiwari.wemate:drawable/list_row_sel
ector) not found.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_helpdesk.xml:8: AAPT: error: resource drawable/search_bar_bg (aka com.shivamtiwari.wemate:drawable/search_bar_bg) not fo
und.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\fragment_shop_list.xml:8: AAPT: error: resource drawable/list_row_selector (aka com.shivamtiwari.wemate:drawable/list_row_selecto
r) not found.
E:\MCA\AndroidProject\weMate\app\src\main\res\layout\nav_header_main.xml:2: AAPT: error: resource drawable/side_nav_bar (aka com.shivamtiwari.wemate:drawable/side_nav_bar) not found.
error: failed linking file resources.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to process resources, see aapt output above for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s
13 actionable tasks: 1 executed, 12 up-to-date
答案 0 :(得分:0)
就我而言,将资源文件从“全局可绘制”文件夹移动到特定的可绘制文件夹后,问题解决了。
例如: 如果您的资源文件在以下路径中
/drawable/btn_bg.xml
然后将其移至
/drawable-hdpi/btn_bg.xml
将解决问题。
同样,任何图像文件,
例如: 如果您的资源文件在以下路径中
/drawable/welcome_illustration.png
然后将其移至
/drawable-hdpi/welcome_illustration.png