问题
I am using zxing library for barcode scanning in my application. So i have set zxing project as a library and adding that library to my project ( properties -> android -> add library )
After adding the library project when i build the code , i see that there are two R.java files created within my project.
One is under the path :gen\com\google\zxing\client\android
and the other : gen\myproject
The first one has all the resource variables from the library plus the resource variables in my project. The second one has resource variables only from my project. When a new layout or resource variable is added its getting updated in both files
So my doubts are : 1. why there are two R.java files 2. Is there a way i can stop generating the one with all library project variables
Because of this behaviour i ran in to very strange issues which was very difficult to debug.
In my zxing library there is a layout "capture" that will be set when we try to scan a barcode. Whenever i was adding any layout or any resource variable with name starting with letter "a" / "b" my application was giving weird behaviours . And everything worked perfect when i just renamed the layout Later i found that it has something to do with the the id for "capture" in R.java file. When i define a layout with letter starting a, it will be inserted in the R.java list before "capture" and thus the id for capture was changing. ( There is another R.java file in the actual zxing project which i had set as library. So seems like the id for capture in my R.java file and the zxing library R.java should be same )
Can you please explain what is really happening here
回答1:
I think you include the complete project...
If so delete that, and only import this files into your project:
http://code.google.com/p/zxing/source/browse/trunk#trunk%2Fandroid-integration%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fintegration%2Fandroid%253Fstate%253Dclosed
Thats all you need :)
来源:https://stackoverflow.com/questions/9924684/android-r-java-behavior-when-a-library-project-is-added