Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can have for example in ivy.xml:</p> <pre><code> &lt;configurations&gt; &lt;conf name="compiling"/&gt; &lt;/configurations&gt; &lt;dependencies&gt; &lt;dependency org="com.actionbarsherlock" name="actionbarsherlock" rev="4.3.1" conf="compiling-&gt;master"/&gt; </code></pre> <p>Then if you use ant, in build.xml you could have a target which prepares these "apklib" files for you:</p> <pre><code> &lt;target name="ivy"&gt; &lt;taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="ivy-2.3.0.jar"/&gt; &lt;ivy:retrieve conf="compiling" type="apklib" pattern="libs/[artifact].apklib"/&gt; &lt;!-- For each apklib artifact you need to unpack it so you can use it. --&gt; &lt;unzip src="libs/actionbarsherlock.apklib" dest="apklibs/action-bar-sherlock"/&gt; </code></pre> <p>Now you have src/, res/, etc of the library project in apklibs/action-bar-sherlock.</p> <p>Here is a full build.xml example of how to build an APK of an Android app which depends on multiple Android library projects:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;project name="dev" default="release" xmlns:ivy="antlib:org.apache.ivy.ant"&gt; &lt;!-- According to http://developer.android.com/sdk/requirements.html --&gt; &lt;property name="ant.build.javac.source" value="1.6"/&gt; &lt;property name="ant.build.javac.target" value="1.6"/&gt; &lt;property file="local.properties"/&gt; &lt;property file="project.properties" prefix="android.project"/&gt; &lt;property name="android.target.dir" value="${sdk.dir}/platforms/${android.project.target}"/&gt; &lt;property name="android.jar" value="${android.target.dir}/android.jar"/&gt; &lt;property name="apk.name" value="YOUR_APP.apk"/&gt; &lt;property name="out.dir" value="build/compiled"/&gt; &lt;property name="out.test-classes.dir" value="build/compiled-test"/&gt; &lt;property name="test.libs.dir" value="libs/test"/&gt; &lt;target name="clean"&gt; &lt;delete dir="build"/&gt; &lt;delete dir="gen"/&gt; &lt;delete dir="apklibs"/&gt; &lt;delete file="${apk.name}"/&gt; &lt;/target&gt; &lt;target name="ivy"&gt; &lt;taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="ivy-2.3.0.jar"/&gt; &lt;ivy:retrieve conf="compiling" type="bundle,jar" pattern="libs/[artifact].[ext]"/&gt; &lt;ivy:retrieve conf="compiling" type="apklib" pattern="libs/[artifact].apklib"/&gt; &lt;unzip src="libs/actionbarsherlock.apklib" dest="apklibs/action-bar-sherlock"/&gt; &lt;unzip src="libs/library.apklib" dest="apklibs/view-pager-indicator"/&gt; &lt;path id="lib.path.id"&gt; &lt;fileset dir="libs" includes="*.jar"/&gt; &lt;/path&gt; &lt;ivy:retrieve conf="compiling" type="source" pattern="sources/[artifact].[ext]" sync="true"/&gt; &lt;ivy:retrieve conf="packaging" type="bundle,jar" pattern="[artifact]-[revision].[ext]"/&gt; &lt;ivy:retrieve conf="testing" type="bundle,jar" pattern="libs/test/[artifact].[ext]"/&gt; &lt;/target&gt; &lt;target name="-check-properties" unless="sdk.dir"&gt; &lt;echo&gt; You need to create a local.properties file with: storepass=...the password... sdk.dir=...path to Android SDK... &lt;/echo&gt; &lt;/target&gt; &lt;target name="generate" depends="-check-properties"&gt; &lt;mkdir dir="gen"/&gt; &lt;mkdir dir="build"/&gt; &lt;condition property="debug.mode" value="--debug-mode" else=""&gt; &lt;istrue value="${debug}"/&gt; &lt;/condition&gt; &lt;echo&gt;debug=${debug}&lt;/echo&gt; &lt;echo&gt;debug.mode=${debug.mode}&lt;/echo&gt; &lt;exec executable="${sdk.dir}/platform-tools/aapt" failonerror="true"&gt; &lt;arg value="package"/&gt; &lt;arg line="${debug.mode}"/&gt; &lt;arg value="-f"/&gt; &lt;arg value="-m"/&gt; &lt;arg value="--auto-add-overlay"/&gt; &lt;arg value="-M"/&gt; &lt;arg file="AndroidManifest.xml"/&gt; &lt;arg value="-F"/&gt; &lt;arg file="build/resources.arsc"/&gt; &lt;arg value="-I"/&gt; &lt;arg file="${android.jar}"/&gt; &lt;arg value="-J"/&gt; &lt;arg file="gen"/&gt; &lt;arg value="-S"/&gt; &lt;arg file="facebook-android-sdk/facebook/res"/&gt; &lt;arg value="-S"/&gt; &lt;arg file="apklibs/view-pager-indicator/res"/&gt; &lt;arg value="-S"/&gt; &lt;arg file="barone/res"/&gt; &lt;arg value="-S"/&gt; &lt;arg file="apklibs/action-bar-sherlock/res"/&gt; &lt;arg value="-S"/&gt; &lt;arg file="res"/&gt; &lt;arg value="--extra-packages"/&gt; &lt;arg value="com.facebook.android:com.viewpagerindicator:com.triposo.barone:com.actionbarsherlock"/&gt; &lt;arg value="-A"/&gt; &lt;arg file="assets"/&gt; &lt;/exec&gt; &lt;taskdef name="buildconfig" classname="com.android.ant.BuildConfigTask" classpath="${sdk.dir}/tools/lib/anttasks.jar"/&gt; &lt;buildconfig genFolder="gen" package="com.actionbarsherlock" buildType="${debug}" previousBuildType=""/&gt; &lt;buildconfig genFolder="gen" package="COM.YOUR.PACKAGE" buildType="${debug}" previousBuildType=""/&gt; &lt;/target&gt; &lt;target name="compile" depends="clean, ivy, generate"&gt; &lt;mkdir dir="${out.dir}"/&gt; &lt;javac destdir="${out.dir}" debug="true" includeantruntime="false"&gt; &lt;src path="src"/&gt; &lt;src path="facebook-android-sdk/facebook/src"/&gt; &lt;src path="apklibs/view-pager-indicator/src"/&gt; &lt;src path="barone/src"/&gt; &lt;src path="apklibs/action-bar-sherlock/src"/&gt; &lt;src path="gen"/&gt; &lt;classpath&gt; &lt;path refid="lib.path.id"/&gt; &lt;pathelement path="${android.jar}"/&gt; &lt;/classpath&gt; &lt;/javac&gt; &lt;copy todir="${out.dir}"&gt; &lt;fileset dir="src" excludes="**/*.java"/&gt; &lt;fileset dir="gen" excludes="**/*.java"/&gt; &lt;/copy&gt; &lt;/target&gt; &lt;target name="apk-unsigned" depends="compile"&gt; &lt;!-- Prepare the .class files and the .properties files. --&gt; &lt;taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="jarjar-1.1.jar"/&gt; &lt;jarjar jarfile="build/app.jar" duplicate="preserve"&gt; &lt;fileset dir="${out.dir}"/&gt; &lt;zipgroupfileset dir="libs" includes="*.jar"/&gt; &lt;keep pattern="COM.YOUR.PACKAGE.**"/&gt; &lt;keep pattern="com.amazonaws.**"/&gt; &lt;keep pattern="com.facebook.android.**"/&gt; &lt;keep pattern="com.google.android.apps.analytics.**"/&gt; &lt;keep pattern="com.google.gson.GsonBuilder"/&gt; &lt;keep pattern="com.google.common.base.Splitter"/&gt; &lt;keep pattern="com.google.common.io.Files"/&gt; &lt;keep pattern="com.google.common.base.Charsets"/&gt; &lt;keep pattern="javax.annotation.Nullable"/&gt; &lt;keep pattern="org.apache.commons.lang3.**"/&gt; &lt;keep pattern="android.support.v4.**"/&gt; &lt;!-- Required because these seem to be missing from the phone JVM and they are used by our CursorMapper. --&gt; &lt;keep pattern="javax.annotation.**"/&gt; &lt;!-- From http://actionbarsherlock.com/faq.html --&gt; &lt;keep pattern="com.actionbarsherlock.**"/&gt; &lt;keep pattern="*Annotation*"/&gt; &lt;rule pattern="com.google.common.**" result="COM.YOUR.PACKAGE.vendor.com.google.common.@1"/&gt; &lt;!-- We rename this because at least "HTC Sensation XL with Beats Audio" has a bad Gson library which we don't want to use. --&gt; &lt;rule pattern="com.google.gson.**" result="COM.YOUR.PACKAGE.vendor.com.google.gson.@1"/&gt; &lt;/jarjar&gt; &lt;!-- Convert the .class files to Dalvik byte code. --&gt; &lt;exec executable="${sdk.dir}/platform-tools/dx" failonerror="true"&gt; &lt;arg value="--dex"/&gt; &lt;arg value="--output=build/classes.dex"/&gt; &lt;arg file="build/app.jar"/&gt; &lt;/exec&gt; &lt;!-- Package the resources and the classes into an apk. --&gt; &lt;taskdef name="apkbuilder" classname="com.android.ant.ApkBuilderTask" classpath="${sdk.dir}/tools/lib/anttasks.jar"/&gt; &lt;apkbuilder outfolder="." resourcefile="build/resources.arsc" apkfilepath="build/unsigned.apk" verbose="false"&gt; &lt;dex path="build/classes.dex"/&gt; &lt;sourcefolder path="${out.dir}"/&gt; &lt;/apkbuilder&gt; &lt;/target&gt; &lt;!-- We need this because I use JDK 7, see the Caution in: http://developer.android.com/guide/publishing/app-signing.html#signapp Ant 1.8.3 allows specifying a sigalg and a digestalg, but I don't have it yet, so we have this macro instead. --&gt; &lt;macrodef name="signjarjdk7"&gt; &lt;attribute name="jar" /&gt; &lt;attribute name="signedjar" /&gt; &lt;attribute name="keystore" /&gt; &lt;attribute name="storepass" /&gt; &lt;attribute name="alias" /&gt; &lt;sequential&gt; &lt;exec executable="jarsigner" failonerror="true"&gt; &lt;arg line="-digestalg SHA1 -sigalg MD5withRSA" /&gt; &lt;arg line="-keystore @{keystore} -storepass @{storepass}" /&gt; &lt;arg line="-signedjar &amp;quot;@{signedjar}&amp;quot;" /&gt; &lt;arg line="&amp;quot;@{jar}&amp;quot; @{alias}" /&gt; &lt;/exec&gt; &lt;/sequential&gt; &lt;/macrodef&gt; &lt;macrodef name="zipalign"&gt; &lt;attribute name="apk" /&gt; &lt;attribute name="optimizedapk" /&gt; &lt;sequential&gt; &lt;exec executable="${sdk.dir}/tools/zipalign" failonerror="true"&gt; &lt;arg value="-f"/&gt; &lt;arg value="4"/&gt; &lt;arg file="@{apk}"/&gt; &lt;arg file="@{optimizedapk}"/&gt; &lt;/exec&gt; &lt;/sequential&gt; &lt;/macrodef&gt; &lt;!-- Make an apk. See http://developer.android.com/guide/developing/building/index.html --&gt; &lt;macrodef name="apk"&gt; &lt;attribute name="keystore"/&gt; &lt;attribute name="storepass"/&gt; &lt;attribute name="alias"/&gt; &lt;sequential&gt; &lt;antcall target="apk-unsigned"/&gt; &lt;!-- Sign the apk for release. --&gt; &lt;signjarjdk7 keystore="@{keystore}" storepass="@{storepass}" alias="@{alias}" jar="build/unsigned.apk" signedjar="build/unaligned.apk"/&gt; &lt;!-- Optimize the apk to improve speed. --&gt; &lt;zipalign apk="build/unaligned.apk" optimizedapk="${apk.name}"/&gt; &lt;/sequential&gt; &lt;/macrodef&gt; &lt;target name="release"&gt; &lt;property name="debug" value="false"/&gt; &lt;apk keystore="keystore" storepass="${storepass}" alias="YOUR ALIAS"/&gt; &lt;/target&gt; &lt;target name="debug"&gt; &lt;property name="debug" value="true"/&gt; &lt;apk keystore="debug.keystore" storepass="android" alias="androiddebugkey"/&gt; &lt;/target&gt; &lt;target name="compile.tests" depends="compile"&gt; &lt;mkdir dir="${out.test-classes.dir}"/&gt; &lt;javac encoding="ascii" source="1.6" target="1.6" debug="true" extdirs="" includeantruntime="false" destdir="${out.test-classes.dir}"&gt; &lt;src path="test"/&gt; &lt;classpath&gt; &lt;pathelement path="${out.dir}"/&gt; &lt;path refid="lib.path.id"/&gt; &lt;fileset dir="${test.libs.dir}" includes="*.jar"/&gt; &lt;pathelement path="${android.jar}"/&gt; &lt;/classpath&gt; &lt;/javac&gt; &lt;/target&gt; &lt;target name="test" depends="compile.tests"&gt; &lt;mkdir dir="${basedir}/out/reports/tests"/&gt; &lt;junit showoutput="true" failureproperty="junit.failure"&gt; &lt;formatter type="plain" usefile="false"/&gt; &lt;formatter type="xml"/&gt; &lt;batchtest todir="${basedir}/out/reports/tests"&gt; &lt;fileset dir="test"&gt; &lt;include name="**/*Test.java"/&gt; &lt;/fileset&gt; &lt;/batchtest&gt; &lt;classpath&gt; &lt;pathelement path="${out.dir}"/&gt; &lt;path refid="lib.path.id"/&gt; &lt;fileset dir="${test.libs.dir}" includes="*.jar"/&gt; &lt;pathelement path="${android.jar}"/&gt; &lt;pathelement path="${out.test-classes.dir}"/&gt; &lt;/classpath&gt; &lt;/junit&gt; &lt;fail if="junit.failure" message="Unit test(s) failed. See reports!"/&gt; &lt;/target&gt; &lt;/project&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload