145

When I followed the instructions to add an ad into my app by xml, I got the following errors:

Description Resource Path Location Type
error: No resource identifier found for attribute 'adSize' in package 'com.google.example'  main.xml    /HelloWorld/res/layout  line 12 Android AAPT Problem
Description Resource Path Location Type
error: No resource identifier found for attribute 'adUnitId' in package 'com.google.example'    main.xml    /HelloWorld/res/layout  line 12 Android AAPT Problem

I did edit the main.xml, add attrs.xml file but the compiler didn't like it.

einverne
  • 6,454
  • 6
  • 45
  • 91
user584819
  • 1,509
  • 3
  • 12
  • 8

25 Answers25

300

Replace /res/ with /lib/ in your custom layout nampespace.

xmlns:android="http://schemas.android.com/apk/res/android"

in your case, would be:

xmlns:yourApp="http://schemas.android.com/apk/lib/com.yourAppPackege.yourClass"
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
M_AWADI
  • 4,086
  • 1
  • 18
  • 12
74

I had the same problem. I copied the example code from Google code, and could not compile.

xmlns:ads="http://schemas.android.com/apk/res/com.google.example"

Finally, I figured it out. The last part of the code "com.google.example", is their package name, so you need to replace it with your project package.

For example, my project package is "com.jms.AdmobExample", so my ads naming space is:

xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample"

Check my example, it works fine. You can download the APK to try. I also put my source code here: Add Google Admob in Android Application

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
James
  • 5,119
  • 5
  • 25
  • 27
  • 13
    Devs, if you are using your project package in xmlns:ads, then you also need to add 'attrs.xml' as explained by James in his link. For newer Admob sdk, attrs.xml is no longer recommended. Just use the following namespace: `xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"` – vivek.m Jan 22 '12 at 08:43
  • 8
    @vivek.m, thank you for pointing me the correct answer! Instead apk/res one MUST use apk/lib in case of 'apklib' project dependency. – se.solovyev Jun 08 '12 at 11:07
  • 4
    Thanks, I love internet, specially Stackoverflow.com – htafoya Jul 15 '13 at 06:24
  • Thanks a lot, after 3 hours of searching and debugging your answer finally popped up and fixed it. – Vlad Schnakovszki Sep 06 '13 at 13:47
  • @vivek.m thanks that is the answer that worked for me -- with the com.google.ads. – raddevus Aug 23 '16 at 14:40
42

for me, I have to add

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

right after:

xmlns:android="http://schemas.android.com/apk/res/android"

in res/layout/main.xml

Zennichimaro
  • 5,236
  • 6
  • 54
  • 78
27

You can also use http://schemas.android.com/apk/res-auto that would take care of it automatically. Use it like this:

xmlns:ads="http://schemas.android.com/apk/res-auto"
Bms270
  • 1,586
  • 15
  • 18
  • @Niklas: This is not a web page link. This is a URL to be used like this: xmlns:ads="http://schemas.android.com/apk/res-auto" which automatically resolves the resource URL. See my updated answer above. – Bms270 Jul 17 '14 at 19:50
8

I had the same problem, but while using a library project. The issue has been solved in r17: Instead of using the package's namespace:

xmlns:app="http://schemas.android.com/apk/res/hu.droidium.exercises"

One has to use a dummy namespace:

xmlns:app="http://schemas.android.com/apk/res-auto"

This will fix the problem of the attributes not being accessible from the referencing project.

Andras Balázs Lajtha
  • 2,576
  • 25
  • 32
8

i download the same custom-demo from Android.com and get the same complie problem.

at frist ,i change

xmlns:custom="http://schemas.android.com/apk/res/com.example.android.customviews"

to

xmlns:custom="http://schemas.android.com/apk/lib/com.example.android.customviews"

it work . then i get another solution

 xmlns:custom="http://schemas.android.com/apk/res-auto"

it also work, but there are some differencies. The second solution has prefect function . i am finding the reason , may be you can have a hand in. thanks

Davood Falahati
  • 1,474
  • 16
  • 34
Bill
  • 1,268
  • 14
  • 14
  • "http://schemas.android.com/apk/res-auto" add all the attributes defined in your project as well as defined in libraries you referanced in your project. therefore it works for you and its more cleaner approach – SAIR Sep 23 '16 at 09:25
3

As you specify in your attrs.xml your adSize attribute belongs to the namespace com.google.ads.AdView. Try to change:

android:adUnitId="a14bd6d2c63e055"         android:adSize="BANNER"

to

ads:adUnitId="a14bd6d2c63e055"         ads:adSize="BANNER"

and it should work.

Mat
  • 202,337
  • 40
  • 393
  • 406
P-A
  • 1,161
  • 12
  • 16
3

I received this error with regards to the largeHeap Attribute, my application did not run under eclipse but under ant it still built and ran normally.

The android documentation states that:

attributes:

xmlns:android

Defines the Android namespace. This attribute should always be set to "http://schemas.android.com/apk/res/android".

I erased that line in my manifest, saved in eclipse, pasted the line back in and saved again, and it worked. In my case I guess the problem was eclipse, ant and adb not talking to each other correctly and the saving reset something. Interestingly restarting eclipse did not solve this problem (usually with these types of problems restarting eclipse is the first thing you should try, and usually it solves the problem).

qtmfld
  • 2,916
  • 2
  • 21
  • 36
tjb
  • 11,480
  • 9
  • 70
  • 91
2

Make Sure you have included this part in your layout (top below xmlns:android line)

xmlns:ads="http://schemas.android.com/apk/res/com.google.example" 
...........blah blah..

Also Check whether you have included attrs.xml in the res/values/

Check here for more details. http://code.google.com/mobile/ads/docs/android/banner_xml.html

Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87
Kabilan
  • 21
  • 1
1

I usually embed the xmlns:ads property into the adview properties this way:

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"/>

so that you dont need to embed into the parent every and each time you copy the adview.

Just copy and paste the adview above and paste it anywhere and it should work

MBH
  • 16,271
  • 19
  • 99
  • 149
1

I've been searching answer but couldn't find but finally I could fix this by adding play-service-ads dependency let's try this:

*) File -> Project Structure... -> Under the module you can find app and there is a option called dependencies and you can add com.google.android.gms:play-services-ads:x.x.x dependency to your project

I faced this problem when I try to import Eclipse projects into Android Studio.

Image

Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
HashanR
  • 194
  • 3
  • 18
1

In my case, I was missing a dependency in the app level build.gradle.

The solution was to add the dependency as google outlines below:

Open the app-level build.gradle file for your app, and look for a "dependencies" section.

dependencies {
    implementation ...SOME_IMPLEMENTATION
    implementation ...SOME_IMPLEMENTATION
    implementation 'com.google.android.gms:play-services-ads:18.1.1'//<---ADD THIS LINE
}

Add the line above, which instruct Gradle to pull in the latest version of the Mobile Ads SDK and additional related dependencies. Once that's done, save the file and perform a Gradle sync.

jwitt98
  • 1,194
  • 1
  • 16
  • 30
1

Based on the answer here, I think you need to change the xmlns:ads attribute. For example, change this:

<com.google.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/res/com.google.example"
    ...
    />

to this:

<com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res/com.your.app.namespace" 
    ... 
    />

It fixed it for me. If you're still getting errors, could you elaborate?

qtmfld
  • 2,916
  • 2
  • 21
  • 36
emcee
  • 863
  • 2
  • 9
  • 11
0

I also faced the same problem, I was using GoogleAdMobAdsSDK-4.1.0.jar then I tried with GoogleAdMobAdsSDK-4.0.4.jar now it is working fine, It is problem with jar file as per my experience.

biegleux
  • 13,179
  • 11
  • 45
  • 52
vicky
  • 1
0

I had a similar issue on MonoDroid when building a class library with Drawables and Layouts files that have "android:" attribute in the xml. I get a similar error as the one in the question.

No resource identifier found for attribute 'textCursorDrawable' in package 'android'

I found from that "android: " attribute is only available in Android API Level 12+ and I was trying to build for an older version. Updating my project to build against Android 4.0 fixed the issue for me. Here is where I found the answer. https://groups.google.com/forum/?fromgroups#!topic/android-developers/ocxKphM5MWM Just make sure that you are building against the right API level if you get a similar issue, and ensure that the missing identifier exists in that API level that you are build against.

Has AlTaiar
  • 4,052
  • 2
  • 36
  • 37
0

just change the target sdk right click on project then click on property select android and select the latest API

0

The same error was happening to me in the "activity_banner_xml.xml" file inside res/layout folder. What I did to fix it was replace

<com.google.android.gms.samples.ads.AdView

with

<com.google.android.gms.ads.AdView

There was no references to my package name. Also, be sure you set the adUnitId for ads:adUnitId="@string/banner_ad_unit_id"> The add unit Id is located in your res/Values/Strings folder.

So my final layout file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/ad_unit_id"/>

Gene
  • 10,819
  • 1
  • 66
  • 58
0

If yours is a gradle project replace:

xmlns:android="http://schemas.android.com/apk/res/android" 

with:

xmlns:app="http://schemas.android.com/apk/res-auto"
chiwangc
  • 3,566
  • 16
  • 26
  • 32
Sahana P
  • 73
  • 1
  • 11
0

I am adding the solution that worked for me for this same error.

I right clicked project > properties > (left panel) Android

Right panel under Library I removed the faulty library and added it again.

For me this error occurred after a corrupt workspace eclipse file where I had to import all projects again.

Onimusha
  • 3,348
  • 2
  • 26
  • 32
0

My problem was very similar (produces same problem). After refactoring variable name by "refactor -> rename" option in Android Studio (from "value" to "myValue") i found changes in manifest file, too. Meta-data "value" pool has changed to "myValue".

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:myValue="@string/facebook_app_id"/>

After revert file everything seams to be ok again.

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

I hope, it will help someone!

Adrian Grygutis
  • 470
  • 1
  • 8
  • 18
0

Add xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads", This will solve your Issue.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.app.activities.Initializer" >


    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-123456789/123456789"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>
N.L.N.Rao
  • 66
  • 3
0

Replace xmlns:android="http://schemas.android.com/apk/res/android" with xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

then Rebuild Project

Shubhamhackz
  • 7,333
  • 7
  • 50
  • 71
0

I added in android.support.design.widget.NawigationView this parameter:

android:layout_gravity="start"

And problem was solved.

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
0

I had the same problem and my cure is to simply enable data binding in my app module's build.gradle.

android { ... dataBinding.enabled = true }

ref - https://halfthought.wordpress.com/2016/03/23/2-way-data-binding-on-android/

Gracie
  • 190
  • 1
  • 10
-2

PUT compile 'de.hdodenhof:circleimageview:2.0.0' IN Gradle Dependencies and put this code in nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/lib/org.mainsoft.navigationdrawer"

    android:gravity="bottom"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:background="@drawable/background_material_red"
    android:orientation="vertical">

<de.hdodenhof.circleimageview.CircleImageView

    android:id="@+id/profile_image"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/profile"
    app:border_color="#FF000000"
    android:layout_marginLeft="24dp"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginStart="24dp" />

</LinearLayout>