error: No resource identifier found for attribute

2019-01-02 17:07发布

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.

标签: android admob
24条回答
爱死公子算了
2楼-- · 2019-01-02 17:24

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

android:layout_gravity="start"

And problem was solved.

查看更多
几人难应
3楼-- · 2019-01-02 17:24

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

查看更多
有味是清欢
4楼-- · 2019-01-02 17:26

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

查看更多
大哥的爱人
5楼-- · 2019-01-02 17:26

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.

查看更多
与君花间醉酒
6楼-- · 2019-01-02 17:27

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>
查看更多
无与为乐者.
7楼-- · 2019-01-02 17:28

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.

查看更多
登录 后发表回答