Best way to distribute Android Library - android

What is the best way to distribute android Library. I dont want the user to see my code, library has images and layout xml. Here is my understanding. Please correct if I am wrong.
If I make Jar then I cannot add res folder as part of my jar. (I know using progurad is an option to obfuscate code.)
If I publish aar I have to make my repo public?
So my question is that how can I distribute my library to user without giving access to my code while adding images and layout files as part of that library.

There is aar format which was exactly created for libraries distribution.

Use Jar
U may have to get the image file and res files through a constructor if that is null use default

Actually you can't, even if it's a jar there is a tons of tools to reverse engineer it (one of the tools)
The only thing you can do is obfuscated your code so it turns to unreadable code. Read here about proGuard with android(proGuard)
For the distribution part with res I recommend using gradle. For example Jake Wharton has a library named butterknife.
He distributed it using gradle so the user could just add
compile 'com.jakewharton:butterknife:6.1.0'
in his gradle files and be good to go.
Another example with res files distrbuted in gradle is the android support libs which can be grabbed by adding:
compile "com.android.support:support-v4:18.0.+"

Related

Is it possible to make android library contains readme.txt?

I am new in Gradle.
I've been made android library and I will upload this into maven repository.
But is it possible to add "Readme.txt" into my library?
for example,
When someone add my library into dependencies section in build.gradle and sync.
then Gradle creates(or copy) "Readme.txt" into target project(probably $projectDir or $projectDir/app) and user can read it(Like NuGet)
(Important things of this library, how to use example or something like that.)
I think it is really annoying visit project web-site and read "How to use" every using single library.
I want my library contains how to use text file.
Thank you.
I don't think this is possible, you don't know how the calling use is referencing your project. They are likely only referencing the compiled source code and never running your gradle file.
This is not a good idea, you don't know their exact folder structure, and even if you did you can not be sure that your readme.txt would have a unique name that did not conflict with their project file.s
When using a .jar file you cannot include this as resources cannot be compiled into it. But you can export your library as an *.aar file which can contain resource files. You get this by using "com.android.library" as your plugin type and can then find the aar-file in your build folder after you have built it.
This can then be included in your other project e.g. as a file reference.

How to make a third dependency or jar in Android studio?

As a new android developer, I just know how to import the third dependencies made by other android developers.But now ,I write a simple custom view ,including a class : enter image description here and a declare-styleable:enter image description here,for convenience for the future,I want make it to a dependency or a jar.I don't know how to do it.Thanks for your help!
A .jar is a compiled Java bitcode for the jvm. Google android Java compiles into dex and it packed into a .apk. I would be utterly shocked if you could ever use a jar file. In general android apks files contain everything needed to run the app they don't tend to depend on anything else.
You can setup intents to pass things around throughout the larger environment but in general if you need the code for several projects, just include the source to be recompiled. You might be able to directly include a .dex but it would certainly not be preferred.

Android: How to create graphs, tried using a library and ended up with a headache

I was wondering what the easiest way is to display a simple graph of any sort based on values that I already have. I tried using a library but ended up with more errors than i can count. What is the trick to using libraries and can someone take a second and help walk me through the steps because online all i can find is tutorials that just go: Download this jar. put it in libs and tah dah. But I am not seeming to find such luck.
Is there a way to download it as if it was a compelete project and then just import it? Or do you have to go through and pick out each little thing?
Quoting the project documentation:
Recommended: If you use Gradle/Android Studio you can use the library from Maven Central.
Add that line to your build.grade file into the dependencies block:
compile 'com.jjoe64:graphview:3.1.3'
Download .jar file and copy it into the libs folder of your project.
GraphView-3.1.3.jar
Download or clone the git repository and link your project with the GraphView library project.
jjoe64/GraphView on GitHub
Since you have the question tagged with eclipse, option #2 would seem to be the most likely choice.
Note that the author also provides:
a series of demo projects
JavaDocs for the library
both of which may help you learn how to use it, as an adjunct to the rest of the documentation.

Including and using a XML layout all within an Android library jar

I want to create an Android jar library which has activities which use layouts that are all within the jar file.
I have been researching and trying different methods for the last few days and exhausted the related posts here. I have managed to get drawables and other raw assets to reside and be loaded from within the jar. However I have not been able to include valid resources which include the layouts. The official view is that it is not supported yet however I am sure it can be done.
I see that this is possible with .aar libraries when using Gradle but I am unsure if .aar libraries are compatible with older Android projects.
Could anyone shed some upto date info on this issue of resources/layouts in jar libraries and also the compatibility of .aar libraries.
Many thanks
I want to create an Android jar library which has activities which use layouts that are all within the jar file.
That is not possible, sorry. However, you are welcome to create an Android library project that serves this role, and that library project can ship a JAR instead of Java source code (see the Play Services SDK's library project for an example). The layouts would not be inside of the JAR file, though.
The official view is that it is not supported yet however I am sure it can be done.
I am sure that you are incorrect in your assessment.
I see that this is possible with .aar libraries when using Gradle but I am unsure if .aar libraries are compatible with older Android projects.
Project age has nothing really to do with it. If you are using Gradle, AAR files work. If you are not using Gradle, AAR files do not work.

Create library for Android development?

I'm pretty new to Android development, but I have some experience with Java and Eclipse. I'm looking for ways to create re-usable libraries (controls, helpers, "standard" activities, etc.) that I could use in my own projects, but that could also be distributed to other developers without disclosing the source code.
Normally, I'd package the class files into a JAR file and any other developer could add it to the classpath and use the packaged classes.
How can I do that with Android projects? 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.
I've also read this post, which asks about the same question but didn't provide a satisfying answer.
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?
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.
Thanx for your solution. From what I understand, you still can not access the resources private to the library from within the libary code. So assume your library has a string resource named "my_lib_resource" under res/values in the library. You bundle this in the jar along with the source code. Can you access this resource from the library source code using something like:
int id = res.getIdentifier("com.example.mylib:string/my_lib_resource",null,null)
assuming your library package name is com.example.mylib.
For me this does not work.
Brave new world of dependency management:
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects

Categories

Resources