IntelliJ IDEA - Can't build anything, always get “package R does not exist”

前端 未结 13 508
轻奢々
轻奢々 2020-12-16 09:32

I\'m trying to use IntelliJ IDEA to work on an Android app with a colleague that swears by it, but I\'m unable to build any of the Android projects he sends me because whene

13条回答
  •  时光说笑
    2020-12-16 10:13

    I've started playing around with IntelliJ since I've had issues with the new Android Studio and wanted to try something that was a little more stable (I've never really used either before). I ended up getting the dreaded “package R does not exist” error. In my experience, this is usually something messed up in an XML file. For me, the problem was actually with the AndroidManifest.xml file for an Android Library Module that I had created for ActionBarSherlock. For whatever reason, when it created the AndroidManifest.xml file it didn't bother to use the AndroidManifest.xml file that came with ABS and it put the following in:

    
    
    
        
            
                
                    
                    
                
            
        
    
    

    When I created this Module I chose File > New Module... I then Selected Library Module under the Android section and for the Content Root I browsed to the location of the files for ABS (Other fields auto filled in correctly and I didn't change them). I then clicked finish and it prompted me if I wanted to keep the local file or the memory file for project.properties. I chose to keep the local file and it didn't prompt me for any others after that.

    I have no idea why it messed up the AndroidManifest.xml file (maybe what I did above was wrong...???), but to fix it I just copied the original AndroidManifest.xml that I had downloaded with the library and replaced the messed up AndroidManifest.xml file. After that I did Build > Rebuild Project and it resolved the “package R does not exist” errors.

    One other thought, @xbakesx mentions the Facets settings, and for any modules you are using as libraries, you should make sure that "Library module" is checked under Facets for that Module. I had some issues with that at first when I was trying to figure out how to configure libraries in IntelliJ/Android Studio (I've really only used Eclipse).

提交回复
热议问题