How to obfuscate Android library project with Eclipse? - android

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.

Related

use git repo of android library

I use AQuery, I have the last jar version and that works good. But i want to use the settempdir() function and i must build them self inside the file, when I try to do this, I can not change the class inside the jar file.
the sourcecode of Aquery is https://github.com/androidquery/androidquery and i have insert it into Android Studio, i have change the code from this link https://github.com/androidquery/androidquery/pull/38 but i can not make a jar file. i see no gradle tab on the right.
Can i use it without making a jar of it?
Greathings christophe
If you choose Build project you should have an aar file in the projects build folder which you can use just like a jar file.

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

Android: HowTo generate Jar for the added framework

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

Categories

Resources