Has anyone figured/found out how Android libraries are intended to work in Android studio?
I have not been able to find any documentation on this yet (the documentat
For the sake of anyone hitting on this, here's what I'm doing to "solve" this issue. It's very far from an elegant solution, IMO, but it's the closest to a good solution that I've found for handling my problem (reusing Android libraries) in Android Studio with Git.
Basic idea is to use Git submodules. Each library has it's own Git repository.
git submodule add
to fetch the library.include ':myLibrary'
and sync the project.It's a far cry from the simple elegance of working with Android libraries in Eclipse, but it works after a fashion. Things to keep in mind:
The built-in VCS should be able to help here, but it's been pretty flaky for me, so I prefer to just do it myself from a terminal now.
Hope this helps.
Multi Project Setup is what you're looking for I think. I wouldn't focus too much on the Android Studio stuff at first. Focus on getting the gradle files right, and then "synchronizing" the module to update Android Studio. (I've had to restart it at times for the "Build Variants" section to update with new flavors.)
@Xav suggested in a Google+ response the following:
The high level project is there in case you want to add new modules later on (Library project). It's easier to create a top project with a single module the first time, than to create a flat project, and converting it later when adding modules.
Two main things to point out, in your settings.gradle file, you would list the :app and :library modules; also the 'android' plugin is used for the app, but the 'android-library' plugin should be used for library modules.
If you are able to ./gradlew assemble from the command line, then Android Studio should update with the proper settings the next time you open the project or synchronize.
Attach android library into android studio. If you have any idea about library then add directly for eg.
(this is the picasso library)
compile 'com.squareup.picasso:picasso:2.3.2'
If you want to create our own library then follow these steps.
Choose New module and select Android Library.
Declare Library Name and package name.
Now finally your library has been created you can use easily.
Click on Dependencies Tab inside small window and click Green color plus button.
And select Module dependency you can see your library file.
select library and ok
Intellij is different to Eclipse, in that your 'workspace' is only for one 'project'. Each project is made up of multiple modules. And these modules can themselves be there own 'project / app / library'.
So a module is kind of like the equivalent of an Eclipse project.
Go to : File->Project Structure->Modules
And add the Android Library as a module, you can declare that it is in Android Library and make it a dependency of your 'project' (app module).
If you want to use additional libraries in your Android Studio project:
In build.gradle
replace
compile files('libs/android-support-v4.jar')
with
compile fileTree(dir: 'libs', include: '*.jar')
If it still doesn't work, navigate to the root folder of your project with our terminal and run a gradlew clean
command.
At the minute you need to configure your build.gradle
file to use jars with Android Studio or you end up with the dreaded NoClassDefException
at runtime. See my answer here for some tips on getting jar libs working. You can also define Maven dependencies straight into that build.gradle
which is very handy.