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!
Related
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 have a project that has multiple android libraries mentioned as dependencies. Is there a need to add all the libraries to Eclipse workspace for building the project? Is there a way to avoid that?
There is the absolute need to have them when compiling your android project. Otherwise you would get compile errors because of missing classes. You have two options here
Have the library project in your workspace and reference it (like you mentioned).
Create a jar from each of the library projects and add those to your application. This way you won't need the library project in your workspace.
It depends on the kind of library which way you should choose. If the library is changed often and you have direct access to the sources I would import the project. If you're afraid to lose the clarity in your workspace you can use working sets to hide the library projects.
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 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.
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