Android: HowTo generate Jar for the added framework - android

I am trying to add some 3rd part framework in android code. The framework is set of java files.
My questions is how to generate Android Specific Jar for this framework so that my applications can use it. What and where am I missing the generation of Jar.
Any suggestions.

What I do to generate jars is create an android project, put the classes inside a package on the src folder and then export the src folder as JAR with Eclipse.
Then add that Jar in your build path on the main project

Related

How to make a library containing native code and pure java for android

I have cross compiled the native code for different architectures for android and have its corresponding jni wrapper class working in android studio. Now I want to make it available as a library. I have two questions:
1)Can I just jar the .so file and jni files to make the library?(not .aar because my library contains only the pure java and native code, no android related stuff such as .xml,res,etc) If so what should be its structure?
2) If I cannot create .jar file, then all I am left with is creating the .aar file. That would include the use of android studio. Can I do it without the android studio?
Edit 1:
If I jar the files, then I don't want to extract .so and then use it. If I jar the files, then add it(the .jar) as a dependency in my project then it should automatically put .so into libs/jni folder in my apk so that jni can find it. Question is how do I do that?(if possible)
Fortunately found a way. As .aar is itself a simple zip file with structure as specified here. What I did is "jar" all the .class files (inside proper package folder) into classes.jar, created an empty folder "res", put all .so files in jni folder (with proper architecture) and made a simple AndroidManifest.xml containing basic tags. Then I jar them into file with extension .aar (like mylib.aar). I have tested it by copying .aar into another project's libs folder and putting a dependency on it in app's build.gradle( like compile(name:'mylib',ext:'aar')). And it works great.

How to obfuscate Android library project with Eclipse?

Hi I developed one small library in Java for my Android application. I want to do obfuscating for that library. I using Android version 4.1.2. First thing is that according to Google's Android documentation there is no proguard.cfg file in my project root directory. Instead of that proguard-project.txt is there. I add proguard.config=proguard-project.txt into my project-properties file.
After this configuration I tried to export this library project and try to do obfuscating of that project. It showing error can generate .apk file because it is library project.
Then I tried with another option in export. Instead of regular export android application I use general -> archive file and tried to export it and generate jar file but I check inside the jar and no encoding is done. That means anyone can extract and check classes and content inside my library. But the main thing is that it generates proguard folder inside my project and also generate dump mapping seeds usage.text files inside it.
So I need help to do proper ProGuard obfuscating of my Android library. Am I doing something wrong. What kind of configuration do I have to add inside my proguard-project.txt so that it will do proper encoding of my code?
Actually, you can obfuscate a library project, but not directly! You can only do that by exporting the entire application's project that uses that library.
With that in mind, you can set a different proguard.cfg at the root folder of your Library Project.
Hope this helps.

Is it possible to create jar that includes android functions?

As the topic indicates I would like to create a jar library that uses some android functions (no layouts) and that will be included in an Android project.
Is that possible and how?
From the research I've made I managed to include a simple jar file that uses pure Java (JAVA SE 1.6), but
when I tried creating a jar file I encountered the following exception when I tried to run the Andoid app: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: mylib.pleasework.amen
I tried including android.jar in my library and removing the java library, so that the jar file is build against android sdk, but it didn't work.
I tried including the jar file under a /libs folder as it is said to be the correct way to import jars in android projects from ADT v17 and after, but that didn't work either.
The jar I want to create will not use any resources (xml layouts, strings.xml) just Log.d and WifiManager.I am aware of Android Library Project but my library source is sensitive and I am afraid that it won't be safe if exposed in a Android library project. I was thinking of creating a jar and using ProGuard ( http://developer.android.com/tools/help/proguard.html ) obfuscate it.
I think I mentioned everything. Any help will be appreciated.
Thanks,
Thomas
As the topic indicates I would like to create a jar library that uses some android functions (no layouts) and that will be included in an Android project. Is that possible and how?
Use the jar command, or the <jar> Ant task. I am sure that there are ways to export a JAR from Eclipse, but I personally have never used them.
For example, in this GitHub repo I have a reusable component and a sub-project that is a sample app. My build.xml for the repo contains the following custom task:
<target name="jar" depends="debug">
<jar
destfile="bin/CWAC-WakefulIntentService.jar"
basedir="bin/classes"
/>
</target>
This generates a JAR file, that other Android applications can use by adding to their libs/ directories.
I am aware of Android Library Project but my library source is sensitive and I am afraid that it won't be safe if exposed in a Android library project.
It won't be safe exposed as a JAR, then, either. You can create an Android library project for public consumption that replaces the src/ tree's contents with a compiled JAR in libs/ in the library.
The way I did it in the end was: to create an Android Library project (check isLibrary checkbox in project properties) export it through Eclipse (right click on the project->export->jar file, careful to deselect all resources - res folder, androidmanifest.xml, *.png etc) and put it in the project you want by importing it under /libs folder. I don't know if this is the best solution but it worked for me.Used ADT r20, Eclipse 3.7.1, Android api level 7

Android how to export jar with resources?

I create an Android project for build my custom widget, and I want to export it as a jar for other project so that reuse them conveniently, but now a problem is, I can't use resources which is included in my custom widget jar, for example a png picture, it gets a null from the resource Id of class R! How can I sovle it?
Update question:
How can I parse LayerDrawable xml from assets folder in code?
You cannot export self-contained Android Library jar at this time and announced will be available in the future SDK release.
https://developer.android.com/guide/developing/projects/index.html#LibraryProjects
You cannot export the Android Project to Jar with Resources. What you can do is Make First Project as Library and then Add that to another project.
See Documentation Here shows how to Setup a Project as Library and use in another Project
In order to get the app working with my exported library .jar file, I had to copy everything in the resources directory "res" from the library project to the application project. Also had to merge file string.xml as well as merge the ApplicationManfiest.xml files as well. To add the project as a library through eclipse is much simpler.

How to include jar files in android library project

I am trying to use phonegap inside an android library project. The library project compiles just fine but when i try to start an activity that extends DroidGap, i get this error
01-02 10:12:17.575: W/dalvikvm(316): Unable to resolve superclass of Lcom/***/***.
I think this is because the phonegap.jar file is not included in the compiled jar file of the android library project. I have tried using ant to build but it doesn't seem to work.
Edit: I am building a android library that can be used in other android projects. I am using the standard android library project but activities in this lib project that extended DroidGap class in phonegap.jar are crashing with the above error.
I´m afraid that is not possible yet. The result jar file will contain all classes and resources defined in the android library project, but will not include external jar files added to the build path. You will have to add those to your final Android Projects using that library. You can also find similar questions in SO like this one
create one folder 'lib' in your project. put your .jar file in lib folder. select your .jar file right clicked on ,select buid path --->'add to build'. will add your .jar file. now you can use this .jar file classes.
I would suggest not making the 'lib' folder manually.
Instead:
Right click Project --> Properties --
Select Java Build Path
Make sure Libraries is the tab selected at the top
Click Add External JARs
Then find your JAR...
Basically, the same way you may have added the PhoneGap.jar
The ADT (Android Development Tool Eclipse plug-in) has built-in support for the creation and reference of library projects. See the example in section 5 of this tutorial.
Try changing the name of the folder to libs instead of lib.
have you added required permission in manifest file..
see the below links
http://docs.phonegap.com/en/1.4.0/guide_getting-started_android_index.md.html

Categories

Resources