Reputation: 530
I'm working on an android application for about 2 months. Almost each time I created custom drawable when I tried to build project I got Android resource linking failed error and after that the name of drawables that couldn't located by android studio.
My solution was that I moved those drawables somewhere out of my project and rebuild the the app after getting error I moved drawables again back to my project and when I rebuild my APK
there was no error anymore and I could build, run, even generate APK
and those drawables worked perfectly fine. But now that my project finished I want generate signed apk but there is no way that I can get rid of Android resource linking failed error.
I put some of my drawables codes below.
retry_btn.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/register_btn_disabled"/>
<item android:state_pressed="true" android:drawable="@drawable/register_btn_clicked"/>
<item android:state_pressed="false" android:drawable="@drawable/register_btn_normal"/>
<item android:drawable="@drawable/register_btn_normal"/>
</selector>
story_box.xml
:
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#70707070" android:width="1dp"/>
</shape>
table_border.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#333333" />
<solid android:color="#EEEEEE" />
</shape>
</item>
</layer-list>
All the drawables are available in my project but I get this output when I try to generate signed apk:
Android resource linking failed
Output: C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_main.xml:51: error: resource drawable/search (aka uk.MyAppName.www.MyAppName:drawable/search) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_movie.xml:234: error: resource drawable/story_box (aka uk.MyAppName.www.MyAppName:drawable/story_box) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_no_internet.xml:49: error: resource drawable/retry_btn (aka uk.MyAppName.www.MyAppName:drawable/retry_btn) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_register.xml:205: error: resource drawable/register_btn (aka uk.MyAppName.www.MyAppName:drawable/register_btn) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_register.xml:215: error: resource drawable/register_btn (aka uk.MyAppName.www.MyAppName:drawable/register_btn) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\activity_search.xml:39: error: resource drawable/search (aka uk.MyAppName.www.MyAppName:drawable/search) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\search_table_item.xml:2: error: resource drawable/table_border (aka uk.MyAppName.www.MyAppName:drawable/table_border) not found.
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\src\main\res\layout\table_item.xml:2: error: resource drawable/table_border (aka uk.MyAppName.www.MyAppName:drawable/table_border) not found.
error: failed linking file resources.Command: C:\Users\MyUser.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\ac5e520165d725772f5386c054776ce5\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
C:\Users\MyUser\AppData\Local\Android\Sdk\platforms\android-28\android.jar\
--manifest\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\merged_manifests\release\processReleaseManifest\merged\AndroidManifest.xml\
-o\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\processed_res\release\processReleaseResources\out\resources-release.ap_\
-R\
@C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\incremental\processReleaseResources\resources-list-for-resources-release.ap_.txt\
--auto-add-overlay\
--java\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\generated\not_namespaced_r_class_sources\release\processReleaseResources\r\
--proguard\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\proguard-rules\release\aapt_rules.txt\
--custom-package\
uk.MyAppName.www.MyAppName\
-0\
apk\
--output-text-symbols\
C:\Users\MyUser\AndroidStudioProjects\MyAppName\app\build\intermediates\symbols\release\R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
this is my gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "uk.MyAppName.www.MyAppName"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'org.jetbrains.anko:anko-commons:0.10.4'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.android.exoplayer:exoplayer:2.9.1'
}
Upvotes: 22
Views: 28032
Reputation: 909
Tried all solutions, what worked for me was
Thank me later
Note: This is a temporary solution for this problem, You will have to repeat this process whenever you're hit with this error.
Upvotes: 0
Reputation: 326
To fix this issue, In android studio I had to change my build variant from debug to release and then the error became very obvious. I had to then add a new Image resource for the release variant and it fixed my issue. In my android studio layout, the build variants was bottom left, below bookmarks.
Upvotes: 0
Reputation: 1245
If you're building a release of your app, make sure that the res
files that are not found
are not in the debug
folder. You can check it by opening your files in the Project
view instead of Android
view.
Upvotes: 3
Reputation: 391
For React Native only
I mistakenly put the splash screen folders in the wrong folder.
Wrong path
/android/app/src/main/res/drawable
Correct path
/android/app/src/main/res
Also, I needed below all folders all with lauch_screen.png file
Upvotes: 0
Reputation: 1
Just change the project structure from app to project_files then goto drawable folder where you created that file which was invisible and delete that problem solved :)
Upvotes: 0
Reputation: 778
There could me some possible reasons what worked for me is.
1.-> <?xml version="1.0" encoding="utf-8"?>
you may have written it twice. which was not in my case.
2.-> I copied the same file in drawable-v24 and it worked for me.
Upvotes: 0
Reputation: 3358
In some situations, it has nothing to do with renaming the drawables.
Re-check the last drawable/xml file you worked on, which is likely the culprit.
I mistakenly had 2 root tags <?xml version="1.0" encoding="utf-8"?>
at the top
Upvotes: 9
Reputation: 767
In my case in the xml it used "@android:drawable/"
instead of "@drawable/"
. Changing to "@drawable/"
allowed Android Studio find my file.
Upvotes: 4
Reputation: 1323
To me the problem arise when inserting a new Image Vector asset from the android library.
It was an asset that I already had in my folder: a save icon, so I named it differently.
I'm used to have standard values for all my assets, so I ctrl + C, ctrl + V these values on to the new created asset, they only include color and size, something like this:
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#718792"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
I always leave the path untouched.
After deleting this asset everything came back to normal.
Case in point of how one should never go full throttle writing code without testing every line inserted (pretty much like the Pavlovian response to ctrl+G in AutoCad for those who know it),... I'm not to even exaggerating.
Upvotes: 0
Reputation: 409
I have faced the same issue.Just create a new drawable folder with your sdk version like (drawable-24) and paste your drawables there and re-build the project.
Upvotes: 3
Reputation: 359
this looks like an similar error ive encountered
using the Analyse -> inspect code ...
tool showed the error in the log
please look here for an full explenation
Upvotes: 3
Reputation: 385
Something that worked for me with a similar problem was delete the reference to the drawable's ID and then use Android Studio's autocomplete to restore it.
Upvotes: 0
Reputation: 530
To all who face this problem just change your drawable folder to drawable-v(your sdk version) hope this answer solve your problems. Or add another drawable directory with the name mentioned and simply copy your drawable files there.
Upvotes: 15
Reputation: 29
Remove shrinkResources
if you are using it in gradle file. Also it can happen when proguard
was enabled
Upvotes: 2
Reputation: 65
look for your gradel file and make sure that the application id is the same as the package of the mainfest file in package attribute
Upvotes: 0