![](/img/trans.png)
[英]AAPT: error: resource drawable/example (aka com.app:drawable/example) not found
[英]AAPT error: resource drawable/... not found
最近升級我的 android 工作室后,我無法再構建我的項目了。
每次執行構建時,我都會遇到以下錯誤:
error: resource drawable/splash_screen (aka com.whereisthemonkey.nowalism:drawable/splash_screen) not found.
Message{kind=ERROR, text=error: resource drawable/splash_screen (aka com.whereisthemonkey.nowalism:drawable/splash_screen) not found., sources=[C:\Users\Lucas\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\cf575568f869a44c685b16e47de83a28\res\values\values.xml:1632:5-84], original message=, tool name=Optional.of(AAPT)}
此錯誤仍然存在,即使文件 splash_screen.xml 存在於 drawable 文件夾下。
重建、清理項目和使緩存無效都不起作用!
添加行 android.enableAapt2=false 並不能解決真正的問題,因此我寧願找到問題的根源。
下面顯示了我的 gradle.build 文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'//https://github.com/bumptech/glide/issues/1939
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.whereisthemonkey.nowalism"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
// Keep the following configuration in order to target Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
res.srcDirs += [
'src/main/res-backgrounds',
'src/main/res-jobs',
]
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
//Do not update due to dex error
implementation 'org.apache.commons:commons-lang3:3.6'
//Do not update due to dex error
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.android.gms:play-services:11.8.0'
implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
implementation 'com.amitshekhar.android:android-networking:1.0.1'
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'
implementation 'com.github.ome450901:SimpleRatingBar:1.4.1'
implementation 'com.sothree.slidinguppanel:library:3.4.0'
implementation 'com.github.esafirm.android-image-picker:imagepicker:1.12.0'
//Do not update due to dex error
implementation 'com.theartofdev.edmodo:android-image-cropper:2.5.1'
implementation 'com.github.bumptech.glide:glide:4.6.1'
kapt 'com.github.bumptech.glide:compiler:4.6.1'//https://github.com/bumptech/glide/issues/1939
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'de.hdodenhof:circleimageview:2.2.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'
implementation 'com.firebaseui:firebase-ui-auth:3.2.1'
implementation 'com.android.support:support-v4:27.1.1'
}
apply plugin: 'com.google.gms.google-services'
感謝您的幫助。
在我的例子中,它是一個 xml 選擇器。 在第一行中,我有兩個(感謝在我的文件中復制粘貼):
<?xml version="1.0" encoding="utf-8"?>
並且 Android Studio 沒有給出任何警告之類的。 刪除它解決了問題,但之后需要一個完整的干凈構建。
我修復了錯誤,它可能來自格式錯誤的復制 XML 文件(可能是一些行尾混淆)
重寫這些修復了錯誤,盡管 Android Studio 顯示了另一個文件作為問題的根源,這實際上與錯誤本身無關。
就我而言,我刪除了重復的命名空間聲明,例如xmlns:android="http://schemas.android.com/apk/res/android"
我使用分析->檢查代碼工具在日志中顯示錯誤,然后我解決了可繪制資源中其他文件xml中的錯誤。
我遇到了同樣的問題,最后解決了這個問題
分析>檢查代碼
我的應用程序在其中一個 XML 文件中缺少結束標記 Just Try Analyze > Inspect Code它會將您重定向到確切的錯誤。
就我而言,我喜歡這樣: <?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
所以我只刪除其中一個
檢查您的每一個 XML,也許您會發現以下情況。
在處理其他項目的代碼或文件時,您可能忘記添加一些資源,例如可繪制對象、字符串。
檢查每個可繪制文件,當您打開該文件時, Android Studio可能會突出顯示。
有時我們必須找到這種類型的錯誤,因為 Android Studio 卡住了錯誤。
我遇到了同樣的問題,當我將可繪制文件中的圖標添加到 24dp 時,我解決了這個問題。
復制您想要的任何圖標並將其粘貼到可繪制文件中,它將創建(默認情況下)24dp 圖標。
就我而言,它是重復的:
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
在可繪制的資源文件中
在我的情況下,它是格式錯誤的 splash_screen.xml,它是“還原提交”的一部分,它實際上刪除了這個文件,但不知何故,它仍然可能是在活動的更改列表中。
修復了該文件並解決了問題。
就我而言,它是一個可繪制資源文件,需要更高的 API 版本,因為它是我在 build.gradle 中設置的 minSdkVersion。 主要問題是文件在您打開它之前沒有顯示任何錯誤,因此很難找到它。 我花了至少 4 個小時嘗試其他事情,因為在構建項目時出現錯誤,它顯示了其他完全沒有任何問題的可繪制資源文件。 刪除需要更高 API 的可繪制對象后,應用程序正常構建。
就我而言,問題是代碼沖突,其他人與我更改了同一個文件。 資源代碼已更改。 當我修復文件時,問題就消失了。
在我的情況下:有一個我沒有在可繪制文件中創建的文件,這個文件是空的,我只是刪除了它,程序開始了
如果您已將自己的圖標放在一起准備在商店發布,請確保不要在 xml 文件中包含圖標的擴展名。 它總是會失敗。 在我的情況下是這個..
<bitmap android:gravity="center" android:src="@drawable/myAppSplashLogo.png"/>
正確的做法是刪除 .png 擴展名。
<bitmap android:gravity="center" android:src="@drawable/myAppSplashLogo"/>
就我而言,我制作了所有調試分類的可繪制文件,並且必須返回 go 並制作等效的發布分類。 這樣做之后,它在第一次嘗試時就成功了。
我在構建我的應用程序的發布版本時遇到了同樣的問題,問題是我在debug
目錄中有我的項目的一些重要的res
文件,而不是在release
目錄中,所以我通過移動文件來解決問題debug
inside release
您可以通過查看項目下的project
樹而不是android
來檢查它
在復制和粘貼代碼的同時,我還粘貼了以下行
<?xml version="1.0" encoding="utf-8"?>
因為,我的 xml 文件已經包含上面的行,並且在添加這一行時它出現了兩次。
所以我刪除了其中一行,它解決了我的錯誤
就我而言,我使用了對 android 資源文件的錯誤引用,即android:color/splash_bg
而不是@color/splash_bg
其中splash_bg
代表我在 res/values/colors.xml 文件中聲明的自定義顏色資源。
就我而言,我不得不從 splash_screen.xml 中刪除android:src="@drawable/background"
和android:src="@drawable/logo"
行,盡管錯誤最初指向 AndroidManifest.xml。
就像第一篇文章說的那樣,確保<?xml version="1.0" encoding="utf-8"?>
在所有 xml 文件中都是正確的。
就我而言,我刪除了“drawable”文件夾
我在@Lucas Romier 也提到的錯誤(我認為)中沒有提到的xml(矢量)文件之一中重新格式化了代碼(因為我沒有發現錯誤),但是文件名帶有紅色下划線,它建議然后清理構建,然后它就起作用了。 :)
對我來說,問題是我拼錯了drawable-mdpi
、 drawable-hdpi
等的名稱(我將它們寫為dawable-mdpi
等)
在我的情況下File > Invalidate Caches
, Build > Rebuild Project
,刪除.gradle
文件夾沒有幫助。 所以我刪除了包含沖突文件的文件夾res\mipmap-anydpi-v26
。
我遇到過同樣的問題。 通過手動添加解決了
dependencies {
...
implementation project(':react-native-splash-screen')
}
即使在與 react-native 鏈接之后。 還添加了
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this); // Added this
super.onCreate(savedInstanceState);
}
我遇到了同樣的問題,我注意到在調試代碼時它工作得很好但是在發布期間錯誤會持續存在。
如果您遇到同樣的問題,請不要擔心,這意味着圖像已保存在調試模式下,並將問題 go 修復到FILE - NEW - IMAGE ASSET (不要更改任何內容,只需單擊您看到的頂部的下一步) res 目錄將其從DEBUG更改為MAIN 。 您的圖像資產現在可以在發布和調試模式下使用。
大多數時候,當您將任何類型的可繪制對象直接復制並粘貼到您的項目到 Android Studio 時,它存儲在調試可繪制對象中,只需通過文件資源管理器從調試資源移動到主要資源。
從\app\src\debug\res\drawable
到\app\src\main\res\drawable
1 - Go 到 app 文件夾並刪除 build 文件夾
2 - 單擊文件 -> 無效緩存 - 無效並重新啟動
從另一個項目中復制“res”文件夾(res 文件夾在哪里 - android/app/src/main)粘貼您自己的項目。 重新運行。
復制drawable文件夾所有文件並粘貼drawable_v24文件夾你自己的項目。 重新運行。 我希望這是工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.