I have recently done some major refactoring to my android studio project as it gets closer and closer to an actual release. Anyways, I have about 6 menu resource files that all have the header
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
that build with my project fine. After coming back and adding 3 new menu resource files (it's a large project) I am getting this error:
Error:(10) No resource identifier found for attribute 'shows action' in package 'com.codemine.pcpartpicker
This only happens with the newly added menu resource files, Gradle still builds if I remove this and only have the old ones, what makes this even stranger is that the error reports there is no package in
com.codemine.pcpartpicker
when my projects package is
com.codemine.unofficial.pcpartpicker
Here is my manifest as I have some suspicion that the problem lies there...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.codemine.unofficial.pcpartpicker">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CPUActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CPUCoolerActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".MotherboardActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".MemoryActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".GpuActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".StorageActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CaseActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".PowerActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".MonitorActivity"
android:parentActivityName=".MainActivity" />
</application>
</manifest>
Edit: Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId 'com.codemine.unofficial.pcpartpicker'
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//for cardView
//for jsoup, grabs dependency from maven central
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'org.jsoup:jsoup:1.7.2'
compile 'com.android.support:support-core-utils:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
testCompile 'junit:junit:4.12'
}
Previous similar questions have been answered on Stack Exchange by suggesting the minSDKVersion must be over 11 for showsaction, but I see yours is set to 15. See:
error:no resource identifier found for attribute"showAsAction" in package android
Having said that, given you have done a major refactor, perhaps it is pointing to an old build.gradle with lower minSDKVersion in someway. In similar situations with an IDE I have found a rebuild can help. Perhaps worth a try. Good luck.
This has been an extremely frustrating error to fix, mostly because I was looking in the wrong place to fix it. It seems this happens after changing the project and adding new resource files (I only ran into trouble with menus, but im speculating it could happen with any resource files). It seems there is some error with the IDE/Gradle, where it seems to want to reference a version of the file in the previous package even though this package no longer exists. As you can see my java, manifest, menu etc is correct, the problem lies elsewhere.
The solution
I copied my resource files into n++ and deleted them from the project then performed a build>clean Project which should complete successfully after commenting out some lines. Then I deleted the menu resource files and added them back with different names, this is important . At this point do not paste your old code back into them . Add an Item without any attributes from xmlns:app="http://schemas.android.com/apk/res-auto"
, make sure the project builds succesfully and then add something from there and have android studio edit the namespace for you . Updating the namespace yourself will not do the trick, trust me I know.
This was a very niche but frusterating problem, hopefully no one else runs into it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.