- Home /
Incorrect R values; Wrong resources
Hello. I'm having an issue making a Unity Android project in that the R file that Unity generates contains the wrong values in its R file, causing the activity to either display the wrong resources or simply crash on NullPointerExceptions when findViewByID (among other things) returns null.
Specifically, I have an Android project with an Android project library, each with their own R files. My reproduction steps are as follows:
I export the entire former project as a JAR into Unity in the Plugins/Android folder.
I then export only the source of the latter library project (otherwise I get duplicate resource errors).
Lastly, I build the project for Android in Unity, where it generates its own R file in its Staging Area. This R file matches the R file in the former Android project, and does not match the latter library project's R file.
During runtime, objects from the library project will request values from R, and have the former project's R values returned instead of the library's R values, resulting in my problem.
If I instead export everything but the gen folder of the former project (that includes its R file), and instead include the gen folder of the latter library project (whose R file matches the correct values) I don't get any of these errors. However, I can't add anything to my former project in this scenario without breaking everything (as then the R values no longer match), so I'd like to avoid this work-around.
I also note that using getResources().getIdentifier() returns the correct R value in every case (as opposed to com.my.package.R.id.value), but for technical reasons I cannot modify my library's source to use this instead.
If anything isn't clear please ask.
$$anonymous$$aybe your code is wrong, causing your error.
The entire project works if I export the library project's gen folder ins$$anonymous$$d though, so I don't think that's the problem.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110413im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Manage resources for mobile game 1 Answer
build android apk that contain Resource XML 0 Answers
Read a specific line from a txt file in Android 1 Answer