I'm just migrating to Android Studio, and I'm a bit confused about how to manage my projects / modules.
For example, in Eclipse I would have 3 projects:
Library project (has a couple of jar libraries)
App project 1 (uses the Library project, plus some other jar libraries)
App project 2 (also uses the Library project, plus some other jar libraries; does not use App project 1)
So if I understand correctly, I would create 2 projects in Android Studio, one for AP1, one for AP2, and in both projects I would add the Library project as a module?
When I do that, I suddenly get two Facets in the Library module called Android and Android2. What does this mean?
Also, if I go a bit further, and add multiple libraries as modules, I get (in the Libraries tab under project settings) multiple libraries, libs, libs1, libs2. These may contain double jars, which AS complains about.
If anyone could clear some stuff up, that would be great. Thanks!
You can see a Module in Intellij as a Project in Eclipse.
And a Project in Intellij is the sum of modules that make your project run.
When you create a module from existing sources, Intellij will add it's module.iml configuration file to the specified location. Then all the configuration you have done on this Library module will be re-usable when importing this module in another Intellij project.
I know this post is quite old, but still I found it when facing similar problems as Niek. The structure of my project is similar to Niek's, with a Library, a "Full" app and a "Lite" app. The following describes what I did migrate from Eclipse Luna to Android Studio 1.0.2, with Android SDK 21.0.3.
If this can help someone popping on that subject, It would make me a happy man!
Create a Android Studio new project
Select the "app" module, hit F4 to reach Module Settings
Select "app" in the module settings and click the "-" button on top to remove it
Manually delete the "app" folder in your project folder
In the now empy project, go to "File" menu, select "Import module"
Import your first dependency (i.e. customLibrary from the Eclipse project structure below) by selecting the folder from your Eclipse workspace
do "F4" on the imported library, go to "Dependencies" tab, and add Google modules (i.e. appcompat-v7 from below)
Do another "Import Module", selecting the "OwnLibrary" folder from your Eclipse workspace
Fix dependencies in "Project Structure" by adding Google modules (here support-v4)
Repeat the "Import Module" operation for App_1 and App_2
Clean Project; it should rebuild and be ready.
If you have minSDKVersion issues, modify your different manifests. I found some answers about that Here and There
Eclipse Project structure
-MyProject-
+--OwnLibrary
| +--support-v4
| +--customLibrary
| +--appcompat-v7
+-App_1
| +--OwnLibrary
|-App_2
+--OwnLibrary
ADDENDUM:
When importing modules, if you changed the module name, there will be a few extra steps, i.e.:
From that 8th point, after importing the OwnLibrary
"F4" on your library, select the "almost duplicate" folder, delete it by pressing "-" button on the top left.
Go to "Dependencies", remove the dependency with the name of the folder you removed.
Add a new dependency with the new folder name.
Manually delete the folder you removed from your project.
Thomas.
Related
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.
I'm using Eclipse for build an Android project. when I try to open bellow item :
file --> new --> Android Application Project
Then when the project is built a series errors displayed :
I am a beginner in this regard and thank you for your help.
Open AppCompactv7 and add as library on your project
The problem is with your appcompat_v7 project. Delete the existing project one in the workspace and re-import it from
\sdk\extras\android\support\v7\appcompat
After that try cleaning the project.
Project -> select Clean -> select the project.
1 - Make sure library project(appcompat_v7) is open & is proper referenced (added as library) in your application project.To do this follow this steps: right click in your project -> "Properties - Android - Add"
2 - Delete android-support-v4.jar from your project's libs folder(if jar is present).
3 - Appcompat_v7 must have android-support-v4.jar & android-support-v7-appcompat.jar inside it's libs folder. (If jars are not present copy them from /sdk/extras/android/support/v7/appcompat/libs folder of your installed android sdk location)
4- Check whether ActionBarActivity is properly imported. (In your case this is right)
import android.support.v7.app.ActionBarActivity;
Here is a good example of how to create a project in Eclipse using v7 Support Library
Finally because you are a beginner I'll recommend you to use Android Studio as it is the official environment for developing for Android. Configuring the SDK can be quite a pain in Eclipse. You can also take advantage of the Gradle dependency system and simply specify which libraries you would like to use and Android Studio will automatically fetch the jars from online remotes as required. I think its the future of Android Application Development.
I've read lots of "how-to" guides to importing libraries into Android Studio (now the only supported Android SDK, hmmpf) yet none of them explain what's actually going on during an import.
I can see projects that have Gradle build files everywhere and some that have none, why is this?
Half the stuff I get on Git-hub to play around with takes me more time to successfully import than the time it's saved me by using. My question is, what is required to successfully import and use your average library (project, not JAR or AAR) in Android Studio without having to refactor half the stuff?
Eclipse would allow me to use one single project (folder structure, not jar) as an "external" library and I needn't define what needs compiling where and when.
Android Studio keeps making copies of the project library inside my project folder then proceeds to complain about a whole host of things whilst it pollutes my project space with incorrectly named folders and packages (See screenshots)
Here's and incomplete import where I only imported the "core" folder
because I don't need this other blokes extra stuff - but it's missing
some definitions.
Here's a complete import of the whole folder (as you can see, samples
and all) but it's polluted my project folder and I don't need the
majority of it, and there's all these individual references now to
dependencies and things I don't think I should need.
How do I properly import a whole library with it's dependencies
without it polluting my current project?
Thanks in Advance!
EDIT
Ok here's what I have in one case of a library for an example.
The root folder of the zipped library - lots of garbage I don't need
What do I need to do to use this library? If I import the whole folder using Android Studio's "Import module" feature, it just makes a mess.
If I import just the "Core" folder it semi-works, but lacks some dependencies.
Why are there 3 individual gradle.build files?
Why are the required components in separate folders?
Should I just manually copy an arbitrary number of folders to my new "Libraries" folder under the root of my project?
Importing via File->Import Module
So the "sample" "module" (library..) requires the "layout" and "core" modules, that makes sense. But why if they're required aren't they all in the one module, using the same gradle.build file?
Now I've done that, I get this "Error:(23, 0) Could not read script 'C:\Users\me\AndroidstudioProjects\MyApp\gradle\scripts\gradle-mvn-push.gradle' as it does not exist."
It does exist at C:\Users\me\place_the_module_was_imported_from\gradle\scripts\ though, but
why if it's needed, was it not copied? Is this just bad Gradle...'ing?
Again, thanks!
I think I've found what seems to be the closest answer to this.
10 Gradle Basics
The addition of Gradle is going to be your largest hurdle during your transition over to Android Studio. Here are the basics of what you need to know:
Your Android Studio project will have a settings.gradle for the whole project
The settings.gradle file includes references to all modules which are included in the project and is generally updated automatically when you import or create a new module
Each Android Studio module will have its own build.gradle file
If one module depends upon another module, you will need to add that dependency in the build.gradle under the dependencies section
If your Module requries a jar file, it must be listed in that Module's build.gradle file
You may add remote dependencies to your project by listing them in a module's build.gradle file
From time to time, you will need to manually edit these gradle files Read more about Gradle over here.
Problem is that dependencies show up as modules in the UI so I now have a polluted workspace full of single-use libraries.
You can add the library via gradle.build and the necessary dependencies will be neatly added to your project without "polluting" your project. An example is the Facebook SDK
dependencies {
...
compile 'com.facebook.android:facebook-android-sdk:3.23.0'
}
As you can see from the image, the only place to know the external libraries am using is in the libraries folder of my project:
Add .jar file in your project
1 - Create libs folder under the app folder.
2 - copy your .jar file
3 - paste in app->libs folder
4 - after Click on File menu and select Project Structer option and open it
5 - Open one window in left side Modules under App folder select that folder
6 - In your window Top display 5 Option menu in select Dependencies option
7 - Then Right side display "+" "-" Sign click on "+" sign
8 - then open small dialog and choice "File dependencies" option
9 - then open another dialog here navigate .jar file in your libs folder and select
10 - click on Ok button and Apply And ok
add module project
1 - Click on File menu and select Import Module option
2 - then open one window here navigate your module and Finish
3 - Click on File menu and select Project Structer option and open it
4 - Open one window in left side Modules under App folder select that folder
5 - In your window Top display 5 Option menu in select Dependencies option
6 - Then Right side display "+" "-" Sign click on "+" sign
5 - then open small dialog and choice "Module dependencies" option
6 - then open another dialog here Module and select
7 - click on Ok button and Apply And ok
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.
I have just updated Eclipse, the Android SDK, and everything else that appeared updatable, via Eclipse's Help->Check for Updates and Window->Android SDK Manager.
My project consists of a main project and 2 library projects. One library project is the normal Android License library project. The other library project contains Java files that reference Android resources that it itself doesn't contain, but that are present in the main project (for example R.id.myPic is used in the library project, but is actually contained in the main project). I had no problem building and running the main project before the update.
For some reason now I cannot build the main project. The main project folder has a "subfolder" called "Library Projects", which contains a jar file for the Android Licensing, but does not show a jar for the second library project. I also have a red exclamation mark on the main project folder.
For some reason I cannot rebuild the library file together with the main project. I've tried Cleaning all projects, building one then the other, building all, restarting Eclipse, but no luck.
If I go to the project properties, then Java Build Path, then Libraries, it appears that the jar file for the library project is missing, but I cannot independently create a jar file for this since it uses resources from the main project.
This is what my problems tab says:
The container 'Library Projects' references non existing library 'C:\AndroidDev\workspace\FlashcardsCommon\bin\flashcardscommon.jar'
Type: Build Path Problem
Any ideas?
Thanks a lot!
See this thread:
http://code.google.com/p/android/issues/detail?id=21031
It generally helps to go to Window -> Preferences -> General ->
Workspace and check "Refresh automatically". Then try clean
building your projects incrementally.
You may also have to remove the source inclusions that represented
your library dependencies manually. You will find that ADT 14 and
15 are very frustrating to work with when you have library projects.
It requires frequent manual cleans of libraries AND their dependent
projects to make changes to library projects effective.
Altogether, good effort by Google, but it's a bit buggy.
Another similar thread:
Cannot build library dependent project after update to ADT 14