Issue Details (XML | Word | Printable)

Key: NBANDROID-2
Type: New Feature New Feature
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: radim
Reporter: Martin_Adamek
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
nbandroid

Add support for external Projects/ Libraries / Jars

Created: 07/Jan/09 08:33 PM   Updated: 23/Mar/11 11:55 AM   Resolved: 23/Mar/11 11:55 AM
Component/s: project
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Tags:


 Description  « Hide

Description From jcpalmer@kenai.com 2008-11-25 18:18:42

Created an attachment (id=10) [details]
Mobility Pack Screenshot

  • Add support for including Projects, Libraries, or Jars on the Libraries
    section of Properties of an Android Application. See attachment for how
    Mobility Pack does this. Mobility's option to include them or not in the final
    output does not seem to apply, unless they are an Android Application Project
    themselves. The reason being a jar file cannot be load on an Android Device.
    It must be put into an APK format, DEXed, & signed.
  • Optionally, add an additional Project type called "Android Class Library",
    which functions just as a JAVA Class Library, producing an UN-DEXed jar. This
    is optional, because it is easily simulated by adding android.jar to a JAVA
    Class Library Project.
  • Devise a build process, which assembles all of the content in the final APK
    just prior to DEXing, with a .JAR extension. This may already be being done,
    and deleted. This is done to allow developers to perform custom processing with
    standard tools to produce production media(like Obfuscation). It is then up to
    them to DEX & re-sign. If adding an Android Application Project to another
    Android Application Project is supported, the UN-DEXed jar is what should be
    used.

Of course, if this can be improved on, feel free.



Martin_Adamek added a comment - 07/Jan/09 08:34 PM

Comment #1 From jcpalmer@kenai.com 2008-11-25 21:38:39 -------

Forgot to explicitly state that added it is the files/folders inside jars of
the external libraries are added into the build, not a jar within a jar. The
Mobility Pack just adds the files/folders. Not sure a jar within a jar would
even work.


Jay Kaluza added a comment - 19/Feb/09 05:53 PM - edited

As a workaround to #1, you can right click on Libraries, Add Jar or Add Library and the add this to your build.xml (overriding the project:

Note that this doesn't properly escape spaces in path names, I'm not sure how to do dynamic <arg/> elements in an ant build file.

<target depends="init,compile,-pre-pre-jar,-pre-jar" name="-dex">
<pathconvert pathsep=" " property="javac.classpath.with.spaces">
<path path="${javac.classpath}"/>
</pathconvert>
<exec executable="${dx}" failonerror="true">
<arg value="--dex"/>
<arg value="--output=${basedir}/${intermediate.dex}"/>
<arg value="--positions=lines"/>
<arg file="${build.classes.dir}"/>
<arg line="${javac.classpath.with.spaces}"/>
</exec>
</target>

test

The other thing that would be really nice to have, is a way to have resources inside a library, but I'm not sure the SDK supports that yet. The aapt -x switch get's you part way there, and you can references resources from your library in your project's java code, but the aapt -I switch doesn't seem to actually include the library's references in the final projects references.


Jay Kaluza added a comment - 04/Jan/10 03:25 PM - edited

This does not seem to work, i added it to my build.xml and it did something, the apk file changed in size, (about 2 kb when the external jar is 14 kb), and i get "could not find class" message when calling the code.


Andreas_Ernst added a comment - 03/Apr/10 11:01 AM

I found this:

http://stackoverflow.com/questions/2057804/how-can-i-use-an-external-jar-in-an-android-project-in-netbeans

but this does not work for me, so i looked a little bit in my projects...

add to build.xml:

<project>
<!-- your other entries -->
<target name="-pre-jar">
<copy todir="${build.classes.dir}">
<!--<fileset dir="${external.libs.dir}" />-->
<zipfileset src="<path to your libs>"/>
</copy>
</target>
</project>


Xil3 added a comment - 26/May/10 09:47 AM

It doesn't work with native libraries as well (.so files).

For example, on compile it should automatically add the folder /lib/armeabi/libHello.so to the .apk, but at the moment it doesn't.

What I haven't yet figured out though, is how to properly modify the ANT script to check for a /libs/armeabi directory and add all .so files to /lib/armeabi/*.

I tried the following so far (in the build.xml):

<target name="-pre-jar">
<copy file="${external.libs.dir}/armeabi/libhello-jni.so" tofile="${build.classes.dir}/lib/armeabi/libhello-jni.so" overwrite="true" />
</target>

That compiles fine, but get the following error at run-time:

Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]

Any ideas?


Xil3 added a comment - 26/May/10 10:13 AM

Found a solution for the native libraries - need to modify the build.xml:

<target name="-post-jar">
<zip update="true" destfile="${dist.apk}">
<zipfileset dir="${external.libs.dir}/armeabi" includes="*.so" prefix="lib/armeabi"/>
</zip>
<zip destfile="tmp.apk">
<zipfileset src="${dist.apk}">
<exclude name="META-INF/." />
</zipfileset>
</zip>
<move file="tmp.apk" tofile="${dist.apk}" />
<signjar jar="${dist.apk}" alias="key alias" storepass="password" keypass="password" keystore="/path/to/your/key.keystore"/>
</target>


jglick added a comment - 23/Mar/11 11:55 AM

Probably now obsolete.