Importing src folder into Android Studio - android

My Android Studio project was doing some funny business with the preview mode. I was getting lots of errors in regards to rendering the views. In just one Activity I would get about 50 errors. Long Story Short: I spent all day searching for a solution to no avail, but noticed that these errors only happen to that particular project. I thought - you know what, I'm just going to delete all the Android generated stuff and re-import my src files into a new project.
So I deleted them, but now I don't know how to import the src folder back into Android Studio! When I tried to import, Android does not create a gradle build for me. This is what I've tried:
Closed AS
Open AS
Click Import project (Eclipse ADT, Gradle, etc.)
Import project from external model -> Gradle -> Next
Use Local Gradle Build -> C:/Program Files/Android/Android Studio/gradle/gradle-2.10
Finish
I get a notice "Frameworks detected: Android framework is detected in the project. Click Configure -> select AndroidManifest.xml -> OK
In Project Explorer -> Android window - no files are present.
In Project Explorer -> Project window - files are present but has a red marking on them, I have no idea what they mean.
Example:
The run, build, debug buttons etc are all greyed out. This tells me that the Gradle build wasn't successful.
Anyway, after I restarted AS, I now get this event log:
Migrate Project to Gradle? This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
Why do I need to migrate? I told Android Studio to build gradle by pointing to the local gradle build?
What is the correct way to create a Android Studio project if you have source codes but not as an existing project in eclipse or android studio?

Maybe you should create a new project, then paste source files.

Related

How to import an Android Studio project from android.googlesource.com?

I'm trying to open the DeskClockApp (https://android.googlesource.com/platform/packages/apps/DeskClock/) in my version of Android Studio. However, since no gradle files are downloaded, Android Studio is struggling to see the project as an Android-Gradle app.
I've tried downloading the source code as a zip, importing it as Git from Android Studio's VCS, etc. The online repository doesn't have the gradle files b/c the developer added a gitignore for gradle (makes sense). I also considered adding the gradle files myself but the project structure seems to be slightly different than the structure defined online. When I first import that project it says Android Framework detected, however, on configuring it for Android it cannot find any module to run, or even display the correct files (in the Project view). Is there any way to generate the correct gradle files for this? Maybe run it without gradle?

Android Studio: Gradle suddenly can't link files and doesn't recognize module "app"

I've been using Android Studio on Windows 8 with this project for a couple months, and earlier today the sidebar suddenly doesn't show any of the project files (just the Gradle Scripts). At the same time, the Gradle build also keeps failing, with dozens of errors of the form "cannot find symbol class X". Finally, when I go into the "Build" menu, it only has a "make project" option but not a "make module 'app'" option, and I suspect that it is unaware of the module 'app' anymore.
This error persists when I switch to different Git branches of the same project, but not when I switch to a different project. I've tried re-importing the project (including deleting the .iml files and .idea folder beforehand), I've tried clearing out the folder and re-syncing, and I've tried reinstalling Android Studio.
I've included a screenshot below that shows some of the Gradle errors and the sidebar that doesn't contain any of the project files.
Try cleaning project by selecting clean project option under Build menu.
Also try building after deleting builds dir in the project.

Gradle sync failed in android studio

I am using eclipse for developing android applications.Its works good and I can debug and run the application.But now I installed android studio and move to creating new apps using android studio,But i get the following error
Gradle sync failed
What is gradle and how can i fix this problem, Now also I can't import my eclipse project to android studio
I had the same issue when importing my project from eclipse to android studio. I'll tell you how I fixed it. It's simple.
- Solution 1: It is possible to import your project from eclipse to android studio, but android studio version 1.2 currently has bugs with that. What I did is I created a new application with the same app name, same package name, same minimum api and all these things... Then normally, go to your app's folder that you want to import it from eclipse, and copy it's src folder and java folder, maybe asset and libs folder too if you have them, and paste it to your newly created project in android studio by going to that folder: "Users/AndroidStudioProjects/appname/".
If that's not your issue, try the other following solutions:
- Solution 2: Add this to your gradle.properties file in the project. This will just increase your android studio's memory:
org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m
You can also replace 512 to 1024 if you have enough memory in your pc.
- Solution 3: Try to close all your pc apps that consume large memory, and try that: In android studio, there is a toolbar at the top, where there is "Build" tab. Select Clean Project then Rebuild Project. Then try to sync your project again.
If you find the File Encoding Error is showed in your log when trying to sync your gradle, click on it and change the project formatting to UTF-8.
Source: https://stackoverflow.com/a/30498383/4843993
I would prefer to start solution 2 then 3 first before trying solution 1. If you still face the same issue, tell me. :)

Importing and converting Eclipse-made Android project from Github to Android Studio Gradle-build

I'm trying to migrate from using Eclipse for my Android-project to the new Android Studio, and I'm having an issue related to Gradle.
What I want is for me to push the latest Eclipse-build to Github, and then be able to pull it down in Android Studio, having the latter automatically convert the project to a Gradle-build. If I'm reading the documentation right, the Android Studio import is supposedly able to do this.
When importing, I can choose between "Create project from exisiting sources" or "Import project from external model"
If I choose the first option, the project won't use Gradle (as far as I can see). If I choose the second, it seems to be looking for an already existing gradle buildfile "build.gradle" in my project.
So - Should I download a Gradle-plugin to Eclipse and make a gradle build-file there, or am I doing something wrong in the import?
It seems the only other questions I can find on SO is about importing and Eclipse export or simply how to pull a project from Github in Android Studio.
Thanks :-)
Importing and converting an existing Eclipse project into a Android Studio Gradle project is quite simple :
File -> Import Project (in Android Studio)
Select the manifest of your Eclipse Android project.
Done.
There may be some dependacy management to deal with.
You can also take a look here :
How do you import an Eclipse project into Android Studio now?
How about this:
clone repo to location 1
export from eclipse
import to android studio in location 2
copy the .hg files or whatever's applicable from 1 to 2
commit from location 2 including deleting eclipse files
Now the repo will have the android studio project and not eclipse.

Convert a project to Android Studio

I'm trying to open the following project https://github.com/mik3y/usb-serial-for-android on Android Studio but all the things I try it give me errors related to gradle :s
It says version 0.9.0 introduce some incompatible changes but then I can't make the changes they said.
Can anyone try it to me?
The biggest issue is that Android Studio uses Gradle and Eclipse does not. It sounds like the GitHub project was built with Eclipse, which means you first have to import that project into Eclipse, then export it with the Gradle files.
From the Android docs
Export from Eclipse
Update your Eclipse ADT Plugin (you must have version 22.0 or higher).
In Eclipse, select File > Export.
In the window that appears, open Android and select Generate Gradle build files.
Select the project you want to export for Android Studio and click Finish.
Your selected project remains in the same location but now contains a build.gradle file and is ready for Android Studio.
Import into Android Studio In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.
Click Import Project. Locate the project you exported from Eclipse,
expand it, select the build.gradle file and click OK. In the following
dialog, leave Use gradle wrapper selected and click OK. (You do not
need to specify the Gradle home.) Now that your project is imported to
Android Studio, read Tips and Tricks for some help getting started.
Note: It's possible to import an existing Android project to Android
Studio even if you don't generate a Gradle build file from
Eclipse—Android Studio will successfully build and run projects using
an existing Ant build file. However, in order to take advantage of
build variants and other advanced features in the future, we strongly
suggest that you generate a Gradle build file using the ADT plugin or
write your own Gradle build file for use with Android Studio. For more
information about the Gradle build system, see the Gradle Plugin User
Guide.

Categories

Resources