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.
Related
I'm in the process of migrating over from Eclipse and I'm certainly having some growing pains.
Eclipse was very straightforward with Android Library projects. Create a project, mark it as an Android Library, and then reference it from non-library Android projects in the same workspace. When code changes in the library project, nothing needed to be changed in the non-library projects.
Android Studio does not seem to be so simple. I've worked my way through the tutorials and I have gotten to the point where I can import my library project as a module, and add it as a dependency to my app module.
But the huge issue here is that it copies my entire library module into the non-library project as a sub-folder. Now, when I make changes to my library project, they are not reflected in my non-library projects unless I manually remove the module, delete the sub-folder, and re-add the library module.
I hope this is not how this was intended. Maybe I'm doing something wrong? Can someone give me some pointers?
Thanks in advance!
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....
I am trying to use this library off of GitHub for a Segmented Control in Android.
My problem is that I do not know how to include the provided library into my existing project. I've tried copying the src and res files (of the library and sample) into my project and modifying their package names to match mine, but the files are filled with errors and will not compile.
I am new to Android development, and so I am unsure how to bring these files in to my project so that I can use them and create the desired segmented controllers.
Note: I am using the Eclipse IDE from the Android website (ADT v22.6.2).
Hi there you will want to actually clone the whole repo and import that project as its own project and then reference that project via this method. Eclipse Android project, how to reference library within workspace?
Good luck.
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.
If I decided to use a library project in mine I still have to keep this library project in my workspace. Is there a way to avoid this? Also, does it mean I have to deliver an addition folder of library project with a folder of mine?
Library projects works like a charm, but of course you need to keep them open in the workspace as everytime eclipse builds your project it needs to access all the stuff from the library project.
If you don't want to keep this project open AND you don't plan to change it a lot AND it's not an Android project, it's a JAVA commom project you can build it once and instead of using a library project reference a JAR in your android project
If you want to do this outside of Eclipse, (say you're building from the terminal with ant, ie. in continuous integration, or if you just hate Eclipse.) Just place the library project in an adjacent directory. In your main project, edit project.properties to include:
android.library.reference.1=../LibraryFolderName
If you have more than one library to add, just number them accordingly, ie.
android.library.reference.1=../LibraryFolderName
android.library.reference.2=../AnotherLibraryFolderName