[android] error: No resource identifier found for attribute 'adSize' in package 'com.google.example' main.xml

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.

This question is related to android admob

The answer is


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


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


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.


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"/>


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.


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.


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.


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


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"

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


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?


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


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.


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).


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


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>

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"

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


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!


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>

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

android:layout_gravity="start"

And problem was solved.


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/


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


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"

I hope it helps.


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.