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>

Tudor Ravoiu
  • 2,130
  • 8
  • 35
  • 56
  • possible duplicate of [android:parentActivityName doesn't work although android-support-v4.jar is included](http://stackoverflow.com/questions/14891032/androidparentactivityname-doesnt-work-although-android-support-v4-jar-is-inclu) – Mario Kutlev Jul 22 '13 at 09:01
  • 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... – Shoham Sep 16 '14 at 17:26
  • 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. – Tarik Jan 17 '15 at 15:38

4 Answers4

57

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

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • In this case will the app run on platforms under 4.1? (Sorry for beeing such a noob) – Tudor Ravoiu Dec 09 '12 at 10:29
  • 1
    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. – David Wasser Dec 09 '12 at 10:34
  • Then why does the [tutorial](http://developer.android.com/training/basics/firstapp/starting-activity.html) 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. – Bakuriu Jan 16 '13 at 10:43
  • @Bakuriu 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**. – David Wasser Jan 16 '13 at 11:39
  • 1
    @Bakuriu 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 element as shown here." It also discusses the use of the compatibility library on API level < 16. – David Wasser Jan 16 '13 at 11:39
  • @DavidWasser How do I include the compatibility library? – Si8 Aug 21 '13 at 16:47
  • How come the library changes at times when I import my project into Eclipse? – Si8 Aug 21 '13 at 16:55
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.

Julien Rousseau
  • 975
  • 1
  • 9
  • 15
  • 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. – Katedral Pillon Apr 30 '14 at 20:50
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.

vitriolix
  • 351
  • 3
  • 9
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+).

AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277