I am using ADT 23.0.2.
I just imported the google-play library to my workspace and added the reference to it in my project.
Now nowhere in my project the resource ids can be recognized because there is no R file.
(Anywhere I have R.id.blah I get the error "R cannot be resolved to a variable);
It's just gone. What am I supposed to do?
I exactly followed the steps by developers.google.com. It's nothing complicated but I don't know why this happened.
(I have all layout files in place and no import for android.R are in my class files.)
Before adding the
Tools I use:
Here are screenshots from my app properties:
My manifest
<permission
android:name="com.appname.appname4.MAPS_RECEIVE"
android:protectionLevel="signature">
</permission>
<uses-permission android:name="com.appname.appname4.MAPS_RECEIVE"/>
<activity
android:name="com.appname.appname4.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.appname.appname4.SearchResultListActivity"
android:label="#string/title_activity_search_result_list"
android:parentActivityName="com.appname.appname4.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.appname.appname4.MainActivity" />
</activity>
<activity
android:name="com.appname.appname4.ContactInfoActivity"
android:label="#string/title_activity_property_detail"
android:parentActivityName="com.appname.appname4.SearchResultListActivity"
>
</manifest>
I had similar issues when I first started Android programming. Here are some fixes that worked for me in the past.
1. Fix/Check all xml(layout) files.
Many times a R file not being generated is due to an issue with your layout file or Android Manifest file. Follow this link and work your way down the page checking permissions and the general layout format.
2. Project/Clean.
go to Project->Clean.
Also make sure you have selected the option to build project automatically.(Without this option check marked R file is never generated automatically).
3. Fix Project Properties.
Right click on your project in Package explorer then choose fix project properties.
Repeat Step 1 after this.
4. Builders.
Go to Project->Properties then Builders. Select the appropriate boxes.
Repeat Step 1, and Clean and rebuild project.
5. Appcom7 and Google Play services error.
Sometimes to fix errors associated with installing these two reference libraries. I copy there folders into a generic library folder on my hard(where I keep most of my eclipse reference libraries), after this I delete them from the Package explorer and from the "default" directory where they were installed. I Fix project properties again and clean/rebuild. This should get you back to your non-reference library version of the package. Then I manually add them as Projects to my eclipse IDE and finally follow this to add them as references to my project. Then fix project properties,clean and rebuild.
6. Reference Question.
Finally, referring to this StackOverflow page has helped me countless times. And one way or another fixed my issue.
Good Luck.
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 whenever I try a build I get an error saying package R does not exist.
I have been trying out everything I can think of. Examples and other things to note are:
Making sure I have a version of the local.properties file pointing to the root of my Android SDKs folder.
Fiddling with various settings in the project structure dialog (I won't list them all).
The project I'm working on has two library projects with also use the R class and they work fine.
The intellisense within the IDE recognises the R class and comes up with the stuff I expect.
Any help would be greatly appreciated. I feel I'm missing something basic.
I am brand new to IntelliJ so I apologize if this doesn't work for you. I was experiencing the same problem and the solution was to add an Android Facet to your project.
(I am on a Mac, so directions here may be slightly off, and there are probably better ways to find this window, if so let me know!)
Right click your project and go down to Open Module Settings (seems F4 also works)
Select Facets in the far left column
Click the + button
Add an Android Facet to your project, and VOILA!
You may need to import your Rs now, which could be a huge pain... so hopefully someone can chime in with an easy way to auto-import
Hope this helps someone!
Another possible solution to those listed here is to check that the package name in your AndroidManifest.xml matches that of your actual package:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.yourpackagename" >
My package was building fine until I refactored the package name, everything refactored except for the package name in manifest file (see above) which caused the error "Package R does not exist".
If you run into this with a package that has been building before you need to "Rebuild".
Build->Rebuild Project . Deleting gen does not do it since IDEA saves the actual generated R somewhere else.
In my case, I added some classes from another project and I had to add the import to the R package from my actual project:
import com.youcompanyname.yourprojectname.R;
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:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ActionBarSherlockLibrary_4_3_1"
android:versionCode="1"
android:versionName="1.0">
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity
android:name="ACTIVITY_ENTRY_NAME"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
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).
I just restart IntelliJ and it magically solved.
Try it first.
Had same issue - the issue was the Manifest file was did not have the default Activity setup properly.
To all the hopeless people who have reached this far down the answers: I feel your pain. I have spent an hour doing nothing but trying all those things above as well as proposals from other sources. I have checked all my xml resources twice, cleaned caches, rebuilt a dozen times, even restarted the entire machine. Here is what actually worked for me:
Under 'Build Variants' (lower left corner), I selected a different Build Variant (in my case release instead of debug) for the target that had the missing R problem. Solved it.
I've refactored the packagename and intellij didn't update it in the manifest.
So if you've refactored the packagename then go to the manifest and update the attribute "package" in the root of the xml file save and rebuild it. If any errors occur then it's probably a wrong packagename in the import (at least this was my case) so just fix them
hope this helps anyone
In my case I had to delete the intellj compiler cache. on my windows machine it was somelike this:
%USERPROFILE%\.IdeaIC12\system\compile-server\<my project>
Try create new project and select "Create project from existing sources"
Adding my $0.02 just in case someone else has the issue I did. In my case I had generated the "Hello world" application using IntelliJ and forgot to change the package name from "com.example." I then used IntelliJ to refactor the package name. This caused the error to start happening.
So I did a global search for "com.example" and it was found in the AndroidManifest file as mentioned by others. However, changing this did not fix the problem. "com.example" was also found in "workspace.xml" under the ".idea" directory. I changed all the occurrences their, did a rebuild and then it started working again!
This seems like a bug in IntelliJ.
In Android Studio, my problem was when i copy pasted a class to use as a template to make another similar class, it asks to automatically import a bunch of stuff, most of which was not going to be related to the new class, so i said cancel. with it it left out import com.your.packagename.R; so R wasnt actually being imported into the file i was trying to use it in.
can be fixed with an alt-enter when clicking on R (it should be highlighted in red)
I'm struggling with getting the demo of the level 4 support library set up in Eclipse and running. Apologies in advance for the length; I want to completely describe what I have done. Would really appreciate the help of one of the experts here in SO.
Here is what I've done -
1 - Create New Project:
Rather than trying to let Eclipse "Create project from existing source" or "Create project from existing sample" and all the problems that seem to result from those project setup approaches I created a new project.
2 - 'src', 'res' sub-directories:
Deleted all files that were auto-created from these directories and then reproduced the folder structure and all files into the project from the sdk version of the Support4Demo.
3 - Added support jar
Created a sub-directory named 'lib' and added a COPY of the android-support-v4.jar to it. I then added this to the Build Path (this resulted in new folder named "Reference Libraries" with the android-support-v4.jar file in it.
4 - AndroidManifest.xml:
Replaced the auto-generated manifest with the one from the demo project directory.
Problem/Question
I get a warning from eclipse about the target API level in
Attribute minSdkVersion (4) is lower than the project target API level (13)
OK, I understand that one. (I want to be able to run this on a level 8 (or lower) virtual device. That's what this support library is for.)
But I also get an error in the manifest file that I can't make sense of -
error: No resource identifier found for attribute 'stopWithTask'
in package 'android' AndroidManifest.xml /Supportv4Demo line 226
Android AAPT Problem
The line in the manifest that this refers to is a Service reference -
<service android:name=".content.LocalServiceBroadcaster$LocalService"
android:stopWithTask="true" />
I'm not very experienced with Eclipse (and that's certainly part of my problem) but I suspect that Eclipse has tinkered with the includes somehow and that I'm not getting the proper package reference somewhere. I've inspected the class LocalServiceBroadcaster and it's 'includes' look like this -
package com.example.android.supportv4.content;
import com.example.android.supportv4.R;
import android.R.attr;
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
... more includes
import android.support.v4.app.ServiceCompat;
import android.support.v4.content.LocalBroadcastManager;
... more includes
How do I get this demo of the support libraries setup and running?
Thanks in advance for any help you can provide!
As you can see in the docs, stopWithTask is only available in API level 14 and above. Either change your target SDK level to 14 or remove that attribute. (It's nothing to do with the includes).
I'm busy trying to get the MapView included in my Android project. I'm following the MapView tutorial on the Android developer website but I'm getting an error:
'MapActivity cannot be resolved to a type'
I tried pressing Ctrl+Shift+O to auto import all classes but it's not helping. When I try to include the Maps libary manually it gives this error:
'The import com.google.android cannot be resolved'
I have added the following line (see below) to the Manifest and my target is API 7 (Platform: 2.1).
<uses-library android:name="com.google.android.maps" />
What am I doing wrong?
Thanks!!!
You need to reference correct library at compile time. But what you describe is asking Android to use this specific library at runtime.
You need to right click your Eclipse project, Properties -> Android. In Project Build Target select any target with vendor Google Inc..
Google API is a third party SDK. Choose third party in packages manager.
I am new to android development. I got an error when I wrote the code
import com.google.android.maps.MapView;
in eclipse. The error is The import com.google can not be resolved.
Please anybody give suggestion to fix this problem.
Bring up your project properties, and go to Android. Do you have an Android target selected that includes the Google APIs? Perhaps you just have a generic Android target.
As Jim said, you have to select "Google APIs" (which is Android x.x + Google APIs) instead of something like "Android 2.2" in your project's properties.
First you have to make sure you have installed Google API
Then set your project's properties in Eclipse to check off the Google APIs version of the SDK.
and Make sure you have include this library in AndroidManifest FIle
<uses-library
android:name="com.google.android.maps" />