Get all library (non-Maven) projects from SVN in Android Studio - android

I have a MainApp which refers to 2 other library projects. All projects are on different SVN servers.
The way I have been working on Eclipse ADT(not using Maven, which is not the good way) is that I imported all library projects one by one and then the MainApp - all within the same workspace. This way the library projects were easily referenced through project.properties ; because they used relative path of library projects. This also meant that I had to update all projects independently and no one-click project update was possible.
So I tried moving to Android Studio/Gradle build system. If I export the gradle files from my local workspace and then import project into AS, it finds all library projects and shows them up as modules in AS. The problem is that I cannot use SVN client in AS to work on my project - as AS assumes everything to be there on my local machine (and not as a SVN codebase)
The other approach I took was to import the build.gradle file for MainApp directly from SVN. This approach does not import the library projects, because, of course the MainApp does not know about the SVN URLs of the library projects.
How should I go around solving this problem, where I don't need to use another SVN client to play around my code ? And use absolute URLs for all library projects ?

Depending on your exact needs, there are several different solutions:
Publish library projects to a local or remote Maven repository (e.g. via their Gradle builds), and declare artifact dependencies on them in MainApp's build. Publishing can be automated by having CI builds for the library projects.
Include library projects' SVN repositories in MainApp's SVN repository using SVN externals, and have a single multi-project Gradle build.
Use Prezi's Pride tool to create a single multi-project build that spans multiple SVN repositories.
It's also possible to attach another Gradle project to an AS project (see the + icon in the Gradle tool window), but I'm not sure if/how this solves the problem at hand.

Related

Android studio project files missing from source control

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.

Importing eclipse android project into android studio

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....

Creating standalone android library project using Android Studio (0.8.14)

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.

Setting up a project in IDEA with Gradle

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.

Using different revisions of multiple android library projects in multiple client projects (in Eclipse)

First of all I have most of my knowlege about library projects from the google docs and a detailed description of the android build system in this article.
Setup
In my Eclipse workspace I have several client projects that import android libraries. Each client imports a different set of libraries and also some libraries import each other.
Each client has its own subversion repository and all the libraries are in one single subversion repository.
All builds and executes well.
Problems
The client projects and the libraries are not evolving synchronously. Some client projects need older revisions of the libraries. One has to create lots of projects in Eclipse. Some libraries projects have to be created multiple times from different revisions of the library repository.
I need to have lots of libraries because with a single library project all its resources would end up in the client project, even if the client actually does not use any of them. Am I right here?
I check out different revisions of the same library into the workspace. With Eclipse it's not possible to import more than one library projects, because the eclipse projects have the same name in .project file (Eclipse complains about that when trying to import the second one)
Eclipse??
EDIT
The answer of Jarek Potiuk works. But it just solves the Problem described in point 3. I still have to create each library project individually in Eclipse.
Is there a solution where I don't need to create a project in Eclipse for each library project imported? Has someone a working solution with ant?
Let me explain how we deal with it. We are using mercurial subrepo but it should be exactly the same using svn:externals in your case.
0) prerequisite: make sure your .project and .classpath files are commited to repo with your projects....
1) In main project we have a "subrepo" directory and we keep all the external libraries (as subdirectories) there. In mercurial it is done using subrepo, in svn you should be able to link to particular version of the library (SVN tag or branch URL) using svn:externals configuration: http://svnbook.red-bean.com/en/1.0/ch07s03.html
2) Net effect is that when you checkout the main project you automatically checkout the dependent libraries in subrepo directory. So far so good.
3) Now in eclipse you get the main directory failing, because it does not have the library linked..... What you do in this case - "Add new Java Project", type in UNIQUE project name (for example libraryprojectname-mainprojectname. Uncheck "Use default location" and browse to subrepo's library. Eclipse will configure the project for you from existing .project. Add this project as depending project in Android and possibly in eclipse as well... Note! the UNIQUE name will not change the .project name, but it will let eclipse to have more than one of your library projects checked out.....
4) Now when your project compiles commit everything (including .project and .classpath files) to repo...
5) Whenever someone checks out the project, library will be checked out in proper version and the only extra step needed is to repeat point 3) - add new Java Project for subrepo and give the project a unique name... That's about it (Eclipse will internally anyhow refer to subrepo/library directory not to the unique name)

Categories

Resources