ini4j only works from the libs directory, not maven - android

I'm trying to use ini4j in an Android app, compiled in the AIDE IDE. When I put ini4j-0.5.4.jar in the libs folder in my app, it works. However, when I include ini4j with the line compile 'org.ini4j:ini4j:0.5.4' in my build.gradle, I get the error bad utf-8 byte a0 at offset 00000004. I've checked the jar file in the Maven directory, and it is identical to the one in my libs folder. Both have the SHA1 4a3ee4146a90c619b20977d65951825f5675b560. I have absolutely no clue what could be causing this.
EDIT: For some reason, it seems to have xerces as a dependency, which is the library known to have these issues.

According to Apache (http://xerces.apache.org/xerces2-j/install.html) xerces.jar is now deprecated and renamed to xercesImpl.jar, so you have to stick to the old JAR.
xerces.jar is no longer available in the main distribution. You can still download this jar from deprecated distribution. xerces.jar is a Jar file that contains all the parser class files (i.e., it contains the intersection of the contents of xercesImpl.jar and xml-apis.jar).
To be clearer, the technical details are:
The old xerces.jar you have in your libs folder is working, because of the internal folder structure.
The new xerces from the repository has a different folder structure and some weird UTF encoded bytes AIDE is not understanding.

Related

Use already developed android project [with its resources(xml, images, layout)] into another project directly as .xyz file

I have read lots of questions on this site and come to the decision that if you wish to use your already developed code with its resources in android then you have to use it as a library.
But from the Building Android applications with Gradle tutorial I read something like...
Gradle supports a format called Android ARchive (AAR) . An AAR is similar to a JAR file, but it can contain resources as well as compiled bytecode. This allows that an AAR file is included similar to a JAR file**.
Does it means that we can use .aar file as an .jar file but with facility of using resources also?
Then I have tried to crate .aar file with the help of Android Studio, but .aar file doesn't contain layout XMLs or images -- it contains some layout and resources but it doesn't contain projects other resources file.
At last I am having the only same, annoying, stupid question: Can we use whole project with its resources with only one file like .jar or .aar or any other file format?
RajaReddy is quite mistaken. The JAR contains only code; you cannot access resources that way.
Google distributes their own "Google Play Services Library" as an Android library project, containing the binary code in a JAR file in the lib directory, the resources in the res directory, and an UnusedStub class in the src directory. If a better approach were viable yet I think they'd be using it.
UPDATE: While Android Studio is still in beta, it includes (buggy) support for AAR files. Seems this will eventually be the way to go.
Library projects bin folder contains jar file, copy that jar file in your main Application ( project ) libs folder we can get all the resource folders like this.
Follow these steps !
1) make your library project a normal project by deselecting IsLibrary flag.
2) Execute your project as Android Application. (It will not show any error)
3) you'll find a .jar file in bin folder..
4) Copy .jar in libs folder of your main application.
this will works fine with all the resources.
I was looking for the same thing for years. Combining byte code of java and resources (xml and other files) into one package. Currently I don't think its possible because even google has to include add resources separately in google play services lib available in the SDK .
What you can do best is generate a .aar or .jar file and add a folder of missing resource files.

Robospice jars for non maven mode

I'm trying to make a build of a sample project (core-basic), without maven, just by picking the jars located in repository/dependencies/1.4.9/robospice and copying them to Android project libs folder.
The jars that I am copying are specifically these:
commons-io-1.3.2
commons-lang3-3.1
robospice-1.4.9
robospice-cache-1.4.9
However, Eclipse shows this error:
robospice-sample-core/libs/commons-lang3-3.1.jar' in project 'robospice-sample-core' cannot be read or is not a valid ZIP file
Moreover, I cannot access into the contents of the jars, WinRar says that they are corrupted or invalid.
So, what am I doing wrong? Can I really use those jar just by copying them to libs folder or do I have to do something more? Why does eclipse say that they can not be read?
(Thanks in advance. In spite of I know that maven setup for Robospice is strongly advisable, I'd like to know why this happens)
Downloading jar by means of right click on its file name --> Save link returns corrupted jar files. Clicking on "Raw" in the file details, return the correct file.
You must have made a mistake while downloading the files. They can be opened pretty easily with zipinfo on my mac. Download them again from the repo branch or pick the artifacts from maven central.

Create a JAR for Android Library Distribution

I am working on an android library, and wish to export a JAR file that I can distribute for others to use in their apps. I don't want to distribute the source code as it contains details on posting to my web server.
I have tried using the JAR file that is created in the bin directory and copying the jar file to my project and referencing it within my project and ticking the export button.
When I try and run my project referencing the library that I've copied, my app throws an exception with NoClassDefFoundError. I've done some Googling and everything I have found suggests you have to provide the source code and let the user import into their IDE and then reference that project into their app which I don't want to do. It must be possible as other companies provide JAR files for libraries that can be included.
Thanks for your help.
I don't want to distribute the source code as it contains details on posting to my web server.
Bear in mind that anyone who wants to can get that data out of the JAR.
It must be possible as other companies provide JAR files for libraries that can be included.
AFAIK, this recipe still works:
Create an Android library project, with your source code, resources, and such, and get it working
Compile the Java source (e.g., via Ant) and turn it into a JAR file
Create a copy of your original Android library project to serve as a distribution Android library project
Place the compiled JAR from step #2 and put it in libs/ of the distribution library project from step #3.
Delete everything in src/ of the distribution library project (but leave the now-empty src/ directory there)
Distribute the distribution library project (e.g., ZIP it up)
This effectively gives you what you see with the Play Services SDK -- a library project with no source code, but instead a JAR in libs/, along with the resources and such.
I will be reconfiming this recipe tomorrow and will try to remember to update this answer if I find that it needs adjusting for the current crop of tools.
And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.
UPDATE
This recipe works, so long as the library project does not itself have dependencies upon another JAR or library project. In those cases, things seem to get messed up in the build process -- everything can compile, but class references from the dependencies cannot be resolved at runtime.
Did you try putting your jar file in libs folder?And if you are exporting a jar library for android be sure it has no /res folder. As you know you can't reference to your res folder from a jar therefore you have to use library project to reference your res folder (drawable,xml,ect...)On the other hand you cant make your code safe (the part you say about posting to your web service) by using it as jar since it is so easy to retrieve by reverse engineering. you better use some encoding (like base64 or any algorithm that bouncycastle provides)

Exporting .jar to use in Unity with 3rd-party libs included: NoClassDefFoundError

This seems to be a common issue when exporting jars with Eclipse. Now, my context.
I'm attempting to write Java plugins to use in Unity applications. When I did a simple plugin with no external libraries (except the classes.jar so I can call a UnityPlayerActivity), it worked pretty well. "Now, let's use some utils libraries". So I wrote a plugin which uses Jackson libraries to parse and process JSON data, so I can serialize it to a Java object, or just pass RAW data, then build a Unity (C#) object.
I add the libraries directly from the file system to the 'libs' folder (copying the .jars, not linking them), add to build path, check every one in the Order and Export, clean and build, and export to JAR file (not runnable, but simple JAR file). Then, I add my new .jar to Unity Assets/Plugins/Android folder, then build my .apk. As soon as the game starts, I get the classic NoClassDefFoundError because of a constructer using a Jackson class. Checking the .jar contents, I find that Jackson libraries are, indeed, exported and within the 'libs' folder, but still it won't "find" it. The error will be thrown by the main thread, thus the application will crash.
I'm using ADT with API 17, so the libs folder must be named 'libs' (even Eclipse does create this folder when creating a new Android project), JRE 1.6 and Jackson libraries ver. 2.2.0. Already followed a lot of questions here, but none of their suggestions has worked for me.
Any pointers here? Has the Android API version anything to do here? Is there something I'm not doing?
Thanks in advance.
I'm quite new to Java, but as far as I can tell when you use an external JAR file it is dynamically linked. In other words, it stays independent - it is not merged into your library.
This was obvious in my case: The external library I used was Google Analytics. Its JAR file, libGoogleAnalyticsV2.jar, is 126 KB. After I added it to my libs directory and built my library I got an output JAR file of only 2 KB...
My solution was to copy the external library JAR file to Assets/Plugins/Android, together with the JAR file I created.

Is library file present in .apk file?

Actually I want to know that if in my application's libs folder, any library file(e.g .jar file) is present, then after installing(running) that application, will library file present in .apk file?
According to my understanding, library FILE should present in generated .apk file. If I am wrong then please correct me.
If my question is below standard, then extremely sorry for that. Any help will be well appreciated
With recent versions of the Android tools, .jar files in the libs folder are automatically included in the build. (See Dealing with dependencies in Android projects.) So, yes, the library is included in the compiled bytecode (not as a separate file).
If you use ProGuard in a release build, then it will attempt to strip out any code which is not actually used. So, it may be that some parts of the library are included in the final .apk, and some parts are removed.
the answer is yes. The apk is just a zipped version of your compiled project. If you open it with winrar for example, youll see that everithing is in there ;)
You can try it and see yourself but you can not directly see the .jar file under libs folder in the apk generated. Library class files are all together are compiled into a single .dex file. If you decompile that dex file, you can reach the java codes.

Categories

Resources