I am trying to import an android project created in eclipse into android studio. This main project also refers to another library project in the same eclipse workspace. The folder structure is like this:
workspace\app1
workspace\lib1
When I import the main project into android studio, the library project is automatically imported as a sub-project (or shall we call it a module) within the main project. That's not what I want. The library project is shared by multiple apps I am maintaining. It should sit in parallel with other app projects in terms of folder structure. I wouldn't want it to go understand any particular app project.
Please help explain how I can make the library project stand its own and refer to the library project from other app projects in android project. I am fairly new to the gradle build system. So detailed instructions would be highly appreciated. Thanks a lot!
Since you are importing in android studio, I assume you are moving to gradle build system. In your case , I think, it would be best to have a separate AS project for library. Use that project to generate a jar file and then import that jar using gradle build script in each project you want to use it.
If you are sharing the same library across multiple, you can configure them as separate AS project and have "aar" file as output. (In your gradle you put>> apply plugin: 'android-library'). You then define them as dependency in your gradle file. (either through maven repo or putting it in your libs directory and defining it in your dependencies section). You can find more info at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-projects
You can use version control tool such as git to synchronize the library project in every main project. But you need to use a version control tool to manage all your projects first.
Read here on "AS Modules"
review 57.1.2 on "common behavior"
Take a look at a project built on AS pattern of modules as libs used in eclipse (gradle.settings) pictured
all the includes are modules
maybe you can rethink the idea of how to get AS to work for you in reusing code....
Related
I am looking a source code repository and it only contains code for an Android project i.e. src/main/java/com/.. and no project definition files such as .idea, .iml ,.ipr, .iws - These files are included in the .gitignore file.
There are no files relating to an Android Studio project at all so I cannot open in the IDE. It has been set up for Maven so I can build that way. If I want to run/debug/alter this project what do I do?
Why would somebody exclude all IDE project files?
It's easy, the repository/source code owner don't commit the project files because the source code must be independent of the IDE used by people. The projects files of Eclipse are different from one of IntelliJ.
You can clone or download the source code and even not use any IDE. Some poeple prefer working with editors like Emacs or Vi and build the project using the command line.
There are many ways to create android projects with Android Studio and Eclipse being the main two.
If the author had to maintain project files it would add considerably to the work required as IDEs etc get updates at different rates.
This way the code is "portable" between IDEs and the author can focus on just supporting his work rather than all of the combinations of IDE/Operating Systems.
My Solution
I am posting solution here as I cannot yet answer my own question.
So, I the solution was in the Maven definition. My codebase was an SDK consisting of numerous libraries and sample apps. Each component had a POM.xml and was all contained using a Parent POM.
All I did was import the Parent POM into Android Studio. Once triggered Android Studio would create its own project files using the POM definitions for each component. All the modules were available in one instance and it built and ran instantly. It was truly beautiful :)
Steps: Import Project -> Select directory containing POM.xml -> "Import project from external model" -> Maven -> Next -> continue to create project.
OK I know people have asked this problem thousands times, but Android studio is so so so hard to understand and use and I still can't find the correct way.
I find several solutions, but all of them says to copy the library codes into main project. It makes no sense to me. When I try to build a standalone project for the library, I find no "New project from existing source" like that in Eclipse.
Can I have a step-to-step for:
I have a main Android Studio project
I have an Eclipse Android library project
Without making a copy of library project
I can let the main project "use" library project
The point is, if I have many app projects using the same library source, I can just modify one copy. If I need to put library codes in every app project, it's a disaster. Eclipse can do this without any problem.
Thank you. I'm really exhausted with Android Studio, but I can't choose to stay on Eclipse since Google says ADT won't be supported anymore.
The real answer to keep your library project only in one place is in this post :
Android Studio 0.8.1 Creating Modules without copying files?
In Android Studio Project import your eclipse library project as new module. Then in Android studio right click on your app module go to module setting > select dependency tab > click plus> select module dependency > select library project module.
new Module or import Module under the project,
then open Module Settings--》Module dependencies --》‘+’ module dependencie.
I see there is option to create module/ android library project with in a project, but don't see any way to create a standalone library project/module that could be shared across different projects. It used to be very simple in Eclipse. When I try re-using an existing module within a different project, AndroidStudio simply creates a copy of that module in new project. Thats what I don't want, I want to re-use my existing code. This link seems to have answer I'm looking for, but not working for latest build for Android Studio.
There are a couple of ways I've tried doing this, a quick and easy way to do this is to symlink your library module directory to a directory in your project and add it to your settings.gradle. A better way to do it is to import the library module as a VCS project (local git works fine) It will still clone the library module into each project but changes made to the library will be consistent across all of the projects using it.
I am currently starting on quite a huge Android project which will include up to 5 different Apps. Each of these will be dependent of an android library.
This can easily be done by building the shared android library into .jar file and reference this from each App. But the problem is this project is really on the early stages, therefore the code of the library will change just as often as the Apps. It will be quite a pain to always have the library open in a different project, and build it everytime a change has been made.
First question is how to setup a workspace where you can an App and the library open at the same time, and referencing directly to the library. Without any concern about a .jar file.
If it's not possible any ideas? I can't be the first guy starting quite a large android project with multiple Apps.
In Android Studio do the following:
Create a new project. The project will hold all the different APK projects and the shared library. Use "File -> New Project" or select New Project from the splash screen for AS.
In the project, create a new module for each separate APK. Use "File -> New Module -> Android Application". I'm refering to these types of modules as APK modules.
In the project, create a new module for the shared library. Use "File -> New Module -> Android Library" to create the shared library.
Associate the shared library with each APK module by modifying the "build.gradle" file to add a dependency for the shared library. You must change the "build.gradle" file in each of the APK modules.
dependencies {
compile project(':aaa')
}
Be sure to replace "aaa" with the name of the shared library.
You can have multiple shared libraries if you like.
The code for all the APK modules and the shared library is now accessible under one AndroidStudio project. Another advantage of this approach is that the single project directory that can be turned into a single git repo for the combined APK modules and shared library.
First, IntelliJ doesn't have the same concept of workspace as Eclipse. In a nutshell, the model is as follows: You have one window for each IntelliJ project. An IntelliJ project has one or more IntelliJ modules, which are linked by source. Modules from different projects cannot be linked by source.
Regarding your specific question, I think the easiest solution is to have a single source repo and (multi-project) Gradle build comprising all apps and libraries. This will translate to a single IntelliJ project with one IntelliJ module for each app/library, all linked by source.
If you absolutely need to have separate Gradle builds, and still want a fast turnaround in the IDE, then as far as I know, IntelliJ 13 can add another Gradle build to the same IntelliJ project with the push of a button, and perhaps Android Studio can do the same (not sure). Last but not least, remember that both Android Studio and the Gradle Android plugin are early access previews.
I have tried fiddling with Android Studio and IntelliJ Idea for sometime and the best bet I had was to export everything from eclipse. You could follow the steps below(which is what I usually do.. Does not seem to be a good idea, but it works for sure :) )
Open up ADT or Eclipse and setup a new workspace.
Create the apps and add the library project as a library to those apps. The library project needs to be imported to workspace again(I'm not detailing as I presume you know it)
From File > Export > Android > Generate Gradle Build Files which would generate the gradle build files for the entire workspace. And this then can be opened up in IDEA.
Please do reply if this helps.
I have a setup of android project on eclipse and I want to migrate to Android Studio. So, I have android-support-v4.jar that I use for my main project and my Facebook lib-project.
I guess I have to exclude lib-projects as a folder in my main module (lets call the main module Jack). Jack has dependancy on the facebook lib-project.
How should I define the android-support-v4.jar as a separate library and use it in both projects? Or should I just use directly the jar files and leave them in both Jack's libs folder and Facebook libs folder?
If the first option should be done, will ant clean release still work (with the build.xml android generated file)?
In Android Studio, builds are done with Gradle now. Gradle is different. With gradle, you tell your project which jar's you need, and it will connect to a server and download them if it doesn't already have them when you compile your apk.
A few things to note:
When you install Android Studio, it has it's own Android sdk directory. You have to download everything from the sdk downloader (from inside the Android Studio App) again. Don't bother trying to switch the sdk download path to your current one. You will only encounter bugs (Or at least I did).
So your question is worded very confusingly. It sounds like you have a main module, and then you have a library module, and the library module uses the support library.
You'll need to set it up so the main module has a dependency on your library module. From there, you'll need to go into your library module's gradle file and tell it that you want to include the android support library
dependencies {
compile 'com.android.support:appcompat-v7:19.0.0'
}
The support library is a little weird in gradle. Gradle normally would download the dependencies you need. However, android studio requires that you have the support library installed through their sdk downloader (top-right group of icons in android studio. The download icon).
After you get all your dependencies entered into your gradle file, you'll then need to go to Tools -> Android -> Sync gradle files with project. From there compile errors should go away, and you should be able to run the project.
Best of luck. By the way, Here is the documentation on Gradle on the android website. I find myself having to go to it A LOT, especially when I made the switch from Eclipse to Android Studio. This + Various tutorials I found as needed via google. http://tools.android.com/tech-docs/new-build-system/user-guide
EDIT: This link might also be helpful. Google has some steps for switching from eclipse to Android Studio: http://developer.android.com/sdk/installing/migrate.html That with some of the stuff above may prove helpful.
While I haven't tried this myself, I suggest you use the recommended migration steps provided by Google in this article.
Before you do that, though, make sure that you either:
Check that both support libraries on the main project and dependencies have the same version (Eclipse will complain about it during build time, and will likely cause problems during conversion to Gradle script.); OR,
Uncheck the "Android Private Libraries" entry on the Order and Export tab of the dependency project's build settings.
If the migration process described doesn't work smoothly for you, you can always call the Ant build script from within the Gradle script, as described here.
The Android Studio uses only Gradle, but you can export Android ant project from eclipse.
To do that go to File -> import project usually next, next, next... works.
If not go to project setting Shift + Ctrl + Alt + S and under modules -> PROJECT_NAME -> Dependencies you can add your support library.
To add a Facebook library you must add it as another module to your project.
If you still want to use Ant there is another option: Use Intellij IDEA which support Ant.