Xamarin.Android build error: duplicate class R.java - xamarin.android

I loaded a long-dormant Xamarin.Android project that I last opened in MonoDevelop, when it was still called Mono for Android. Every time I tried to build the project, debug or release, it fails with "Error: duplicate class" pointing to R.java.
Since R.java is just an auto-generated file for the various project resources, I tried editing a filename and letting Xamarin Studio update the file. This didn't resolve the build error.
Similar searches find issues with improperly named IDs in an axml file, but all the IDs in this project appear to meet Android requirements (and it built fine the last time I worked on it to generate the project's APK).

Deleting the project's bin and obj folders entirely and letting them be rebuilt from scratch resolved the build error just fine.
Since the actual R.java file is buried deep in the obj folder, it may have been possible to be a little less eager with the deletes. There is probably a better solution entirely, but this certainly got the job done.

delete all files and folders from your c:\users\\appdata\local\xamarin\
Restart VS - very important
Clean Solution
Build / Rebuild solution
If the above ends up with some other resource errors , close and reopen VS and repeat steps 2,3,4.

Related

Build error Xcode 10 - Multiple commands produce

I just upgraded to Xcode 10, and I suddenly face this error when I try to build, any ideas how to fix it? I tried cleaning derived data, but without any luck.
If you use CocoaPods, click Xcode menu file -> Workspace Settings , And click Build system choice Legacy Build System
If you not use CocoaPods, same of top , select Project Settings
If your app is generating the error related to the multiple .app files just like mentioned above in question then removing the .plist files from "Copy bundle Resources" WILL NOT WORK.
If the error is related to .app file then follow the following steps.
Select the Target.
Go to Build Phases tab.
Remove the items listed in Output Files
Compile the code if it compiles successfully then not follow the next steps.
If code does not compile successfully and Xcode may give you an error related to "Library not found". Then add the missing library in General Tab in Linked Frameworks and Libraries that Xcode mentioned in the error.
Keep adding these libraries (that Xcode ask through compile errors) in Linked Frameworks and Libraries until the code compiles successfully.
Hope this helps.
You can try to change the build system to Legacy,
File > Workspace Settings > Build System > Legacy Build System.
I also faced this issue in xcode 10 but it was because of adding the same framework in main project + other extensions (watchkit or siri extension etc).
I added ObjectMapper in podfile for my main project + for my extensions. When I compiled it gave me an error that multiple command produce and also shows me which framework is causing this issue. Now its working fine for me as I've removed it from my extensions I wasn't using it in my extensions.
Don't know about your issue may be you can check your podfile.
If this is CoreData related. The issue is that you are trying to generate the NSManagedObject subclass but you need to set the 'CodeGen' option to Manual/None. This option is defaulted to Class definition and this would regenerate the code thus creating this issue.
i encountered this issue as well while working with CoreData.
in my .xcdatamodeld file, it came down to the fact that, during the creation of my various Entities, i had copy and pasted one multiple times (thinking i was saving time because various properties were similar enough that i thought this was a good idea).
the resulting Build error Xcode 10 - 'Multiple commands produce' occurred because i forgot to check and make sure the new Entities were set to their own unique corresponding class to match the new Entity in the Data Model Inspector pane.
unfortunately, it took me two days to figure out the original Entity's Class Name was still in place.
so lesson: careful when you copy/paste/duplicate Entities in CoreData.
(... i guess :0} )
some time saver. oops! hope this helps someone.
I had this same issue with Core Data entity class. I had forgotten to select Codegen Manual / None because I do not allow mine to be autogenerated. So I had a class in place and also it was trying to generate one.

After changing file locations, project can't recognize some of my classes

First off, I know this is a config issue because my code was building and running just fine before I synced my project to GitHub. Xcode's internal source control seems to be having trouble recognizing some of my files and I'm getting Use of unresolved identifier... errors where these files' initializers are in use, and were working before. I'm running the latest versions of Xcode and OS X, and these are the steps I was taking before and after the issue started...
BEFORE:
After several rounds of implementation and committing with the default local repository, I built and ran the app multiple times with no issues.
I created a new repository on GitHub, committed (w/push to remotes) and everything made it to GitHub just fine and was building and running in the simulator.
In order to organize the repository (to match the 'groups' I had created in Xcode) I did some brief research and then added nested directories to my project folder. I re-opened Xcode and repaired the file paths. Some took, but several kept showing ? (although I could still access the code just fine) and I got the corresponding Missing Files... warnings.
Because I couldn't get the new hierarchy to work (the files w/?s, not being recognized, were not able to be committed to GitHub), I tried to move the files back. This worked for most, but for a few (which seem to be the effected files) I had to rename them, recreate a new file and then paste their contents over (this is where I think the problem lies). I was able to commit everything to GitHub (even the problem files went up) but all the warnings remained.
To clear out the warnings I attempted to run my tests, and that's when the Use of unresolved identifier... errors popped up, and of course the build failed.
AFTER:
I verified all the paths and target memberships were correct.
When that didn't work, I built an entirely new project (although I did add it to the same workspace; not sure if that matters) and copy/pasted all my code over to new files. I didn't drag / reference the files and I didn't link the new project to GitHub. When I went to build, same errors in the same places...
I exited the workspace and opened the new project separately. Still no joy.
Any help or points in the right direction would be much appreciated.
EDIT:
After some help, I tried deleting the reference and dragging the file in manually but that didn't resolve the issue.
I also checked Build Phases -> Compile Sources and everything was listed fine with no compiler flags. I removed and re-added from Compile Sources, issue persists.
You can try removing referencer for the missing class file in Xcode,then add same file to folder (right click add file ) from physical workspace location this might help.
After rebuilding an entirely new app a third time, with all new files, I copied the files over and this time everything seems to be working fine. Had to repair a bunch of provisioning issues to make sure it worked (maybe that was part of the problem, but I doubt it), but everything is back to normal with the app. The only thing I did differently this time was not adding the new project to the same workspace.

Resource files not updating with Xcode 5

I have some binary files with a proprietary extension that don't get updated in a build when I compile. In previous versions of Xcode with this same project, it would detect the file was changed, and rarely would I have to perform a 'Clean' as I have to do with this version. Of course this is consuming a lot more time -- I would appreciate it if someone could let me know what's changed with Xcode 5 and/or what I could do about this.
I didn't include any project specifics because it's really just a proprietary binary file with a custom extension in a resource folder, which, used to update automatically upon it being changed since last compile. If you need any specific project settings I would be glad to offer it.
It's using the sort of 'blue' resource folder that is a reference to the folder it's in, and isn't just copied into the project directory. I apologize since I forget what this particular resource folder type is called (I'm guessing Reference).
Version: Xcode 5 (5A1413)
UPDATE:
This only happens when I'm referencing a file that I modify programmatically with fopen,fwrite,etc, and upon using a file editor in OSX to resave the file (without really changing it) Xcode will then see it as changed.
I'm now looking into FSEvents to see if this underlying API is something I need to use, although I'm not exactly sure how to set flags with this just yet.
UPDATE:
Well, just as a simple test, I take the same file and resave it via:
NSData* data = [[NSData alloc] initWithContentsOfFile: #"/location/file.dat"];
[data writeToFile:#"/location/file.dat" atomically:YES];
Sure enough, after I call that and then run the app that uses the resource, it is updated via Xcode during the build. So it would seem that Xcode 5 relies on some special flags not set by the standard io functions. At this point I can either patch what I've got with that 2 line thing or figure out what the flagging mechanism is, and how to write to it. (FSEvents? I don't see a writing mechanism there..)
I had the same problem. I set up an Xcode build-phase script to touch the root resource folder, and it works now. I found the instructions here and they are as follows (see link for more detail):
1) Add your single resource directory (named anything but ‘Resources’) to your project in the Resources section as a blue ‘Folder Reference’
2) Right click on your app target, select Add->New Build Phase->New Run Script Build Phase
3) In the resulting ‘Info’ window, change the shell to /bin/tcsh and copy and past the script below into the ‘Script’ text view.
Script:
touch -cm ${SRCROOT}/../../YourResourceFolder
(Also, you may need to know how to find "Build Phases" in Xcode 5)
I was also running into problems. Everything was fine before Xcode 5, and my referenced resources folder would copy pretty dependably. However, after updating, no matter what I did to an individual file (touch it, delete and re-copy it, etc.), nothing triggered Xcode to scoop it up again.
However, I now modify the last write time on the referenced folder during my build step, and now it's contents seem to be copying correctly again. I Hope that helps you too.
I am using custom tools, but I'm sure a build script can do the same. My guess is that Xcode tries to optimize the dependency step, and checks the folder's last access/write times before diving into it.
well a simpler way would be to just touch the folder from your shell or term.
e.g. on your terminal just run
touch -cm PATH_TO_FOLDER_UNDER_RESOURCES
PATH_TO_FOLDER_UNDER_RESOURCES is actual path to the folder under resource folders which contains the files.
Since changing your files do not necessarily change the timestamp of the folder and Xcode looks into the timestamp of the containing folder.
I had the same issue with xcode5, I need to update javascript frequently. I had to clean and then build, it took long time because my project had many source files. Later I tried to delete the app (choose "move to trash" rather than "delete reference") and then build, it was quite fast, but I had to restart xcode so that app can appear in the project again.

xCode can't find header files in Unity3D project

I'm building an iOS app using unity3D. Everything goes ok until I try to build the solution. Unity builds the xCode project with 0 problems but then, when I try to build with xCode, I get several, all of them the same: "*.h not found".
The problem in this is that the headers don't exist in the project folder, but in the original-unity project folder they do exist.
I've seen a lot of similar problems around the web, but most of them relate to independent xCode projects, being the solution messing with the paths and so on... But with a project built by unity is it supposed to change that? When I go check them, they seem correct...
I've also seen that unity had a problem and by reinstalling it would fix the problem. Unfortunately it didn't...
Does anyone know what kind of problem is this? Should I change the build paths even though unity set them some way? Is it unity's fault?
Thank in advance
Native plugins need to be stored in special folder Plugins, for iOS it is Assets/Plugins/iOS. Citing from Unity - Building Plugins for iOS:
Automated plugin integration
Unity iOS supports automated plugin integration in a limited way. All files with extensions .a,.m,.mm,.c,.cpp located in the Assets/Plugins/iOS folder will be merged into the generated Xcode project automatically. However, merging is done by symlinking files from Assets/Plugins/iOS to the final destination, which might affect some workflows. The .h files are not included in the Xcode project tree, but they appear on the destination file system, thus allowing compilation of .m/.mm/.c/.cpp files.
Note: subfolders are currently not supported.
I marked the subfolders statement bold as I ran into trouble with this some time ago :)

Cordova-2.1.0 Couldn't load CordovaLib.xcodeproj because it is already opened from another project or workspace

I have recently upgraded to cordova 2.1.0 and previously each Xcode project referenced its own cordovalib folder.
I thought I understood that if you want an Xcode to use a cordovalib on its own and not share it with any other projects, then you can run
./update_cordova_subproject
in
Cordova-2.1.0/lib/ios/bin
and that if you don't run the update script with its parameters then you can share the CordovaLib.xcodeproj file across many projects. However if I open two Xcode projects that reference the same Xcode project I get this error:
Cordova-2.1.0-global/lib/ios/CordovaLib/CordovaLib.xcodeproj Couldn't load CordovaLib.xcodeproj because it is already opened from another project or workspace
and if I try opening the CordovaLib/CordovaLib.xcodeproj file I get this error:
The file couldn’t be opened.
However all projects run without any problems.
Quitting xcode and reopening the project without any others that reference the same cordovalib open removes the error.
Does this mean that:
I cannot share a CordovaLib.xcodeproj file across many projects and each project has to have its own cordovalib that it references, otherwise I could run into serious problems in the long run? Or
I can share a cordovalib across many projects but can only have one Xcode project open at any point in time and that I will not run into any serious problems in the near future?
Is there something I am overlooking?
I have tried googling the problem but most of the questions refer to previous versions of cordova whereby the method of referencing the CordovaLib was different.
Thanks in advance.
You can reuse the subproject, but you can only have it open in one app at a time.
Not a problem if you only work on one thing at a time like most people, but since my current preferred development setup involves 18 desktops and never closing anything, I work around it with git submodules - each app gets its own fully independent copy of Cordova without actually keeping a separate copy in source control.

Resources