Android Eclipse Import Existing Code - android

I am trying to organize my code for SVN so I can work from multiple locations without issue and potentially add more developers. The problem is that I can't get the code into a new project easily. I am trying to create a project from existing code.
Once I select the folder, the "main activity" shows up, but I can never use it. I've tried deleting all the .project files and what not in the folder as well, but the thing is always greyed out and I can never get it to import.
Why is it greyed out? What do I need to do to get it to import?
-- ADT Build v21.0.0-519525

I played around with this a bunch and found out that it was conflicting with another similarly named activity that already existed in the workspace. The error message "Select at least one project" was covering up that message. It would appear very quickly and then switch to select at least one project.
To get around this, I deleted all the projects from my workspace. I didn't know which one it was because I am making an app that is being versioned and branded for different companies.

I had a hard time with the same problem with TrivialDrive. Try to check "Main Activity" from the project names you have in your workspace. if it exist, you'll get this error.

Solution A:
1) Close Eclipse,
2) when it starts it will ask for new working directory, choose something different then your default one.
if it is not asking for "new working directory"
Solution B:
1) Go to File > Switch Workspace > Other
2) Choose a new Working-Directory (not the same!)
After that it should be possible importing projects

Just delete the ".project" file in your project folder (it's hidden on Linux, use "ls -a" to show), then from Eclipse, choose Create Android Project from existing source.
It worked for me..
Thats it.Cheerzz..

It's grayed because project name equals to the name of existing project within workspace.
Solution: Use "Existing Android Code Into Workspace" import. Type "Root Directory". Change "New Project Name" field directly in Import Projects wizard. Do the following: first press path text (right from checkbox) in "Project to Import" field then go to "New Project Name" field to change name.

just go to eclipse-workspace and delete .metadata file
restart eclipse
open project

I had this problem when I needed to build an apk file as a one-off from an svn tag. I managed it by creating a new workspace and switching to it. After that New->Project->Android->Android Application From Existing Code worked as you would hope.

Related

Can't get application to find android.support.v7, won't find appcompat_v7 project

I'm trying to create an Android application in Eclipse (on Windows Vista), and I can't get it to find the android.support.v7 library stuff that I need. I think I'm setting things up correctly, and what I'm doing works on one computer but is not working at all on another, and I need help figuring out where things are going wrong.
In Eclipse, I followed the steps to create a new "Android Application Project", and selected API 11 as the minimum SDK, and went through all the other steps. (For "Create Project in Workspace", I unchecked it and asked for the files to be created in a location on a network drive, in case that matters.) This created another project, appcompat_v7, which I understand is how things work now. I built that project. But then when I tried to build my application, I couldn't get past The import android.support.v7 could not be resolved errors.
Here's the symptom that concerns me: I right-clicked on the application project and selected Properties -> Android. The bottom part, "Library", has "C:\users\me\workspace\appcompat_v7" in the left (Reference) column, and a question mark in the right (Project) column. [This is the workspace directory, not the network-drive directory where I'm keeping the files.] Also there's a red X next to the pathname. I tried selecting Add, which brought up a list including the appcompat_v7 project that got automatically added. I selected that, and it got added to the list with a green check mark. Then I selected the other one and Remove'd it. Now the list had just one appcompat_v7 project, with a green check mark, and the correct name in the right column, so everything looked OK. I clicked OK (also tried Apply then OK). But when I went to Properties -> Android again, now the red X was back and the project name was ? again. So it seems that something it was able to find just a few seconds ago could no longer be found (?). Rerunning Eclipse hasn't helped. The workspace\appcompat_v7 directory and its contents seem to show up normally in a dir command, although if there's something missing I wouldn't know what to look for.
Any suggestions about what to try, or what to check for?
EDIT: By experimenting, I've found more information. Apparently unchecking "Create Project in Workspace", and then selecting a network drive, is what causes the problem. If I start with a clean workspace, and uncheck "Create Project in Workspace" and select a directory on the C: drive, everything works fine. If I do the exact same thing but select a directory on a different drive, such as a network drive or USB flash drive, the problems show up.
After more research, I've concluded that this is a symptom of Android Issue 16472, in which things fail if you have a project on one drive and a library on another drive. The new mechanism, in which the ADT plugin creates appcompat_v7 automatically when you set up a new project, exacerbates the problem. If the workspace is on the C: drive but you want the project files to be on some other drive, by unchecking "Create project in workspace", the plugin will put the project files on your other drive but create appcompat_v7 on the C: drive, which automatically causes the problems reported for #16472.
It's probably best to set up the workspace on the same drive where you put the project files (but I haven't tested this; and in any case, having them on different drives hasn't caused a problem for me, for non-Android Java projects). However, I've found a way to work around this, by copying appcompat_v7 to the other drive:
Use the Android Application Project wizard to create a new application, and let it create your project and a new appcompat_v7 project on different drives.
Using Windows Explorer or some other method, copy the newly created appcompat_v7 from C: to someplace on the other drive.
In Eclipse, delete the appcompat_v7 project.
Import -> Android -> Existing Android Code into Workspace. Browse to the location where you've made a copy of appcompat_v7, select it, and do the import. I found that it called the new project android-support-v7-appcompat, but this is OK. I waited for "Building Workspace" to complete (if you're set up not to build projects automatically, you may have to use Build Project on the new project).
Right-click on your application project, "Properties", "Android". The "Library" section will probably have a path name (the path of appcompat_v7 on the C: drive) with a red X by it. Click on Add; a window with android-support-v7-appcompat should show up; click on that. It should be added to the library list with a green check mark. Now select the path name on the C: drive, and click Remove and then OK. I'd double-check by clicking on "Properties" again, to make sure the library shows up and still has a green check mark.
After you do this, if your workspace is set up to build automatically, this should build your application successfully. (Otherwise build it manually.)
If you later add another application to the same workspace, you don't need to repeat steps 2, 3, or 4. After the wizard creates your project and another new appcompat_v7 or appcompat_v7_2 or something, use Step 5 to add the android-support-v7-appcompat you've already imported and remove the old library reference, then delete the duplicate appcompat_v7 that it just created. (See also Remove v7 appcompat folder.)
Add the library to your application project:
In the Project Explorer, right-click your project and select Properties.
In the category panel on the left side of the dialog, select Android.
In the Library pane, click the Add button.
Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
In the properties window, click OK.
If you open Java Build Path dialog for the android-support-v7-appcompat project it should look like the one on the picture below.
I know this is a bit old but if anyone had the same issue I fixed like this:
From gradle leave just the last V7 (mine is compile 'com.android.support:appcompat-v7:23.1.1'
and I deleted compile 'com.android.support:appcompat-v7:22.2.0'
) after that go in your class and delete the import v7...after sync again and you will see that Android Studio will ask automatically you if you want import the new Dialog.
I hope this simple case will help someone.

Cannot create new project - There must not already be a project at this location

I am trying to start using the just released Android Studio, I have already established the location for the Android SDK, and the Studio opens correctly.
Now, I want to create a new application project, but I cannot figure out what to select as project location.
Steps followed:
Launch Android Studio
Select New Project
Enter Application Name, Module Name, Package Name.
Click on the '...' button to select a project location
Select the appropriate folder I created for the project, which is empty. See Screenshot here of the dialog at this point.
Clicked Ok on the dialog, and now I am prompted with a second dialog, that is now labeled 'Select Path', where previous dialog was labeled 'Please choose a Project Location'. No matter what folder I select, the option for 'Ok' is grayed out and cannot be selected. Image here.
I read a similar question, and I am making sure, as you can tell by the steps I followed, that I am entering the path at the very end, and it still won't work for me.
I really think there must be a silly thing I am missing here, not sure what it may be though.
Any ideas?
So, apparently what caused the main problem is that the first time I launched Android Studio I didn't create a new project, I imported one, and that seemed to screw the whole workflow of it.
As per someone's answer, who was apparently removed, here are the steps.
Go to C:\Users\Username\ and erase the folder named: .AndroidStudioPreview.
Launch Android Studio again, it will ask if you want to import any settings, select the option that doesn't import anything.
Optionally Configure, Project Defaults, Project Structure, Platform Settings, and make sure that both the JDK and Android SDK are configured, for instance, I had to point Android Studio to a folder where the SDK had already been downloaded.
Create new project, and leave the default workspace that will now show, it should be C:\Users\Username\AndroidStudioProjects
That's it, just go through the setup wizard, and you're done.
This is a really simple issue. Android Studio likes to create the folder for the project on its own. That means you can't just select a pre-made folder. For example if you select C:/Android Projects with Android Projects being a folder, you must append a folder name to the location for Android Studio to create, for example C:/Android Projects/NEW PROJECT
No work-arounds needed.
I have found a workaround.Here's what I did :
Click on check out from version control.
Select git(I have a bitbucket account,but might work with github).
Put in repo-url
Select the parent directory(this directory will also become the parent directory of your android projects)
Then click clone
Select YES when asked if you want to create Android studio project from existing sources.
Select Create Project from existing sources
Don't change anything,select Next and then Finish.
Now it will create a new project at your selected location
Close android studio,go back to your parent directory and delete the project folder.
And now start your new project wizard,you should be able to see your parent directory listed in project location.Start typing details about your project and the directory will be updated accordingly.
I had the same issue this morning when trying to create a new project and found a simple way to get around it.
Choosing the path to the project folder was impossible as I kept getting the same error message 'There must not already be a project at this location'. What I then did was type out the path manually, but not all at once. To begin with I thought I'd just try to set a folder at the root of my drive eg. C:\AndroidStudioProjects. It seemed to be ok with this, which led me to try to add the rest of the path manually as well. So the final path would be something like C:\Development\Android\AndroidStudioProjects
This worked, no errors showed up and it let me go through the rest of the set up.
Hope this works for others out there who are facing the same issue.

Eclipse/Mac/Android: Deleting a project and recreating one with the same name

I'm a complete newbie to Eclipse and Android development and I've been trying to delete a project and then creating one with the same name again. I choose to delete the project from the workspace and the dir/files are indeed gone. The new AndroidManifest.xml file though has the original contents appended as does the layout XML file and generates parsererrors rightaway!
Are references to the project file somehow stored outside the workspace dir itself that I can delete by hand?
If I restart Eclipse after deleting the project, it doesn't give me this problem
When you delete a project from the eclipse it shows you following dialog box,
If you have selected(ticked) the option as shown in the image, it will delete all the files and folders of the project from the workspace. You can not get back once you delete it. But if you haven't selected this option then it will only delete project from the project explorer/package explorer, but project files and folders are safe there in the workspace which you can later get it by importing in the eclipse.
Once you delete the project from the Workspace, in Windows it's at the User main Workspace/[The project] once you delete, your project goes to dream land. so you restart Esclipse and make new one with same name, thats not an issue.
Umm, try searching in your mac about the project name, or go to the workspace and delete it, it should be enough.
I found this, take a look at it, please:
How to delete Eclipse completely (including settings and plugins) from Mac OS X?
Sorry, but you can delete Eclipse, and re-install it as a secondary option, if u deleted the Dir, and your project name is still in-use x.x
EDIT: in the link it says that you can change the workspace to another place, so I suggest you change the workspace place or delete the whole workspace after u take a backup of it.

Erased project from Project Explorer and cannot re-import it

I erased a project from the Project Explorer, because I didn't think I had everything in the Workspace folder that it needed. I was getting error messages. When I got the complete project into the workspace folder and tried to re-import it I get this message: "Some projects cannot be imported because they already exist in the workspace."
The three folders of the project show up in the window, but are greyed out and cannot be selected.
Thanks to Arun and Francis below.... but new problem
OK. Great! Got passed that one deleting from hard disk and creating a new workspace folder. But now when I try to run it as an Android Application I get the message, "No compatible targets were found. Do you wish to add new Android Virtual device? And in the Console: "Failed to find an AVD compatible with target 'Google APIs'." I'm really new to this so thanks for whatever patience you have to answer newbie questions.
Try back up your project folder and delete the project completely from project explorer and from the hard disk. Make your backed up project folder into a zip file and try re-import it and recreate a separate project copy in your workspace. If this doesn't work, try switching workspace...... :)
So it sounds like the project is still there in the workspace, so try deleting it again. When you delete it, make sure you select the option "Delete files on the disk", this will actually remove the underlying file in addition to just removing the project definition from the workspace.
If you still have trouble (that is, the project is still there), delete the files from the workspace associated with the project by hand (in the operating system). And then Refresh the project and try deleting it from the workspace again (don't select the option to delete files on disk). It should be gone then.
Once the project is gone from the workspace and the underlying files are gone, try your import again.
If you use working sets, make sure they are all deselected. Only the projects from the current working set will display in Project Explorer. By having no working sets selected you can see all the conflicting projects in Project Explorer and delete them by hand. Then re-import.

Missing AndroidManifest.xml when importing an old Android project into Eclipse

I have an Android project developed on Eclipse (GNU/Linux) that I last touched half a year ago. I am trying to import the project into Eclipse 3.6 on Windows (with ADT installed) installed using File -> Import Project in Eclipse. When the project is imported, I see the following error twice on the console:
[2010-12-10 02:17:12 -
com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper]
Unable to read C:\Program
Files\Android\android-sdk-windows\AndroidManifest.xml:
java.io.FileNotFoundException:
C:\Program
Files\Android\android-sdk-windows\AndroidManifest.xml
(The system cannot find the file
specified)
Why is Eclipse looking for AndroidManifest.xml on the Android SDK path? The file actually seems to be in the project's directory. How do I fix this problem and get the project to compile?
A simple solution is to either reimport the AndroidManifest.xml file or make a change to the file and save it. This worked for me.
If you see an error about AndroidManifest.xml, or some problems
related to an Android zip file, right click on the project and select
Android Tools > Fix Project Properties. (The project is looking in the
wrong location for the library file, this will fix it for you.)
from: http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html
The way you are importing the Android project into Eclipse is wrong. The Correct way of doing is File -> New Android Project. In the Contents Tab in "New Android Project", select "Create project from existing source" and choose the Build Target. That should fix your problem.
It appears that this error is produced because Eclipse thinks the default location for new Android projects is the Android SDK path. Even if the project location is changed, the error fails to be resolved, so the trick is to change the project location before Eclipse is aware of the condition generating the error.
To circumvent this quirk I imported the old project with the following steps:
File -> New -> Android Project
Un-check 'Use default location' and browse to project root directory.
Click 'Create project from existing source'
It's important to do step (2) before (3) otherwise the error persists and prevents running the project.
I had the same problem, all of the above did not work. I cleaned the project and it worked.
Instead of using File ---> New Android Project --> "Create project from existing sources", which will result in the error your are seeing, choose "Create project from existing sample" and choose it from the drop down. This will work.
Experienced JAVA developers tend to go with the first option which is normally there and works for classic Eclipse projects. But this is not your typical project and I bet the Google developers put this special case in the wizard to accommodate the differences.
I had the same problem. I was trying to compile the JakeWharton view page sample, so I checked out the GIT in a directory in a different folder then the workspace which caused the problem.
Eclipse was maintaining 2 folders:
1. A new workspace folder was made under the workspace directory, which eclipse checks for libraries and others source code including the AndroidManifest.xml file
2. The existing folder which was not under the Root workspace
To fix the problem after importing I had to manually move the files in the new workspace folder created by eclipse.
I met this problem when using Facebook SDK, now I solve it by doing this:
Close the project;
Copy "AndroidManifest.xml" file to the project's root path;
Open the project and refresh it, it's Done!
this worked for me by the way:
I changed the project name to the exact name of the project that I am importing.
Eclipse seems somewhat fragile in its naming conventions. One of the causes for this error is a difference between the project name and the folder name in the workspace. I imported a zip file for a project named "HelloDialogs" into a workspace folder named "HelloDialog". This caused the "AndroidManifest.xml file missing" error. Once I renamed the folder correctly, everything worked fine.
Because of the multiple different answers here, I thouhgt I'd add yet another one that worked for me, as I had exactly the same issue when first working with Phonegap android dev tools.
So I found (as mentioned by Gintautas in comments to the accepted answer), that I had to create a new project using the phonegap 'create' script, then when importing the project into eclipse. the only way to get this to work successfully was if the project was originally created in some temp folder somewhere other than the place I actually want to work with it.
So I created a project in windows like this in a cmd window...
c:\phonegap\phonegap-2.6.0\lib\android\bin>create.bat c:\temp\android_boilerplates\test app.test test
Then I imported the project in eclipse like this...
File > New > Project
Within the new project wizard select: "Android Project from Existing Code"
Click "Next"
Now navigate to the temp location of your project and set that to the root directory, check the project you want and check "Copy projects into workspace" as the example below...
Click "Finish"
And that's it, Eclipse should copy all your project files into your workspace and there shouldn't be any errors in your project (fingers crossed).
Your project should look something like this...
Hope that helps, it took me an age to work out why Eclipse didn't like creating a new project from existing code when the new project was being setup in the same place as the existing code. This isn't a problem for other languages I've used, so it was a little weird, but understandable as Eclipse (I'm guessing) seems to want to overwrite certain files.
Eclipse randomly decided to make another folder instead of the one that i had specified, but doesnt have any resources or data or layout etc in it..
it has some conflicts i guess..
anyway, a noob approach to this was, copying the original file to some other location(i put it to desktop)..
now create new project-create existing project, select this one from desktop, n VOILA.. its all fine.. :D
I am a little late to this game but I caused this same problem by generating the initial application into the exact location I was going to work on it. That is to say I put it directly into my current workspace. I then did File, Import, Existing Android Code Into Workspace. The import process blanked out my android.xml file.
I tried above solutions and had no joy. I then generated the initial application into a temp directory and imported from there. This worked for me.
The only way to import a project into eclipse workspace is to create an empty project and then drag and drop all the folders and files into this project. Why is this so is beyond me.
The answer from Raunak is wrong.
I found a .classpath file in the root directory of my Android project. I opened it and updated the file paths in it, and it seemed to fix the problem for me.
I had the problem when I tried to update an old project with recent code from the SVN. I had the Manifest.xml exported to my local file system as backup and deleted it. I've then reverted my complete project to the most recent version from the SVN and then it worked :)
This is what I had to do to get this to work. Fortunately I had backups of earlier "project".
1) Import the project as usual.
2) If the errors with empty xml etc. comes up, close the project.
3) Go to the original project if you have backup.
4) Copy all of the projects root files and directories and paste it over where Eclipse expects the projects root directories and files to be.
5) Open the project and refresh. Make "Clean" if necessary and you're done!
Always make backups because Eclipse f--kups! I learned this the hard way when suddenly my Android project refused to work because of empty manifest-file.
Sometimes if you automatically fix imports in MainActivity IDE imports android.R class instead of one that will be generated for the project. Remove the import and recompile.
when importing project from another workspace add existing project in workspace. and tick to the copy projects in workspace.then check the api level and supporting library from project.properties files.then rebuilt project and clean it.. it is works for me.
2017 Solution: Much Easier and tested solution is to remove your application folder from elipse project only then Import it again and the problem will be fixed immediately!

Categories

Resources