Android drawable resource id conflict?

╄→гoц情女王★ 提交于 2019-12-01 08:14:18

Ok, it seems like the Android platform has a few wrinkles when using library projects. I noticed that the R class of my project and the R class of the ZXIng library project were conflicting all over the place e.g.

public static final class id {
    ...
    public static final int mainmenu_btn_scan=0x7f070028;
    ...

And in the library project's R class:

public static final class id {
    ...
    public static final int share_app_button=0x7f070028;
    ...

This explains how a UI element from my activity was being picked up by an activity in the library project. Android will give priority to resources ids in the main project.

This excellent article gave the solution: http://blog.blackmoonit.com/2010/12/android-sharing-resources-in-eclipse.html

In CaptureActivity (the activity I was calling in the library), I replaced

viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);

With this

viewfinderView = (ViewfinderView) findViewById(
    getResources().getIdentifier("viewfinder_view", "id", getPackageName()) );

This fixed the issue, although I'll need to go through and replace all direct id references with getIndentifier() to ensure there aren't any other conflicts. Not an ideal solution. It feels like there ought to be some fairly straightforward extension to the aapt tool to ensure that the ids between R classes don't conflict.

See here for more info: http://devmaze.wordpress.com/2011/05/22/android-application-android-libraries-and-jar-libraries/

use project->clean.. to regenerate R Class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!