No resource identifier found for attribute 'parentActivityName' in package 'android'
Asked Answered
E

4

37

I'm trying to complete this tutorial from the Android Page http://developer.android.com/training/basics/firstapp/starting-activity.html But I Eclipse throws this error: "No resource identifier found for attribute 'parentActivityName' in package 'android'" I have included the android-support-library.

Here is the whole AndroidManifest.xml code

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.myfirstapp.DisplayMessageActivity"
        android:label="@string/title_activity_display_message" 
        android:parentActivityName="com.example.myfirstapp.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.myfirstapp.MainActivity" />
    </activity>
</application>

Edible answered 9/12, 2012 at 10:17 Comment(3)
possible duplicate of android:parentActivityName doesn't work although android-support-v4.jar is includedWenwenceslaus
I think the Android manual is a bit misleading. If you don't use min target 16, then of course the attribute "parentActivityName" won't compile. I think the answer should have been this: If min SDK < 16 : add the meta-data entry "android.support.PARENT_ACTIVITY". if min-sdk >= 16: add the attribute "parentActivityName". I don't see a reason to use them both simultaneously...Aurelio
You need to have the latest APIs so that it can be built against them. Make sure that you are targeting an API that is after 15.Wapiti
T
57

android:parentActivityName appears first in Android 4.1 (API level 16). You need to have the latest 4.1 SDK to compile this.

Tympan answered 9/12, 2012 at 10:22 Comment(7)
In this case will the app run on platforms under 4.1? (Sorry for beeing such a noob)Edible
If you include the 4.1 compatibility library in your APK and use android:minSdkVersion="11" then it will run on everything from API level 11 and later.Tympan
Then why does the tutorial explicitly state that unknown attributes are ignoredwhen compiling with lower APIs? Either your answer is not correct or there is a huge bug in android's sdk or the official tutorials are completely wrong about supporting older SDKs. Also note that the linked tutorial uses android:minSdkVersion="8", so there ought to be a way to may it work for APIs < 11.Waterborne
@Waterborne I looked at the linked tutorial. Nowhere did I see where it explicitly states that "unknown attributes are ignored when compiling with lower APIs". I can tell you from experience that unknown attributes aren't ignored when compiling, but they are ignored when installing/running on a device with lower APIs.Tympan
@Waterborne Anyway, the linked tutorial, in the discussion of android:parentActivityName explicitly says: "The system uses this value to implement default navigation behaviors, such as Up navigation on Android 4.1 (API level 16) and higher. You can provide the same navigation behaviors for older versions of Android by using the Support Library and adding the <meta-data> element as shown here." It also discusses the use of the compatibility library on API level < 16.Tympan
@DavidWasser How do I include the compatibility library?Capon
How come the library changes at times when I import my project into Eclipse?Capon
S
24

To add to David Wasser's answer, if you use Eclipse and have the correct SDK library installed but still have this error, it means that while the correct library is installed Eclipse does not use it for this project.

To change that, go to your project's Properties (right-click on its name in the Package Explorer and it's the last but one option), select Android in the left hand column and you should have a list called Project Build Target. Then:

  • Select the appropriate target (Android 4.2.2 or Google APIs for Platform 4.2.2 in this instance)

  • Save your Manifest file (make a trivial edit if necessary)

Once it is saved Eclipse will process it and those errors should disappear as Eclipse finds the resource identifier in its new build target.

Saltsman answered 13/4, 2013 at 12:47 Comment(1)
It's kind of weird that I had to make the trivial change and then save. I would never guess. Anyway, I add a space then delete it then save.Elephantine
D
1

This error will also happen if you don't have the exact version of the SDK that the sample app uses as it's build target. Following the same steps as Julien describes above and choosing an SDK you have locally will fix it.

Dionysus answered 11/4, 2014 at 5:0 Comment(0)
S
0

In IntelliJ IDEA, you need to change in Platform Settings->SDKs->Android something->Build target TO 4.1+.

If you don't see the option, you need an SDK version 4.1 or higher (API level 16+).

Shall answered 20/3, 2015 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.