I have imported the project from github and I am getting this error repeatedly. I can open my previous projects and run them on my phone but I can't do the same with this project. The "Gradle Build Running" runs forever. I have read through the answers regarding the same and I couldn't find anything useful.
android.R is the wrong import.
You should import com.example.android.miwok.R.
If that cannot be resolved, then R.java is not being generated.
Possible options
You need to build your project in order to generate that file.
You have some error elsewhere (usually in a XML resource file).
The "Gradle Build Running" runs forever.
A slow internet will cause this. When you first start a project, all the dependencies and Gradle binaries for the project need to be downloaded.
Related
A few days ago, I accepted a contract from a returning client to make a few changes to his Android app over the course of the next few weeks. After getting the project source code from Github, I imported it into Android Studio (3.2) and noticed an error that I usually see pretty frequently but only for a short time during a Gradle sync: error: package R does not exist. Naturally, I shrugged my shoulders and ran 'Clean Project' and then 'Make Project.'
Nothing changed
Did a quick Google search and tried every 'solution' I could find. I tried every combination of "Make Project", "Make Module", "Clean Project", "Rebuild Project", "Sync Project with Gradle Files", "Sync with File System", "Invalidate Caches/Restart" imaginable. I restarted my laptop, updated SDK files, updated build tools, singled out each and every Gradle 'Implementation' line, and finally ended up uninstalling/reinstalling Android Studio as well as deleting all my IDE preferences just in case.
Still nothing
Next, I created a new project and noticed that the generated setContentView() line had the same error referencing the generated layout file. Wait. An untouched new project is having the same error?!? I went ahead and pressed 'run' and the project compiled without any errors contrary to what the real-time inspections are saying.
Switching back over to the original imported project, I tried running it and the compiler gives the same R package error. WHY?!?! There aren't any other errors, Android Lint runs cleanly, my Gradle implementations are recognized in the files, package names are all correct, and my AndroidManifest.xml file is perfectly fine.
If you need to see my build.gradle files, AndoridManifest, or anything else, comment and let me know.
Any ideas?
EDIT
Not a duplicate because as I mentioned, I've tried all of those solutions and none worked. I explained what I've tried, and why it's a unique situation.
Compare the contents of your build folder to mine and you should notice the difference:
Notice that the R folder in the upper image is marked differently? That's a working one. The lower image shows the broken project. These were taken moments apart.
So it turns out this painfully specific undocumented error had to do with having multiple build flavors all with different google-services.json files. In one of them, the package name was incorrect but because it was in a different source directory, Android Lint didn't have any context for which to compare the package name against and the R.java file wasn't being generated because there was technically an error when Gradle Sync was running.
I discovered this after many hours of tearing through the source files and re-constructing the project one file at a time in an empty project. There's nothing like the feeling you get when you finally resolve an error you've been struggling against for days!!
I can cause a similar error to occur if I edit AndroidManifest.xml to have a different package name than my source structure:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stackoverflow.garbage">
All of my code inside the com.example.stackoverflow package gives me the "package R does not exist" error. That's because these files don't import R.java, since normally the generated R.java file would be in the same package as these files. But it's not: it's in a com.example.stackoverflow.garbage package.
I can solve the problem by adding imports. But I can also solve the problem by changing my manifest's package attribute back to what I expect.
I'm a newbie with both android and eclipse, so if you can help me, please don't assume that I know very much.
I have downloaded kankan.wheel and I'm trying to run the demos. I built the demo project in eclipse, using Android project from existing code. The project compiles without error, but crashes with a NoClassdefFoundError exception when I try to run it. The main menu comes up, but when I press a button to run a demo, the app crashes. I posted a screenshot of the the error message in context at https://dl.dropboxusercontent.com/u/24746182/except.png
I have added the wheel.jar file to the assets folder, and placed it on the build path. I've also checked wheel.jar in Order and Export. (This makes no sense to me, but I see this suggested in answer to similar questions.)
What have I done wrong, or failed to do?
Is there some reason why eclipse wouldn't just build a runnable project?
This is an update after trying the suggestion people have made. I still can't get it to work, so I'm afraid that I'm overlooking something so obvious that no one's thinking to tell me. Here is what I did.
I downloaded and unrarer a rar file with the wheel library and a wheel-demo project.
I created the wheel-demo project in eclipse, using new android project from existing cde.
I added a libs folder to my project, and copied wheel.jar into it.
I right-clicked on the wheel-demo project in Project Explorer, and chose java build path.
I clicked on "Add external jar" and navigated to wheel.jar.
I went to "Order and Export" and checked wheel.jar.
I had several errors. In the .java file for each activity (except the main activity), I got an error on the line
import kankan.wheel.R;
I commented this line out.
Also, since wheel.jar apparently doesn't specify a minimum API level, I got a error, but I just put a minimum sdk level of 8 in the manifest. I was then able to build the project without error. Still, the main screen comes up, but the app crashes as before when I press a button for any activity.
Can you see anything I've left out or done wrong?
Try to place your jar file to the 'libs' folder at the project root
I was never able to get it to work with the rar file. Here is what worked;
svn checkout http://android-wheel.googlecode.com/svn/trunk/ android-wheel-read-only
import wheel project into eclipse
fix the android:targetSdkVersion version in the manifest to get rid of the "unable to resolve target android-7" error
build the wheel project as a library
import wheel-demo project into eclipse
fix the skdVersion in the manifest
change "import android.wheel.R" to "import android.wheel.demo.R" in all the source files where it occurs.
build the wheel-demo project
I may have left out a minor detail or two.
I have an Android project for which I use the Eclipse IDE and I wanted to try an use the ProGuard tool to obfuscate/shrink my code. Unfortunately I couldn't get it to work with Eclipse throwing up a ProGuard error when I try to export my project.
To resolve this I altered the necessary project properties file to NOT use ProGuard but Eclipse just complained there were errors with the project which needed to be resolved. I tried cleaning the project, refreshing too but all to no avail. As I use a Mercurial for source control I reverted to my last good sources but now Eclipse throws up even more errors which I cannot get rid of:
org.eclipse.core.internal.resources.ResourceException: Resource is out
of sync with the file system: '/XXXXX/AndroidManifest.xml'.
loadAndParseRClass: failed to find manifest package for project
XXXXXXX
I've never been a great fan of Eclipse but how can I clean my project and get it back to a NON proguard state?
I resolved the problem. There's ANOTHER error log in Eclipse called 'Problems' which tells me my Debug certificate has expired on 25/12/2011. Handy how Eclipse labels this as a 'problem' and not an error and gives no indocation other that a red x that there's some sort of problem!
Anyway I resolved this by going here.
Make sure you Refresh your project so that the state of your Workspace/IDE agrees with your state on disk (Right click on the project and select "Refresh"). This will get rid of the first error you have.
And then just do a Team -> Revert on your projects and select the files that you have changed and want to revert to the checked-in version.
I just imported the Android tutorial solution Notepadv3. I wanted to see it run.
As usual, I'm greeted with the inability to resolve R.
I searched for an import R line and see none.
I edited a line and saved. I closed and opened the application.
What do I do??
This seems to happen on every project.
(I have tried this with Eclipse Ganymede under Ubuntu 9.1 and Eclipse Helios under Windows 7.)
I searched for an import R line and see none.
R.java will be generated in the same package that is declared in the manifest. Usually, your code resides in that same package, and therefore a manual import of R is not needed.
What do I do??
R.java will be created as part of the build process, in your project's gen/ directory.
If you have automatic builds enabled, and R.java is not being built, check your Eclipse console for error messages, such as bad or missing resources.
If you do not have automatic builds enabled, do a build.
Every now and then, you will need to do a Project|Clean to clear out erroneous errors and force Eclipse and Android to rebuild your project from scratch.
In addition to what #CommonsWare said, if after you do a Project > Clean and R is still not resolved, make sure you are importing your project's R.java and not android.R.*.
check for errors in .xml files.Build may be failing because of these.
I am baffled by eclipse. I had a working android application which i created inside eclipse. I now have come back to the application after a week and it is saying in the last java files there are hundreds of issue. I am sure there is no programming error inside the files as they worked one week ago. I think it may be a build path issue...i was wondering has anybody else come across this issue and why does it occur??
Several of my other projects also say the last file has errors which i know they dont.
Why is eclipse doing this to me?
Where should the build path point?
Under Java build path-> libraries..it says...unable to get system library for project?
Clean build in eclipse. That should generate the R.java and that should resolves your compilation issues.
This problem happens many times to me, here is the way I use to fix it:
Export the project to an external folder
Delete project from workspace (check "delete files on disk")
Import the project into the workspace again (check "copy project files to workspace")
Did you change the SDK location? That may cause this issue.
If possible please post exact error message.