Way to avoid layout file naming conflict among multiple Android projects - android

Currently, I have an Android project, consists of 1 main project, and multiple library projects.
Just that recently, I realize that if there is same layout filename among main project and library project, bad thing can happen.
third-party-library-project
- res
- layout
- actionbar_custom_view_done_discard.xml
main-project
- res
- layout
- actionbar_custom_view_done_discard.xml
So, if in third-party-library-project, if you are having line of code in its activity,
final View customActionBarView = inflater.inflate(
R.layout.actionbar_custom_view_done_discard, null);
Error stack trace caused by layout file naming conflict
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.yccheok.jstock.gui/group.pals.android.lib.ui.lockpattern.LockPatternActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at group.pals.android.lib.ui.lockpattern.LockPatternActivity.initActionBar(LockPatternActivity.java:356)
at group.pals.android.lib.ui.lockpattern.LockPatternActivity.onCreate(LockPatternActivity.java:347)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 25 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010137 a=-1}
at android.content.res.Resources.loadDrawable(Resources.java:1892)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.TextView.<init>(TextView.java:614)
at android.widget.TextView.<init>(TextView.java:442)
... 28 more
If I change the layout XML file in third-party-library-project to actionbar_custom_view_done_discard1.xml, the runtime error will gone.
This is not an issues, if the number of library projects is small. Conflict can be solved easily with simple renaming. However, when comes across huge number of library projects, what is a robust way, or strategy to overcome this problem?

Library projects need to ensure that their resource names will be distinctive and not collide with other library projects, such as by applying a prefix to those resource names.
Note that apparently the new Gradle-based build system supports resource subdirectories. I have not yet experimented with this, but if the subdirectory names form part of the resource ID, then putting your resources in a distinctive subdirectory would help to keep the resource IDs distinct (at least for non-values resources).

First I would suggest renaming your project resource file and not the 3rd party file in your first example since you may want to pull changes from the 3rd party library project again. Secondly I would suggest not using too many 3rd party library projects to begin with. From my experience the Android build system still has lots of hiccups with library projects. Things like BuildConfig.DEBUG do not work and I've had issues with library projects that contain jar file dependencies breaking the ability to run unit tests through Android instrumentation. There are tons of other bugs as well, most of them probably fairly obscure but enough of an issue that I don't suggest using library projects any more than absolutely necessary.

Related

android.view.InflateException: Binary XML file line #1: Error inflating class <unknown> background pic

I have a activity with a Background Image - now I would like to Change it and copied the new one in the drawable-hdmi Folder - rename it to Background an have deleted the old one in the Folder
but now I can put None Picture as Background - every time appears above mentioned error
<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: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="#drawable/background"
>
What can I do - have cleaned it already
02-11 21:58:33.653 10226-10226/de.tetzisoft.virjouthrger E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.tetzisoft.virjouthrger/de.tetzisoft.virjouthrger.ICit_A}: android.view.InflateException: Binary XML file line #1: Error inflating class
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at de.tetzisoft.virjouthrger.ICit_A.onCreate(ICit_A.java:16)
So say Android Studio
1) Make sure you name your resource "background" and not "Background". It's case-sensitive.
2) If you changed the resource using Windows Explorer and not Android Studio, refresh the project to update the resources.
3) You spelled your drawable folder like this "drawable-hdmi". It should be "drawable-hdpi".
4) Put the resource in "drawable" (default folder) just in case your device's density is mdpi or lower.
Have you tried naming it something else? Also even though you refer to it as background, have you made sure it keeps its .png extension?
Try cleaning and rebuilding your project,invalidate caches and restart.
Finally, open the folder for your app in finder and assure that background.png is in there.

NoClassDefFoundError occured while initiate fragment

java.lang.NoClassDefFoundError occured at the first line:
FirstFragment firstTab = FirstFragment.newInstance(10);
mTabsAdapter.addTab(generateTabSpec(0, mTabHost),
firstTab.getClass(), null);
But I'm pretty sure the Fragment exist! (it's a fragment so don't need to check if declared in Manifest.) Even refactoring its name or move to other package didn't fix the problem. Here's the stacktrace:
ERROR/AndroidRuntime(23608): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: dev.twothree.android.wtf.FirstFragment
at dev.twothree.android.activity.FragmentTab.setupTabHost(FragmentTab.java:110)
at dev.twothree.android.activity.FragmentTab.onCreate(FragmentTab.java:75)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2207)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Is it a bug of Intell J 12.0.4? My version is Build #IC-123.169. Later I'll try it in the Eclipse, but still hope it can be resolved in Intelli J.
After open the whole project with Eclipse, config all the dependencies ONCE AGAIN, Eclipse point out that I accidentally CAST one of the custom library class to another class. Maybe that's why no successful compiled class file existed for later invoke.
Anyway, it seems Intelli-J didn't found that error while 3rd party library is involved, it could be a bug. But the blame is also on me for not find that so obvious error.

FileNotFoundException: res/drawable-xhdpi-v4/foo.png in Play Store crash logs only

We've seen about 40 of these crashes in the past two days of our app release for 4.0. After reviewing crash logs, we've discovered it's existence since version 3.3 of our app. We have been unable to reproduce this in house.
Further research has indicated this problem is prevalent in other applications, but I was unable to find a resolution or an indication that Google is aware of the issue.
The crash itself happens on the setContentView(R.layout.foo) method call in onCreate()
Notes:
We limit our API to version 4 and target 15.
We've seen this on at least 2.2 - 4.0.3 on mdpi,hdpi,xhdpi phones and tablets.
User comments specify that the app crashes immediately (expected) and that the Evernote icon in the application launcher turns to the default app icon (cannot read any drawables).
The crash is not limited to one specific drawable, we have seen many different ones in the logs, however they all "seem" to be image drawables, not colors, layouts, xml files, etc...
This is not limited to 9patches, it has happened on both regular .png and .9.png
Our drawable folders look like the picture attached
We store only xml in our drawable folder
Stack trace:
android.content.res.Resources$NotFoundException: File res/drawable/ics_tab_title_unselected.xml from drawable resource ID #0x7f02016f
at android.content.res.Resources.loadDrawable(Resources.java:1697)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.view.View.setBackgroundResource(View.java:7533)
at com.evernote.ics.ActionBarTabbedTitle.a(ActionBarTabbedTitle.java:103)
at com.evernote.ics.j.a(ActivityActionBar.java:150)
at com.evernote.ics.a.c(ActionBar.java:731)
at com.evernote.ics.a.p(ActionBar.java:440)
at com.evernote.ics.a.g(ActionBar.java:423)
at com.evernote.ics.j.m(ActivityActionBar.java:68)
at com.evernote.ics.phone.SwipeableTabbedActivityAbstract.s(SwipeableTabbedActivityAbstract.java:990)
at com.evernote.ics.phone.SwipeableTabbedActivityAbstract.a(SwipeableTabbedActivityAbstract.java:662)
at com.evernote.ics.phone.SwipeableTabbedActivityAbstract.b(SwipeableTabbedActivityAbstract.java:617)
at com.evernote.ics.phone.PhoneMainActivity.b(PhoneMainActivity.java:113)
at com.evernote.ui.EvernoteFragment.a(EvernoteFragment.java:136)
at com.evernote.ui.EvernoteFragment.a(EvernoteFragment.java:132)
at com.evernote.ui.EvernoteFragment.d(EvernoteFragment.java:128)
at com.evernote.ics.phone.b.onItemClick(HomeFragment.java:1324)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3513)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/tab_unselected_focus.9.png from drawable resource ID #0x7f0201e6
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:162)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at android.content.res.Resources.loadDrawable(Resources.java:1694)
... 28 more
Caused by: java.io.FileNotFoundException: res/drawable-xhdpi-v4/tab_unselected_focus.9.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:406)
at android.content.res.Resources.loadDrawable(Resources.java:1706)
... 33 more
Any recommendations would greatly be appreciated.
App: https://play.google.com/store/apps/details?id=com.evernote
Thanks,
Ty
similar error solved by adding the following in the "proguard" file.
-keepclassmembers class **.R$* {
public static <fields>;
}

zxing android integration crash on some devices , he following classes could not be instantiated: - com.google.zxing.client.android.ViewfinderView

I have integrated Zxing as Library and used in my application. I am calling by
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_FORMATS", "CODE_39");
intent.putExtra("SAVE_HISTORY", false);
startActivityForResult(intent, 0);
It works fine on most devices but on Some devices like HTC Desire ,GT-I9000 . I am receiving below Error.
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.Armacell.login/com.google.zxing.client.android.CaptureActivity}:
android.view.InflateException: Binary XML file line #25: Error
inflating class com.google.zxing.client.android.ViewfinderView at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:123) at
android.app.ActivityThread.main(ActivityThread.java:4627) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:521) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) at
dalvik.system.NativeStart.main(Native Method) Caused by:
android.view.InflateException: Binary XML file line #25: Error
inflating class com.google.zxing.client.android.ViewfinderView at
android.view.LayoutInflater.createView(LayoutInflater.java:513) at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) at
android.view.LayoutInflater.inflate(LayoutInflater.java:407) at
android.view.LayoutInflater.inflate(LayoutInflater.java:320) at
android.view.LayoutInflater.inflate(LayoutInflater.java:276) at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:200)
at android.app.Activity.setContentView(Activity.java:1647) at
com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:160)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more Caused by: java.lang.reflect.InvocationTargetException at
com.google.zxing.client.android.ViewfinderView.(ViewfinderView.java:62)
at java.lang.reflect.Constructor.constructNative(Native Method) at
java.lang.reflect.Constructor.newInstance(Constructor.java:446) at
android.view.LayoutInflater.createView(LayoutInflater.java:500) ... 21
more Caused by: android.content.res.Resources$NotFoundException:
Resource is not a Drawable (color or path):
TypedValue{t=0x1/d=0x7f070012 a=-1 r=0x7f070012} at
android.content.res.Resources.loadDrawable(Resources.java:1681) at
android.content.res.TypedArray.getDrawable(TypedArray.java:601) at
android.view.View.(View.java:1895) at
android.view.View.(View.java:1844) ... 25 more
I am also receiving this warning on Capture.xml file in zxing source -
"The following classes could not be instantiated:
- com.google.zxing.client.android.ViewfinderView"
I am requesting all to help in this case. Thanks in Advance.
This is all wrong -- you're including our Android code in your app. It's not necessary, not encouraged, and you haven't done it correctly either. Please delete all code you copied from android/ into your project.
(In fact we strongly discourage you from copying and pasting like you have.)
Instead you should just be using code in android-integration and nothing else. You're not actually using the integrator code even!
Please start over from: http://code.google.com/p/zxing/wiki/ScanningViaIntent
I have Got Solution on My Own.
The Issue is regarding Culture. I have change default "values". make "values-de" to "values". That crashes Zxing on device that have German culture.
I don't know why it was working but now i have made english as default and it working now :)

Why is my app trying to use drawable-mdpi/title_bar_shadow.9.png?

The app works fine on HPDI and MDPI, but when run in an LDPI (v2.0) emulator, I get the exception and stack trace below.
Why is it looking for this image? (it's not referenced in my application, I've checked). The starter activity has disabled the title bar in any case.
If the OS expects this image, why is it not present?
Why is the exception relating to an MPDI image, when the emulator is LDPI?
04-20 11:35:19.432: ERROR/AndroidRuntime(236): Uncaught handler: thread main exiting due to uncaught exception
04-20 11:35:19.502: ERROR/AndroidRuntime(236): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spondle/com.spondle.EventsActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4310)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
at android.app.Activity.setContentView(Activity.java:1622)
at com.spondle.EventsActivity.onCreate(EventsActivity.java:38)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.ImageView.<init>(ImageView.java:105)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 23 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-mdpi/title_bar_shadow.9.png from drawable resource ID #0x7f02002a
at android.content.res.Resources.loadDrawable(Resources.java:1710)
at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
at android.widget.ImageView.<init>(ImageView.java:115)
... 27 more
Caused by: java.io.FileNotFoundException: res/drawable-mdpi/title_bar_shadow.9.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:391)
at android.content.res.Resources.loadDrawable(Resources.java:1702)
... 29 more
If the OS expects this image, why is it not present?
Why is the exception relating to an MPDI image, when the emulator is LDPI?
If the requested resource (title_bar_shadow.9.png) is not present in drawable-ldpi (and it wasn't until Android 2.3), Android will try to find the best match (drawable-mdpi will be the next folder to search in). Anyway, the file will not be found there either (again, it was not there until Android 2.3). So the next step would be to search for it in drawable-hdpi (where it can be found). But apparently the search stops on drawable-mdpi (which is strange... maybe a bug in Android 2.1? you could try Android 2.2 emulator)
Why is it looking for this image? (it's not referenced in my application, I've checked). The starter activity has disabled the title bar in any case.
This image (shadow) is not used by the title bar. It is displayed UNDER the title bar.
To make it disappear, you have to create your own theme, like this:
<style
name="Theme"
parent="android:Theme.NoTitleBar">
<item
name="android:windowContentOverlay">#null</item>
</style>
I solved this problem making a copy of the images from drawable-ldpi/mdip/hdpi to a drawable (only drawable) folder. Put in this folder your low resolution images.
You don't need to have a title_bar_shadow.9.png file on these folders.

Categories

Resources