I downloaded the source for SpriteMethodTest, and I want to build it in Eclipse. So I Went:
File >> New >> Android Project >> Create Project From Existing Source >> SpriteMethodTest
It created the project alright, but the R class is not generated. Any file that references a resource in R says R cannot be resolved
.
Importing android.R just results in R.drawable.background cannot be resolved
. How do I generate R again?
You are having an issue because you are importing Androids R
, not your project specific R
. Simply delete the import android.R;
, then hover your mouse over the reference to the R that is giving the R cannot be resolved to a variable
. From there you will have possibly a few different options on which R to import. You want to import the R that is in your package.
The generated R resource file can only be generated by eclipse if the files it reads can compile, meaning errors in a file (such as the manifest file) prevent compilation. So, resolve your errors (listed in the 'Problems' tab) first, then save the changes and it should then be generated.
The reason it usually seems to be related to API versions is because different versions cause compatibility errors. This usually happens when people grab sample code and don't set the same API version as the code creator was using. Changing to the correct version resolves the errors and allows the R file to be generated.
I had this exact same problem with SpriteMethodTest. It has nothing to do with package names or imports. As tarkeshwar says, if R is not being generated, then the problem is prior to compilation. In this case it's AndroidManifest.xml
.
The last tag in the manifest is
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
but android:targetSdkVersion
is not a supported attribute. Change the line to
<uses-sdk android:minSdkVersion="3"/>
and that should allow Eclipse to generate the R class.
In my enviroment android SDK was missing the folder platform-tools and I had to start android and install platform-tools. Now it is working.
Had a similar problem, which seemed to be caused by the SDK versions as well:
*Happened when tried to check out the snake example code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With