Layout xml tools:targetApi not working - android

I use https://github.com/mattprecious/swirl/blob/master/README.md in my app.
I don't want appear SwirlView on lowwer sdk marshmallow version. because SwirlView working on version sdk marshmallow or higher version.
so I add "tools:targetApi='M'" to SwirlView xml node. look at the code below.
<com.mattprecious.swirl.SwirlView
android:id="#+id/fingerprint_SwirlView"
android:layout_width="100dp"
android:layout_height="100dp"
tools:targetApi="M"/>
but when I run app on lolipop version. occure error like this.
android.view.InflateException: Binary XML file line #29: Error inflating class com.mattprecious.swirl.SwirlView
what is problem with my code.
sorry for my poor english skill.

You gotta override the xml instead of suppressing the error. Tools don't affect the app, only Android Studio.

Related

Xamarin Android Google Maps error in Fragment

I'm getting an error while displaying maps in a fragment, I've been searching for the solution and Tried several codes but nothing seems to work.
MainActivity.xml
StackTrace: {Android.Views.InflateException: Binary XML file line #1: Binary XML file line #2: Error inflating class fragment --->
Android.Views.InflateException: Binary XML file line #2: Error inflating class fragment --->
Java.Lang.RuntimeException: API key not found.
Check that
is in the element of AndroidManifest.xml
it says API Key not found, but i did declared it in manifest and validated it using http://yougapi.com/tools/google-api-key-checker.php
AndroidManifest.xml
activity_main.xml
PS: Im using android 9.0 physical device for debugging
Please make sure if you have install Xamarin.GooglePlayServices.Maps package from NuGet.
And you used Android 9.0 physical device, please make sure your device if have Google Play services
I test my demo in the Android 10.0 emulator, it worked as normal.
Here is my demo. You can test it.
https://github.com/851265601/XAndroidMap

Error inflating class ImageButton during runtime but Android Studio shows no errors and compiles flawlessly

Application crashes with the following exception:
android.view.InflateException: Binary XML file line #185: Binary XML file line #15: Error inflating class ImageButton
But Android Studio shows no layout errors, layout preview of the file that is responsible for the crash is properly rendered and the application can be compiled and run.
Crashing ImageButton:
<ImageButton
android:id="#+id/kasablok_pager_btn_left"
android:layout_width="74dp"
android:layout_height="match_parent"
android:background="#FFFFFF"
app:srcCompat="#drawable/ic_chevron_right_black_24dp"
android:rotation="180"
tools:ignore="ContentDescription" />
The source drawable exists and is click-through to the file. There are no errors or warnings in the preview window to indicate a possible problem.
vectorDrawables.useSupportLibrary = true is also properly set in my build.gradle file.
Answer: the ic_chevron_right_black_24dp.xml file was located in the specific res/drawable-v24 folder instead of the common res/drawable. This way the id was only available on API 24+. Moving the file into the latter folder did solve the problem. My phone ran Android M (API 23) and that's why it crashed. The ic_chevron_right_black_24dp id could not be found.
How did the file end up in the wrong directory without my knowledge?
I copied the ic_chevron_right_black_24dp.xml file over from another project. What I did was to paste the file into the drawable resource directory while viewing the project as Android (the top left dropdown that allows you to choose how to represent your project in the left navigation panel). Android studio somehow decided to put the file into the specific drawable-v24 instead of the general drawable folder.
Why didn't Android Studio show any errors and why was the preview properly inflated?
The layout preview was properly inflated because the preview and also the compileSdkVersion was set to android-P. This way the preview was rendered as if it was on android-P API, where the resource existed.
How to tackle InflateException in your application?
When you see an InflateException, this exception itself doesn't provide any usable information about your problem. It can be caused by a variety of different independent things. You must look deeper. InflateException is not the cause - it is the effect caused by something else.
In my case the whole stack trace looked like this:
android.view.InflateException: Binary XML file line #185: Binary XML file line #15: Error inflating class ImageButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2335)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1423)
.....
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
.....
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070070
at android.content.res.Resources.getValue(Resources.java:1364)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:328)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:58)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:78)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageButton(AppCompatViewInflater.java:201)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:121)
That's more usable. The trace shows that the InflateException was triggered by a Resources$NotFoundException and this was the real culprit.
I solved this error, move the file(Image) from /res/drawable-v24 to the general folder /res/drawable, this is folder for any versions, and handle it with app:src in the layout code XML.

Error with com.viewpagerindicator.CirclePageIndicator

It worked before, but now it throws:
android.view.InflateException: Binary XML file line #16: Binary XML
file line #17: Error inflating class
com.viewpagerindicator.CirclePageIndicator caused by:
java.lang.UnsupportedOperationException: Can't convert to dimension:
type=0x1d`
I've tried to set #color/color_primary values and '#ff00ff' color hex
values: the same issue.
As a workaround: I set all needed colors in runtime by calling
setFillColor(), setPageColor() and setStrokeColor() respectively.
Library version compile 'com.viewpagerindicator:library:2.4.1#aar'
Source https://github.com/JakeWharton/ViewPagerIndicator/issues/424
This happens when you update your gradle version, and this Lib isn't giving any support or having updates for more than 5 years...
Despite I tried many other alternatives to keep using it, the best solution was to change it for this one:
implementation 'com.github.splatte:ViewPagerIndicator:3.0.0'
More information here: https://stackoverflow.com/a/47785895/6706788
There are other options there (one telling to add "app:" on all attributes of this lib), feel free to try them too if you want, for me, the solution of the alternative lib (a branch) was the only one that worked.

Android - problems with new AdMob implementation

I am trying to replace old adMob implementation with the new Google Play Services AdMob version.
Unfortunately on some devices (with Android 4.0, 4.1) get following error:
*FATAL EXCEPTION: main
E/AndroidRuntime(5280): java.lang.RuntimeException: Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #14: **Error inflating class com.google.ads.AdView***
As you see, the problem is with com.google.ads.AdView but I am replaced this with com.google.android.gms.ads then no more using this old ads library mentioned in this error. I am sure that all code is replaced with the new gms library properties (in Manifest, XML, imports and invoking method).
Due my tests even removed all ads and libraries calls from my app but the problem still exist.
This app (and new ads) working properly on some devices (with Android 2.3.5 and 4.4.3) and in emulators but not working on devices with Android 4.0 or 4.1.
I am using Eclipse.
Thank you for any help.
With Google Play Services, the package name of the Ad classes have changed. Instead of com.google.ads, it's now com.google.android.gms.ads.
So if you change this in your layout, it should work.

Android: there's no way i can install admob on my app

I begin to get angry, there's no way I can put admob in my app.
I have a 2.3.3 app with min-sdk="10" I need it for zxing.
now I need to put admob... I go in my account to download it (version 6.0.1), and i found that android 3.2 is needed!
I've tried various implementation, such as put admob4, varios code, but i had no success...
how can i install admob and let 2.3.3? how can make this terrible thing work?
logcat:
07-10 13:55:20.007: E/AndroidRuntime(1348): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.mi.action.codmmunicator_2ddecoder/it.mi.action.codmmunicator_2ddecoder.Tabs}: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.ads.AdView
Here you can see how you can add admob into your app. You simply have to work with the 3.2 or 4 android sdk but in your manifest min-sdk tag you put 10 ... For more details please take a look at that tutorial.

Categories

Resources