How to Use External Jars in an Android Project

Adding external library (.jar) in Android Studio

I ran the gradlew.bat file, which gave me the following Exception:

Exception in thread "main" java.lang.RuntimeException: Could not determine wrapper version.at
org.gradle.wrapper.GradleWrapperMain.wrapperVersion(GradleWrapperMain.java:111)at
org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)Caused by:
java.lang.RuntimeException: No build receipt resource found.at
org.gradle.wrapper.GradleWrapperMain.wrapperVersion(GradleWrapperMain.java:97)... 1 more

which brought me to this answer and indeed i had used an ! in my project name. Removing it somehow solved the problem.

Is it possible to embed (combine) an external jar file to my library project in eclipse?

So you want to combine the library and the external jar into one library that your project can link to? That is not possible. You cannot just combine/link two binaries (JARs) and expect them to work as one single library. Your libraries are dynamically linked and not statically, and each library is loaded in a different address space. If you want them to be as one, you need to have the source of the two libraries (your existing library and external jar) and compile them into one (that is, static linking).

Update:

Thanks Sergiu for the insight, that is quite true. The above answer was based on the precinct that a library is a binary loaded by the JRE at runtime at some memory location, and that it is formatted binary with functions/variables loaded at locations calculated by the environment - A General CS theory.

Based on your comments, I googled how to combine two JARs, and your method seems right.

Here's another SO answer: Combine two JARs

Check out the 2nd answer, it also clarifies about the Manifest.mf file.

How to add external jar library file to Intellij Idea android project

if you are using Gradle I believe you also should modify build.gradle for your module.
In section dependencies add line like this:

compile fileTree(dir: 'libs', include: ['*.jar'])

like in this answer:
https://stackoverflow.com/a/13072692/1570833
Hope this helps!
Cheers



Related Topics



Leave a reply



Submit