How to create your own library for Android development to be used in every program you write?
You have to create Android Library Project.
Create android project in Eclipse, enter Project Properties -> Android and check isLibrary property. Now you can add this library to your Android Application project by adding it to list on the same property page.
More detailed instructions here in Working with Library Projects section
How to create my own android library and host it
If you've pushed your code to GitHub then sharing the library (aar) is easy with JitPack.
Your users will just need to add the repository to their build.gradle:
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
and then your GitHub repository as dependency:
dependencies {
// ...
compile 'com.github.YourUsername:Repo:Release'
}
The nice thing is that you don't have to upload your library. Behind the scenes JitPack will check out the code from GitHub and compile it. As you publish a new release on GitHub it becomes available for others to use.
There is also a guide on how to prepare an Android project.
How to create a library project in Android Studio and an application project that uses the library project
To create a library:
File > New Module
select Android Library
To use the library add it as a dependancy:
File > Project Structure > Modules > Dependencies
Then add the module (android library) as a module dependency.
Run your project. It will work.
Create STANDALONE Android Studio (1.5) library project
This may not feel comfortable for a person from other platform/IDE/world, but this is The Way. Personally i'm getting annoyed with Xcode every time i use it in the exact same way you're annoyed with AndroidStudio now. But lets get down to business:
- Create an empty project and select "Create no activity".
- When everything is set, go to "File\New\New Module" and select "Android Library"
- Give a name for created library and click "Finish".
(Optional) go to "Run\Edit Configurations" and set everything like below:
Now open the librarie's 'build.gradle' file. Make sure to open the file from exact same folder which is named with your library name, because there are a couple of 'build.gradle' files all over the place. Remove support-library entry from the file:
- Write some code and when you're ready to deploy the library set everything like this:
Go to "Build" menu at the top and select "Build APK".
And about unit tests:
**Edit 1: **
If you really want to remove the 'app' folder, than follow instructions on a picture below:
Android - Is it possible to create a custom library to use across several applications?
Well, I think there is a way to do it (although I didn't try it myself), but it requires the users of your library having to build their APKs manually via aapt
.
The problem is this: The JAR you're exporting contains the R
class file which holds the resource IDs of your library. So, any application can access these IDs by simply linking your JAR. However, that's not enough, because by default, only resources in the app's res/ folder are bundled with the APK. Hence, you have to create the APK yourself using aapt, telling it to also include any resources from your library. Check the aapt tool help for more information.
Since this implies that users of your library have to introduce a manual build process (or at least modify it), it makes for a poor experience.
Create library for Android development?
I've read about Android Library Projects, but as the documentation states they can not be
packaged into a JAR, but will be compiled along with the project that references the library
project. This means I also have to distribute the source code.
Not true. It does require a bit of extra packaging work, but you can compile your code to a JAR and distribute the JAR in the library project's libs/
directory.
So: Is there a way of compiling and packaging a set of classes and other files (including
XML layouts, resources and stuff) and distribute only that package without any source
codes so that it can be "referenced" and used like a JAR file by any other developer?
Use an Android library project. I have some stuff written up here that describes a bit more of the packaging options, plus pointers to some "parcels" that follow the conventions described therein.
Related Topics
How to Implement "CSS Versioning" (To Solve Cache Issues) Using Jsf 2 H:Outputstylesheet
How to Use CSS for Vaadin Components
"Loadstylesheetunprivileged" Error When Trying to Use CSS Stylesheet with Javafx
Find Out If Class Name Contains Certain Text
Is It Really Impossible to Protect Android Apps from Reverse Engineering
Difference Between Getexternalfilesdir and Getexternalstoragedirectory()
What Is the Basic Purpose of @Serializedname Annotation in Android Using Gson
How to Get String Array from Arrays.Xml File
How to Change Color of Hamburger Icon in Material Design Navigation Drawer
How to Get an Android User's Email Address
Openssl Is Not Recognized as an Internal or External Command
Android Audiorecord Class - Process Live Mic Audio Quickly, Set Up Callback Function
What Exactly Is a Context in Java