not able to add Google Admob - android

I wrote code for Admob. This is my layout.xml file code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/relativeLayoutHomeParent"
tools:context=".Home" xmlns:app="http://schemas.android.com/apk/lib/com.google.ads">
<RelativeLayout
android:id="#+id/relativeLayoutHomeTopBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/textView1"
android:text="Home"
style="#style/screen_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/imageViewHomeSettings"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/set_settings"
android:layout_marginRight="10dp" />
</RelativeLayout>
<View
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="#+id/relativeLayoutHomeTopBar"
android:background="#drawable/shadow" />
<ListView
android:id="#+id/listViewHome"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#BDBDBD"
android:dividerHeight="1dp"
android:layout_below="#+id/view1" >
</ListView>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
app:adSize="BANNER"
app:adUnitId="a1512f50d8c3692"
app:loadAdOnCreate="true"
app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
Output:
I want the bar that is on the top(yes that black bar), on the bottom of the screen. I also wrote for it but it showed the output as the above image.
Also i dont understand that which one is the admob banner, the top one or the bottom one ?? Can anyone please explain the difference these two bars. Actually i am new to this. This is the first time i've code for admob. Please help me to learn on this.

Maybe the ADK update has messed-up with your project's build-path. Try removing the admob JAR and add it again to your libs folder, add it to your Build Path and do a Clean Project.
EDIT following poster's comment about not having a libs folder:
You should try this:
Remove all references to the AdMob JAR in your project -> your code should not build without error anymore
Create a libs folder at the root of your project.
Copy the AdMob JAR into the libs folder
Make sure this AdMob JAR is in your Build Path (this will allow your code to build wihtout error)
(If still not running OK) Right click your project > Android Tools > Fix Project Properties

Related

Android Studio shows wrong layout in layout preview (ActionBarOverlayLayout?!)

I have a nice FrameLayout as main container and some other views inside it's hierarchy.
But the preview shows a simple ActionBarOverlayLayout.
What is that? Why is it here?
I have Android Studio 3.0.0
I have tried:
Restart Android Studio. Refresh the preview by resizing. Changed the preview device, changed the SDK of the preview, changed the blueprint\design options, pressed "force refresh layout" Button.
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="match_parent"
android:layout_height="#dimen/walk_list_item_height"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:layout_heightPercent="25%"
app:layout_marginLeftPercent="0%"
app:layout_marginTopPercent="0%"
app:layout_widthPercent="100%"
app:riv_corner_radius="#dimen/corner_radius"
android:id="#+id/walk_iv" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/gradient"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<TextView
android:id="#+id/walk_name_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical"
android:padding="16dp"
android:text="New Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_duration_icon" />
<TextView
android:id="#+id/duration_tv"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:gravity="center|left"
android:text="TextView"
android:textColor="#fff" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_marker"
android:layout_marginLeft="16dp" />
<TextView
android:id="#+id/stops_tv"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
That is because there is a broken build in your earlier build. It is coming from the intermediate files which is because the files are not proper in your xml files. There might be a broken link or a - in the drawables names.
Until you resolve this you cannot proceed to see the layout of your app in the layout-editor.
Moreover Android Studio will not show you any error in the error log or any other terminal.
Start from the styles/themes of the app, it might contain something which is missing from the gradle or resources of the project. Due to the support library still in the project it partially showcases it as missing control of XML files, but it will not let you load the xml editor visually for the project.
You have see that by yourself, start first from drawables and then move to values folder, if not check your gradle and then come back to Java files for the error.
Had to raise
buildToolsVersion to 26.0.0
previous was bugged (25.0.2)
I faced the same problem and, In my case, it was simpler than that. I just received a warning message recommending to remove the explict reference to the BuildToolsVerison from build.gradle file so I just did it, then saved all file, Menu >> Run >> Make a project and it worked fine.

Rendering Problems NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts

I have a project in Android and everything is okay then when i open the project yesterday this kept giving me this error
Rendering Problems
NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts.
"invisible" in attribute "visibility" is not a valid integer (109 similar errors not shown)
Tip: Try to refresh the layout.
even when i start a new project and i go to the layout it kept giving me the error.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
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:background="#color/backgroundDark"
tools:context="coalesce.collabup.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/Logo"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="CollabUp"
android:textSize="70sp"
android:lineSpacingExtra="8sp"
android:typeface="normal"
android:textAlignment="center"
android:textStyle="normal|bold" />
<TextView
android:id="#+id/motto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="Collaboration at its finest"
android:textStyle="normal|bold"
android:textAlignment="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="50dp" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"
android:textSize="18sp"
android:padding="10dp"
android:layout_marginBottom="10dp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:imeActionId="#+id/login"
android:imeActionLabel="Sign In"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<CheckBox
android:text="keep me log in?"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/checkBox2"
android:layout_marginTop="10dp" />
<Button
android:id="#+id/email_sign_in_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:text="Sign In"
android:textStyle="bold"
android:layout_marginLeft="250dp"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/registertxt"
android:text="New to CollabUp? Create an Account now!"
android:textStyle="normal|bold"
android:textAlignment="center"
android:textSize="14sp"
android:onClick="gotoRegister"
android:layout_marginBottom="20dp" />
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/forgettxt"
android:text="Forgot your password?"
android:textStyle="normal|bold"
android:textAlignment="center"
android:onClick="gotoSendForget"
android:textSize="14sp" />
<TextView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/creditstxt"
android:text="Coalesce 2016 - All rights Reserved - CollabUp"
android:textStyle="normal|bold"
android:textColor="#android:color/white"
android:textAlignment="center"
android:textSize="14sp"
android:layout_marginTop="20dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
The issue is resolved by these changes:
Close Android Studio
Go to C:\Users\UserName.android and rename the build-cache folder to buildcache.bak
Go to C:\Users\UserName.AndroidStudio3.2\system and rename these folders
(1) caches to caches.bak
(2) compiler to compiler.bak
(3) compile-server to compile-server.bak
(4) conversion to conversion.bak
(5) external_build_system to external_build_system.bak
(6) frameworks to frameworks.bak
(7) gradle to gradle.bak
(8) resource_folder_cache to resource_folder_cache.bak
Open the Android Studio and open your project again.
This issues is caused in newer versions of android studio 3.2 you can fix the error by deleting the cache files.
step 1 : close android studio.
step 2: Go to .AndroidStudio3.2->system->caches.
step 3: Delete all files.
step 4: open Android studio
Your template is corrupted. Just go file and then setting. On the top search box, search templates and find file and code template. Choose that then choose other tab at the right hand side. click android and click layoutResourcesFile.xml.
copy and paste the below code on it and make sure you click live templates.
<?xml version="1.0" encoding="utf-8"?>
<${ROOT_TAG} xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="${LAYOUT_WIDTH}"
android:layout_height="${LAYOUT_HEIGHT}">
</${ROOT_TAG}>
I also got this error. I was helped by the following:
Remove the Android Studio files
To delete any remains of Android Studio setting files, in File Explorer, go to your user folder (%USERPROFILE%), and delete .android, .AndroidStudio and any analogous directories with versions on the end, i.e. .AndroidStudio1.2, as well as .gradle and .m2 if they exist.
The source is here
But I have not deleted these folders. I removed the dots in the folder name. After that, I launched Android Studio. She suggested that I export the settings from the old folders (in which I removed the dots in the title). I refused and re-tuned the studio. After that I opened the project and everything works.
Sorry for my english. I hope you understand my answer :)
The only thing that worked for me.
1. Download Android studio from the official website https://developer.android.com/studio/#downloads.
2. Install
You can even import settings from the previos install.
Now the render is fixed
I used the simple feature of Clean Project (Build -> Clean Project) and it somehow worked for me!

New xml layout file is not being added to R.java

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background1"
tools:context="com.example.flavours.Category" >
<ImageView
android:id="#+id/homeimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:src="#drawable/ice1"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
Each time I had a problem with R (R.id/layout) not been generated after change build target (6.0) to (5.0.1).
I already cleaned the project multiple times and whn i cleaned my project instantly i get error on "r"(R cannot be resolved to a variable) .I also import my (com.example.flavours.R;) but it remove whn i press Ctrl+shift+o.
i checked your code and i tested it ,
its true and works !
make sure that your new .xml file,has a valid name
valid name contains only
lowercase letters `a-z`
numbers `0-9` and they should`nt be in the first of file name.
underline `_`
also right click on the project and cleanup the source
Right Click On Project > Source > Clean Up...
or check build path for unwanted changes
Right Click On Project > Build Path > Configure Build Path...

when clean and build project getting error in eclipse console

When clean and build project getting error in eclipse console. And one more thing R.java in not be created it show error on R.
Error are like
W/ResourceType( 7964): Bad XML block: header size 85 or total size 5529592 is larger than data size 0.
Any help guys why this happened?
I am using these two xml
itemlist.xml
<TextView
android:id="#+id/txtNewsSource"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:background="#64CBD8" />
and secone one main.xml
<com.krish.horizontalscrollview.CenterLockHorizontalScrollview
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</com.krish.horizontalscrollview.CenterLockHorizontalScrollview>
<LinearLayout
android:id="#+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/scrollView"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:id="#+id/btnPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Prev" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Next" />
</LinearLayout>
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/bottomLayout"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:textColor="#FF0000"
android:padding="#dimen/padding_medium" />
First Copy "android-support-v4.jar" from your main project libs and paste it in your all external libraries.(Mean replace all android-support-v4.jar with you main one support library.)
Ensure that there is no duplication of xml data (let say:same code in your external library string file and in your main project's string file.)
Remove all external libraries, Clean+build your project.
Again include your external libraries one by one and clean.
"W/ResourceType( 8032): Bad XML block: header size 85 or total size 5529592 is larger than data size 0"
Means that you have a malformed XML resource.
You need to solve the XML error then you clean build your project.
Please validate your XML online
First Clean project from project menu
Then fix import in in your class file like this:
import com.your.package.xyz.R;

How to properly configure AdMob using IntelliJ IDEA?

I'm trying to incorporate AdMob into my Android application. I'm using IntelliJ IDEA for development and I cannot seem to set my project up properly. At this point I've done the following:
Did all the preliminary steps necessary to download the AdMob SDK.
Followed the directions here, trying to augment them for IntelliJ IDEA. I've added a Single-Entry Module Library dependency to the AdMob SDK to my project.
It looks like the IDE has no problem recognizing the classes from the SDK if I try to use them in code. However, it fails to resolve them in XML. I have the following two errors:
Cannot resolve symbol 'AdActivity' when I set up the ad activity in AndroidManifest.xml the instructions call for.
Element com.google.ads.AdView is not allowed here when I try to add an ad view to a layout in the manner documented here.
Thank you very much in advance for your help. I hope I've been clear.
EDIT
A clarification based on Cristian's answer. It's true that the first error seems to not matter. However, the second error causes the project build to break with the following message:
.../res/layout/main.xml:7: error: Error parsing XML: unbound prefix
The XML in question is the following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="123dp"
android:src="#drawable/logo"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/cart"/>
<Button android:id="#+id/new_shopping_list"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:text="#string/new_shopping_list_btn"/>
<Button android:id="#+id/view_all_shopping_lists"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_below="#id/new_shopping_list"
android:text="#string/saved_shopping_lists_btn"/>
<ImageView android:id="#+id/copyright_notice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="7dp"
android:layout_marginRight="5dp"
android:src="#drawable/copyright"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/copyright_notice"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="4dp"
android:src="#drawable/techsmart_logo"/>
<ImageButton android:id="#+id/user_guide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="7dp"
android:layout_marginLeft="5dp"
android:src="#drawable/user_guide"/>
</RelativeLayout>
Do not worry about those errors. AdMob library is obfuscated, thus IntelliJ cannot read the correct names of the classes. However, your application will compile and run fine. This is how one of my projects looks like, and they work fine:
As you can see, there are other libraries like Pontiflex or AirPush that has the same problem.
With regards to your second problem, it seems you forget to add the XML NameSpace. This answer says that you must add this one:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Categories

Resources