Android Studio not recognising Gradle projects - android

No matter what projects I import they never work - Android Studio is always flagging this is not a Gradle build project.
I select VCS -> GIT and clone the repo without any problem. I then go through the wizard with no issues (I select create project from existing sources), creating my code base with a warning, below. When i try to run throws all sorts of errors.
Migrate Project to Gradle? This project does not use the Gradle build
system. We recommend that you migrate to using the Gradle build
system. More Information about migrating to Gradle.
Don't show this message again.
When I go to the link it makes no sense whatever to me, it says to create an arbitrary Gradle file and populate it with my references (I think), which is out of my understanding. I shouldnt have to do this as it says in the repository instructions that it is in fact a Gradle-based project.
The project I am trying to clone is
https://github.com/googlesamples/android-play-location.git
Can anybody tell me specifically how to import and run the following git repo in Android studio for example?

Ok from the start (as i dont know what other way works)
Go to Git master page (it has 'download to zip' or 'clone to desktop' button). use https://github.com/googlesamples/android-play-location as a test master page if you like to ensure you have no other issues i did not.
Click 'download zip'
Unzip the project
Close the current project in Android Studio -> File/Close Projects
A popup screen like this will appear, choose Import Project (Eclipse ADT, Gradle etc.)
You will be asked to select the project, select your unzipped project within the master folder, eg basicLocation
Select 'create project from existing resources' default
dont change project name (may cause issues)
Next through 'import project -> directories'
Next through project -> libraries
Next Through import projects -> modules and module dependencies
Next through import project ->SDK
Next through import project ->manifest.xmls
Android Studio starts. Ensure the configurations dropdown has a project in it called 'app' app
Select 'sync Gradle' icon (green circle)
May get language warning, ignore or accept restart, doesnt matter
At bottom it should now say 'Gradle executing tasks' after which it will run on device or emulator :)

Short answer: File > Open > the build.gradle file you just cloned with the repo
I just wanted to add this, because I had the same problem, and even if Fearghal´s answer and comments pointed me in the right direction, I think he may have added unnecesary extra steps, i.e. Download as ZIP, Close current project, etc.
Simply put, you VCS > Git Clone, and then open the build.gradle file. That´s it

This can happen for many reasons. I typically see it when I move the directory. The easiest way I have found is to close the project and then reopen it using "Import project (Gradle, Eclipse, ADT, etc.) menu item then selecting the folder. This will force it to reimport the project and fix any metadata/configs.

What worked for me was
On Android Studio
Open the settings.gradle file
include your project
include ':myproject'

Well, as Android Studio correctly says, https://github.com/googlesamples/android-play-location is not a Gradle project.
Any subdirectory of that repository is however.
They are different projects.
So clone that repository and import one of its subdirectory in Gradle.

Related

Import Android project not select 'copy project into workspace' error

I have a problem with importing Android project to Eclipse in three scenario:
I have clone my Android project from Bitbucket and synchonized with Eclipse workspace successfully! But the project raise many error.
Then I remove my project and using import function in android (File>import project). I import the project from repo and also check to 'copy project into workspace', awesome! the project work perfectly.
Then I testing again. I also use import function and not check on 'copy project into workspace', oh no, the project keep the error like scenario 1.
We've always had this issue - however, we face it in P4 SCM.
I guess the problem would be the same, anyway - your project may not be detected as an Android project.
First create a new Android Project. Now, go to Navigator in Eclipse (Window -> Show View -> Navigator) and open .project file - copy it's contents and paste in your (imported) project's .project file. This should fix it.
Make sure to make the required changes (the project name is the only change we usually make) after copying.

Import an eclipse android project with version control system into Android Studio

I am trying to import an eclipse project with version control system into Android Studio.
Support for direct eclipse project import was added in Android-Studio version "0.5.5" where we don't need to export project first from eclipse to import it into Android-Studio.
I have an eclipse Android Project which I am trying to import into Android Studio.
Import is successful but imported project no more has version control.
Edit:- More detail
Suppose I have following Directory Structure
Project ----
|---------- .git/
|----------- MyApp
|------------MyApp_imported
During project import, I point Android Studio to Project Directory "MyApp", It copies all files in my project "MyApp" to new directory "MyApp_Imported". But imported project doesn't have version control enabled.
Now I am not sure how to proceed further.
How should I tell Android Studio to use old repository for imported project.
A step by step guide to do this will be very helpful .
Here is text from Android Tools Project Site
Project
- Importing modules should now work properly. You can import existing Eclipse
ADT projects as well as Gradle modules into an existing Gradle project;
it will copy in the sources as is done for full project import, as well as
handle dependencies transitively. Import modules either from the project structure dialog or the File | Import Module action.
- New project structure dialog implementation: Should be faster, includes
Gradle sync notification, should only perform a Gradle sync at the end
when necessary, and won't list invalid IntelliJ module warnings as before.
This is actively being worked on and the individual editors
(for flavors, build types, signing configurations etc) will be improved
in upcoming builds.
Here is the step by step solution to do it.
Open Android Studio -> Import Project-> Select your project directory. (In above case "MyApp")
Remember Select the directory which contains Manifest file otherwise new "direct import wizard" doesn't
get triggered and android studio uses old import wizard.
Android Studio will create a copy of your project "MyApp_imported" with new directory structure.
Copy your existing ".git" directory inside "MyApp_imported"
Android Studio -> VCS -> Enable version control
This will make Android Studio use your existing repository for imported project. Though imported project has
different directory structure but git handles them pretty well.
You might want to also call git add . and git add -u in the root folder of the imported project to make sure all new files are added and existing file moves are detected by git.
Android Studio -> Changes
Review all files and commit. Git will automatically handle new directory structure and file history etc will not be lost.
Now you can share it on github/Bitbucket by
VCS-> Share it on GitHUb
Note:- For bitbucket you will have to install "Bitbucket plugin" for Android Studio.
Couple of months ago I got my job as android developer.The first problem i had faced were my collegues who using Eclipse.I was allowed to use Android studio if I will not make any changes to existing project structure.After 3-4 attemps I finally found a decision.Here is steps to open Eclipse git project without migrating to Gradle and without changing project structure.
Clone git repository of project
Add /gen and /.idea to .gitignore
Open any of already created Android Studio projects.
File -> Open -> Choose path root project folder(with src and res inside)
Doble-click project to open project structure
Select root project folder -> F4
Project -> Project SDK -> Android API XX Platform && Project language level -> Override in interfaces
Modules -> Sources tab. Mark src as Sources && res as Resources.
Modules -> Paths tab. Use module compile output path.Create folders output and output_test inside gen folder (create gen if folder not exist yet).Output paths should look like C:\Users\User\project_rep\project\gen\output
Modules -> Dependencies tab. Click "+" -> Jars or directories.Select all .jar libraries which are using by your project.(Android Studio can pretend like its added only one jar but thats not true)
Facets -> "+" -> Android
Facets -> Structure tab -> Reset to defaults.
Close Project Structure window.
Run -> Edit configurations -> Android Application -> Module -> Select your module.Target device -> Show chooser dialog.
Edit configurations -> Before launch -> remove Gragle aware make, add Make.
Finally, after all of those steps you are able to hit Run button.Enjoy!
The import process does not make this easy. But here's something to try:
Let Android Studio do what it wants to do. It creates a file in the root of the new copy of the project which shows what was moved where.
Make a fresh (scratch) copy of the original git repository. Use "git mv" commands to duplicate the directory structure changes which Android Studio made. Commit the changes.
Copy the resulting .git directory into the project made by Android Studio. Use "git status" there to see how the result of the import process differs from what you did in your scratch copy of the project. At this point you might just choose to commit the remaining differences right there.

Android Studio The project is already registered

I've a big problem with Android Studio.
I have a project that depends on two other projects (as libs).
I followed the guide Problems importing project into Android Studio regarding ActionBarSherlock for import external modules.
I opened "Project Structure", imported the module, but after that I can't see it in the Modules area.
The Modules area contains only the root module, seems it is not refreshed (this is strange). So if I try to add the module as a Dependency, Android Studio doesn't find any module!
Then, if I try to re-import the module, it says that the module/project is already registered!!
Maybe I'm missing something, but I don't know what....! I have this problem both on Windows and MacOSX.
Thanks in advance,
Federico
Look around in your .idea directory for mentions of the problematic project. I had the same problem and resolved it by deleting the entry from .idea/sbt.xml.
In ij go to menu: View -> Tool Windows-> Gradle
Right click on the problematic module and click Refresh External Project, You should see the module in project explorer.
I had a similar problem with ABS and other library imports. The 'Project Structure' interface just wouldn't show the modules. On trying to import the modules, it would prompt, "The project is already registered". Seems to be an IntelliJ/Android Studio issue. Invalidate Caches option didn't help.
Reimporting the project after some cleanup did work for me.
As a precaution, take a backup of your project and store it safely
Ensure that your project builds via gradle command-line and you have all required dependencies specified in respective build.gradle files. Try building with: gradle clean && gradle build
Close the project in Android Studio (or close Android Studio)
Delete .iml files and .idea folders from all modules and the main project
Start Android Studio and reimport the project (Import project from external model > Gradle)
you should remove the project from respective gradle/sbt/maven/ant tab (used to be on right vertical line of Android Studio/Intellij IDEA)
See this answer: https://stackoverflow.com/a/30442195/907576
My issue was fixed when I restart IDEA.

What is Android Dependencies? Remove it from Build Path, ClassNotFoundException occurs

I'm working on a team project. I included a .jar file in Build Path and committed to SVN. When I updated code in my working directory, a new folder appears in Eclipse called "Android Dependencies". If I let it be there, my program runs; If I remove it, my program reports a ClassNotFoundException.
Now how to fix this ClassNotFoundException?
For the people whose heart dropped when they read the comment that deleting the Android Dependencies virtual folder will destroy your project, there is an easy fix.
Right click on the destroyed project
Select "Android Tools > Fix Project Properties" in the dropdown
I hosed my project dependencies when trying to set up my git repo, and this is fixed it.
Android Dependencies is a virtual folder where Eclipse shows what JAR files the project depends on. It's not a physical folder; you won't find it on your hard disk. And the folder is not checked in into Subversion.
Do not delete that folder. You will destroy your project.
To fix it, just revert to an older Subversion revision and check it in again.
I've had a similar problem after setting up a git repo with my project.
The problem was that the appcompat import lost its folder reference.
If the 'Fix Project Properties' mentioned doesn't work for you try this:
Go to Project > Properties
Go to the 'Android' tab
Under 'Libraries', if there's a red 'X' next to the appcompat folder, remove
it then hit 'add' and add it in again. The reference should show a
green tick now.
Save and clean the project if needs be
If you also have marked project build target below API level 16 in the Android project properties, the error is going to come because prior to this level, there was no Android dependencies.

Eclipse - HelloWorld - Android error?

I created a Hello world app but get this strange error:
The project cannot be built until the build path errors are resolved
I haven't changed the project, jut created it and tried to run it.
to avoid that annoying problem i have 3 solutions that worked for me.
Solution 1)
delete your generated R.java file
inside your gen/ folder
Solution 2)
a)Delete your project from Eclipse
(i said ONLY from Eclipse, uncheck option: Delete project
contents on disk)
b) import your project to Eclipse:
file > Import > Existing Projects into
Workspace (Look for your project
previously deleted from Eclipse) >
Finish.
Solution 3)
make Solution 1 then Solution 2
It is either a spurious message you can solve by forcing Eclipse to recompute its library paths
I found the resolution for this at Scott D. Strader's blog.
To summarize the solution I only needed to add a library to my project and then remove it to force Eclipse to perform the necessary actions to resolve the problem. I would post the detailed steps here but I don't want to steal his content.
The resolution was to force a resave of the selected projects (and their .classpath files):
Open the project properties
Select Java Build Path > Libraries
Add a new, arbitrary library (to be deleted later) > OK
Wait for the workspace to refresh (or force a refresh of the project)
The error(s) will go away
Remove the dummy library
Note: as the OP mentions, a simple restart of the IDE can be enough.
Or you actually miss one critical library like a JRE library:
I needed to add the JRE library to the project for it to run. Not sure if this was due to the updated version or something else…. Any way this fixed the issue:
Project > Properties
Java Build Path
Libraries tab
Click add library
Select JRE System Library
Next
Finish
Sounds like you are missing an import or a jar. In your project in the project explorer there should be a red x on the file icon that contains the error.
In addition to the listed answers, there is one other scenario I've seen this error appear when using the sample projects included with the Android SDK. For some reason, the generated R.java file can be invalid or corrupt. You can get around it by expanding the "gen" folder in the Package Explorer and deleting the R.java file. It will immediately get regenerated and the error goes away.
Right click on your project, choose "Build Path", "Configure Build Path" -> and choose Android 2.2, or that target you specified when you created your project
I have had similar issues. for me simply closing the emulator and re-running the project works

Categories

Resources