DexMaker.html revision e3ecebfb7a89fbe549680e47d7e6f306d5ae146c
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<!--NewPage-->
3<HTML>
4<HEAD>
5<!-- Generated by javadoc (build 1.6.0_26) on Mon Jan 09 16:02:37 EST 2012 -->
6<TITLE>
7DexMaker (dexmaker)
8</TITLE>
9
10<META NAME="date" CONTENT="2012-01-09">
11
12<LINK REL ="stylesheet" TYPE="text/css" HREF="/stylesheet.css" TITLE="Style">
13
14<SCRIPT type="text/javascript">
15function windowTitle()
16{
17    if (location.href.indexOf('is-external=true') == -1) {
18        parent.document.title="DexMaker (dexmaker)";
19    }
20}
21</SCRIPT>
22<NOSCRIPT>
23</NOSCRIPT>
24
25</HEAD>
26
27<BODY BGCOLOR="white" onload="windowTitle();">
28<HR>
29
30
31<!-- ========= START OF TOP NAVBAR ======= -->
32<A NAME="navbar_top"><!-- --></A>
33<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
34<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
35<TR>
36<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
37<A NAME="navbar_top_firstrow"><!-- --></A>
38<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
39  <TR ALIGN="center" VALIGN="top">
40  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
41  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
42  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
43  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
44  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
45  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
46  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
47  </TR>
48</TABLE>
49</TD>
50<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
51</EM>
52</TD>
53</TR>
54
55<TR>
56<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
57&nbsp;<A HREF="/com/google/dexmaker/Comparison.html" title="enum in com.google.dexmaker"><B>PREV CLASS</B></A>&nbsp;
58&nbsp;<A HREF="/com/google/dexmaker/FieldId.html" title="class in com.google.dexmaker"><B>NEXT CLASS</B></A></FONT></TD>
59<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
60  <A HREF="/index.html?com/google/dexmaker/DexMaker.html" target="_top"><B>FRAMES</B></A>  &nbsp;
61&nbsp;<A HREF="DexMaker.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
62&nbsp;<SCRIPT type="text/javascript">
63  <!--
64  if(window==top) {
65    document.writeln('<A HREF="/allclasses-noframe.html"><B>All Classes</B></A>');
66  }
67  //-->
68</SCRIPT>
69<NOSCRIPT>
70  <A HREF="/allclasses-noframe.html"><B>All Classes</B></A>
71</NOSCRIPT>
72
73
74</FONT></TD>
75</TR>
76<TR>
77<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
78  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
79<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
80DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
81</TR>
82</TABLE>
83<A NAME="skip-navbar_top"></A>
84<!-- ========= END OF TOP NAVBAR ========= -->
85
86<HR>
87<!-- ======== START OF CLASS DATA ======== -->
88<H2>
89<FONT SIZE="-1">
90com.google.dexmaker</FONT>
91<BR>
92Class DexMaker</H2>
93<PRE>
94java.lang.Object
95  <IMG SRC="/resources/inherit.gif" ALT="extended by "><B>com.google.dexmaker.DexMaker</B>
96</PRE>
97<HR>
98<DL>
99<DT><PRE>public final class <B>DexMaker</B><DT>extends java.lang.Object</DL>
100</PRE>
101
102<P>
103Generates a </i><strong>D</strong>alvik <strong>EX</strong>ecutable (dex)
104 file for execution on Android. Dex files define classes and interfaces,
105 including their member methods and fields, executable code, and debugging
106 information. They also define annotations, though this API currently has no
107 facility to create a dex file that contains annotations.
108
109 <p>This library is intended to satisfy two use cases:
110 <ul>
111   <li><strong>For runtime code generation.</strong> By embedding this library
112       in your Android application, you can dynamically generate and load
113       executable code. This approach takes advantage of the fact that the
114       host environment and target environment are both Android.
115   <li><strong>For compile time code generation.</strong> You may use this
116       library as a part of a compiler that targets Android. In this scenario
117       the generated dex file must be installed on an Android device before it
118       can be executed.
119 </ul>
120
121 <h3>Example: Fibonacci</h3>
122 To illustrate how this API is used, we'll use DexMaker to generate a class
123 equivalent to the following Java source: <pre> <code>package com.publicobject.fib;
124
125 public class Fibonacci {
126   public static int fib(int i) {
127     if (i &lt; 2) {
128       return i;
129     }
130     return fib(i - 1) + fib(i - 2);
131   }
132 }</code></pre>
133
134 <p>We start by creating a <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker"><CODE>TypeId</CODE></A> to identify the generated <code>Fibonacci</code> class. DexMaker identifies types by their internal names like
135 <code>Ljava/lang/Object;</code> rather than their Java identifiers like <code>java.lang.Object</code>. <pre>   <code>TypeId&lt;?&gt; fibonacci = TypeId.get("Lcom/google/dexmaker/examples/Fibonacci;");
136 </code></pre>
137
138 <p>Next we declare the class. It allows us to specify the type's source file
139 for stack traces, its modifiers, its superclass, and the interfaces it
140 implements. In this case, <code>Fibonacci</code> is a public class that extends
141 from <code>Object</code>: <pre>   <code>String fileName = "Fibonacci.generated";
142   DexMaker dexMaker = new DexMaker();
143   dexMaker.declare(fibonacci, fileName, Modifier.PUBLIC, TypeId.OBJECT);
144 </code></pre>
145 It is illegal to declare members of a class without also declaring the class
146 itself.
147
148 <p>To make it easier to go from our Java method to dex instructions, we'll
149 manually translate it to pseudocode fit for an assembler. We need to replace
150 control flow like <code>if()</code> blocks and <code>for()</code> loops with labels and
151 branches. We'll also avoid performing multiple operations in one statement,
152 using local variables to hold intermediate values as necessary:
153 <pre>   <code>int constant1 = 1;
154   int constant2 = 2;
155   if (i &lt; constant2) goto baseCase;
156   int a = i - constant1;
157   int b = i - constant2;
158   int c = fib(a);
159   int d = fib(b);
160   int result = c + d;
161   return result;
162 baseCase:
163   return i;
164 </code></pre>
165
166 <p>We look up the <code>MethodId</code> for the method on the declaring type. This
167 takes the method's return type (possibly <A HREF="/com/google/dexmaker/TypeId.html#VOID"><CODE>TypeId.VOID</CODE></A>), its name and
168 its parameters types. Next we declare the method, specifying its modifiers by
169 bitwise ORing constants from <CODE>Modifier</CODE>. The declare
170 call returns a <A HREF="/com/google/dexmaker/Code.html" title="class in com.google.dexmaker"><CODE>Code</CODE></A> object, which we'll use to define the method's
171 instructions. <pre>   <code>MethodId&lt;?, Integer&gt; fib = fibonacci.getMethod(TypeId.INT, "fib", TypeId.INT);
172   Code code = dexMaker.declare(fib, Modifier.PUBLIC | Modifier.STATIC);
173 </code></pre>
174
175 <p>One limitation of <code>DexMaker</code>'s API is that it requires all local
176 variables to be created before any instructions are emitted. Use <A HREF="/com/google/dexmaker/Code.html#newLocal(com.google.dexmaker.TypeId)"><CODE>newLocal()</CODE></A> to create a new local variable. The method's
177 parameters are exposed as locals using <A HREF="/com/google/dexmaker/Code.html#getParameter(int, com.google.dexmaker.TypeId)"><CODE>getParameter()</CODE></A>. For non-static methods the <code>this</code> pointer is exposed
178 using <A HREF="/com/google/dexmaker/Code.html#getThis(com.google.dexmaker.TypeId)"><CODE>getThis()</CODE></A>. Here we declare all of the local
179 variables that we'll need for our <code>fib()</code> method: <pre>   <code>Local&lt;Integer&gt; i = code.getParameter(0, TypeId.INT);
180   Local&lt;Integer&gt; constant1 = code.newLocal(TypeId.INT);
181   Local&lt;Integer&gt; constant2 = code.newLocal(TypeId.INT);
182   Local&lt;Integer&gt; a = code.newLocal(TypeId.INT);
183   Local&lt;Integer&gt; b = code.newLocal(TypeId.INT);
184   Local&lt;Integer&gt; c = code.newLocal(TypeId.INT);
185   Local&lt;Integer&gt; d = code.newLocal(TypeId.INT);
186   Local&lt;Integer&gt; result = code.newLocal(TypeId.INT);
187 </code></pre>
188
189 <p>Notice that <A HREF="/com/google/dexmaker/Local.html" title="class in com.google.dexmaker"><CODE>Local</CODE></A> has a type parameter of <code>Integer</code>. This is
190 useful for generating code that works with existing types like <code>String</code>
191 and <code>Integer</code>, but it can be a hindrance when generating code that
192 involves new types. For this reason you may prefer to use raw types only and
193 add <code>@SuppressWarnings("unsafe")</code> on your calling code. This will yield
194 the same result but you won't get IDE support if you make a type error.
195
196 <p>We're ready to start defining our method's instructions. The <A HREF="/com/google/dexmaker/Code.html" title="class in com.google.dexmaker"><CODE>Code</CODE></A>
197 class catalogs the available instructions and their use. <pre>   <code>code.loadConstant(constant1, 1);
198   code.loadConstant(constant2, 2);
199   Label baseCase = new Label();
200   code.compare(Comparison.LT, baseCase, i, constant2);
201   code.op(BinaryOp.SUBTRACT, a, i, constant1);
202   code.op(BinaryOp.SUBTRACT, b, i, constant2);
203   code.invokeStatic(fib, c, a);
204   code.invokeStatic(fib, d, b);
205   code.op(BinaryOp.ADD, result, c, d);
206   code.returnValue(result);
207   code.mark(baseCase);
208   code.returnValue(i);
209 </code></pre>
210
211 <p>We're done defining the dex file. We just need to write it to the
212 filesystem or load it into the current process. For this example we'll load
213 the generated code into the current process. This only works when the current
214 process is running on Android. We use <A HREF="/com/google/dexmaker/DexMaker.html#generateAndLoad(java.lang.ClassLoader, java.io.File)"><CODE>generateAndLoad(java.lang.ClassLoader, java.io.File)</CODE></A> which takes
215 the class loader that will be used as our generated code's parent class
216 loader. It also requires a directory where temporary files can be written.
217 <pre>   <code>ClassLoader loader = dexMaker.generateAndLoad(
218       Fibonacci.class.getClassLoader(), getDataDirectory());
219 </code></pre>
220 Finally we'll use reflection to lookup our generated class on its class
221 loader and invoke its <code>fib()</code> method: <pre>   <code>Class&lt;?&gt; fibonacciClass = loader.loadClass("com.google.dexmaker.examples.Fibonacci");
222   Method fibMethod = fibonacciClass.getMethod("fib", int.class);
223   System.out.println(fibMethod.invoke(null, 8));
224 </code></pre>
225<P>
226
227<P>
228<HR>
229
230<P>
231
232<!-- ======== CONSTRUCTOR SUMMARY ======== -->
233
234<A NAME="constructor_summary"><!-- --></A>
235<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
236<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
237<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
238<B>Constructor Summary</B></FONT></TH>
239</TR>
240<TR BGCOLOR="white" CLASS="TableRowColor">
241<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#DexMaker()">DexMaker</A></B>()</CODE>
242
243<BR>
244&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
245</TR>
246</TABLE>
247&nbsp;
248<!-- ========== METHOD SUMMARY =========== -->
249
250<A NAME="method_summary"><!-- --></A>
251<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
252<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
253<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
254<B>Method Summary</B></FONT></TH>
255</TR>
256<TR BGCOLOR="white" CLASS="TableRowColor">
257<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
258<CODE>&nbsp;void</CODE></FONT></TD>
259<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#declare(com.google.dexmaker.FieldId, int, java.lang.Object)">declare</A></B>(<A HREF="/com/google/dexmaker/FieldId.html" title="class in com.google.dexmaker">FieldId</A>&lt;?,?&gt;&nbsp;fieldId,
260        int&nbsp;flags,
261        java.lang.Object&nbsp;staticValue)</CODE>
262
263<BR>
264&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Declares a field.</TD>
265</TR>
266<TR BGCOLOR="white" CLASS="TableRowColor">
267<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
268<CODE>&nbsp;<A HREF="/com/google/dexmaker/Code.html" title="class in com.google.dexmaker">Code</A></CODE></FONT></TD>
269<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#declare(com.google.dexmaker.MethodId, int)">declare</A></B>(<A HREF="/com/google/dexmaker/MethodId.html" title="class in com.google.dexmaker">MethodId</A>&lt;?,?&gt;&nbsp;method,
270        int&nbsp;flags)</CODE>
271
272<BR>
273&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Declares a method.</TD>
274</TR>
275<TR BGCOLOR="white" CLASS="TableRowColor">
276<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
277<CODE>&nbsp;void</CODE></FONT></TD>
278<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#declare(com.google.dexmaker.TypeId, java.lang.String, int, com.google.dexmaker.TypeId, com.google.dexmaker.TypeId...)">declare</A></B>(<A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A>&lt;?&gt;&nbsp;type,
279        java.lang.String&nbsp;sourceFile,
280        int&nbsp;flags,
281        <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A>&lt;?&gt;&nbsp;supertype,
282        <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A>&lt;?&gt;...&nbsp;interfaces)</CODE>
283
284<BR>
285&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Declares <code>type</code>.</TD>
286</TR>
287<TR BGCOLOR="white" CLASS="TableRowColor">
288<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
289<CODE>&nbsp;<A HREF="/com/google/dexmaker/Code.html" title="class in com.google.dexmaker">Code</A></CODE></FONT></TD>
290<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#declareConstructor(com.google.dexmaker.MethodId, int)">declareConstructor</A></B>(<A HREF="/com/google/dexmaker/MethodId.html" title="class in com.google.dexmaker">MethodId</A>&lt;?,?&gt;&nbsp;method,
291                   int&nbsp;flags)</CODE>
292
293<BR>
294&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Declares a constructor.</TD>
295</TR>
296<TR BGCOLOR="white" CLASS="TableRowColor">
297<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
298<CODE>&nbsp;byte[]</CODE></FONT></TD>
299<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#generate()">generate</A></B>()</CODE>
300
301<BR>
302&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Generates a dex file and returns its bytes.</TD>
303</TR>
304<TR BGCOLOR="white" CLASS="TableRowColor">
305<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
306<CODE>&nbsp;java.lang.ClassLoader</CODE></FONT></TD>
307<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#generateAndLoad(java.lang.ClassLoader, java.io.File)">generateAndLoad</A></B>(java.lang.ClassLoader&nbsp;parent,
308                java.io.File&nbsp;dexDir)</CODE>
309
310<BR>
311&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Generates a dex file and loads its types into the current process.</TD>
312</TR>
313</TABLE>
314&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
315<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
316<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
317<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
318</TR>
319<TR BGCOLOR="white" CLASS="TableRowColor">
320<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
321</TR>
322</TABLE>
323&nbsp;
324<P>
325
326<!-- ========= CONSTRUCTOR DETAIL ======== -->
327
328<A NAME="constructor_detail"><!-- --></A>
329<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
330<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
331<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
332<B>Constructor Detail</B></FONT></TH>
333</TR>
334</TABLE>
335
336<A NAME="DexMaker()"><!-- --></A><H3>
337DexMaker</H3>
338<PRE>
339public <B>DexMaker</B>()</PRE>
340<DL>
341</DL>
342
343<!-- ============ METHOD DETAIL ========== -->
344
345<A NAME="method_detail"><!-- --></A>
346<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
347<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
348<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
349<B>Method Detail</B></FONT></TH>
350</TR>
351</TABLE>
352
353<A NAME="declare(com.google.dexmaker.TypeId, java.lang.String, int, com.google.dexmaker.TypeId, com.google.dexmaker.TypeId...)"><!-- --></A><H3>
354declare</H3>
355<PRE>
356public void <B>declare</B>(<A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A>&lt;?&gt;&nbsp;type,
357                    java.lang.String&nbsp;sourceFile,
358                    int&nbsp;flags,
359                    <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A>&lt;?&gt;&nbsp;supertype,
360                    <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A>&lt;?&gt;...&nbsp;interfaces)</PRE>
361<DL>
362<DD>Declares <code>type</code>.
363<P>
364<DD><DL>
365<DT><B>Parameters:</B><DD><CODE>flags</CODE> - a bitwise combination of <CODE>Modifier.PUBLIC</CODE>, <CODE>Modifier.FINAL</CODE> and <CODE>Modifier.ABSTRACT</CODE>.</DL>
366</DD>
367</DL>
368<HR>
369
370<A NAME="declareConstructor(com.google.dexmaker.MethodId, int)"><!-- --></A><H3>
371declareConstructor</H3>
372<PRE>
373public <A HREF="/com/google/dexmaker/Code.html" title="class in com.google.dexmaker">Code</A> <B>declareConstructor</B>(<A HREF="/com/google/dexmaker/MethodId.html" title="class in com.google.dexmaker">MethodId</A>&lt;?,?&gt;&nbsp;method,
374                               int&nbsp;flags)</PRE>
375<DL>
376<DD>Declares a constructor. The name of <code>method</code> must be "<init>",
377 as it is on all instances returned by <A HREF="/com/google/dexmaker/TypeId.html#getConstructor(com.google.dexmaker.TypeId...)"><CODE>TypeId.getConstructor(com.google.dexmaker.TypeId<?>...)</CODE></A>.
378<P>
379<DD><DL>
380<DT><B>Parameters:</B><DD><CODE>flags</CODE> - a bitwise combination of <CODE>Modifier.PUBLIC</CODE>, <CODE>Modifier.PRIVATE</CODE>, <CODE>Modifier.PROTECTED</CODE>, <CODE>Modifier.STATIC</CODE>,
381     <CODE>Modifier.FINAL</CODE>, and <CODE>Modifier.VARARGS</CODE>.</DL>
382</DD>
383</DL>
384<HR>
385
386<A NAME="declare(com.google.dexmaker.MethodId, int)"><!-- --></A><H3>
387declare</H3>
388<PRE>
389public <A HREF="/com/google/dexmaker/Code.html" title="class in com.google.dexmaker">Code</A> <B>declare</B>(<A HREF="/com/google/dexmaker/MethodId.html" title="class in com.google.dexmaker">MethodId</A>&lt;?,?&gt;&nbsp;method,
390                    int&nbsp;flags)</PRE>
391<DL>
392<DD>Declares a method. The name of <code>method</code> must not be "<init>".
393<P>
394<DD><DL>
395<DT><B>Parameters:</B><DD><CODE>flags</CODE> - a bitwise combination of <CODE>Modifier.PUBLIC</CODE>, <CODE>Modifier.PRIVATE</CODE>, <CODE>Modifier.PROTECTED</CODE>, <CODE>Modifier.STATIC</CODE>,
396     <CODE>Modifier.FINAL</CODE>, and <CODE>Modifier.VARARGS</CODE>.</DL>
397</DD>
398</DL>
399<HR>
400
401<A NAME="declare(com.google.dexmaker.FieldId, int, java.lang.Object)"><!-- --></A><H3>
402declare</H3>
403<PRE>
404public void <B>declare</B>(<A HREF="/com/google/dexmaker/FieldId.html" title="class in com.google.dexmaker">FieldId</A>&lt;?,?&gt;&nbsp;fieldId,
405                    int&nbsp;flags,
406                    java.lang.Object&nbsp;staticValue)</PRE>
407<DL>
408<DD>Declares a field.
409<P>
410<DD><DL>
411<DT><B>Parameters:</B><DD><CODE>flags</CODE> - a bitwise combination of <CODE>Modifier.PUBLIC</CODE>, <CODE>Modifier.PRIVATE</CODE>, <CODE>Modifier.PROTECTED</CODE>, <CODE>Modifier.STATIC</CODE>,
412     <CODE>Modifier.FINAL</CODE>, <CODE>Modifier.VOLATILE</CODE>, and <CODE>Modifier.TRANSIENT</CODE>.</DL>
413</DD>
414</DL>
415<HR>
416
417<A NAME="generate()"><!-- --></A><H3>
418generate</H3>
419<PRE>
420public byte[] <B>generate</B>()</PRE>
421<DL>
422<DD>Generates a dex file and returns its bytes.
423<P>
424<DD><DL>
425</DL>
426</DD>
427</DL>
428<HR>
429
430<A NAME="generateAndLoad(java.lang.ClassLoader, java.io.File)"><!-- --></A><H3>
431generateAndLoad</H3>
432<PRE>
433public java.lang.ClassLoader <B>generateAndLoad</B>(java.lang.ClassLoader&nbsp;parent,
434                                             java.io.File&nbsp;dexDir)
435                                      throws java.io.IOException</PRE>
436<DL>
437<DD>Generates a dex file and loads its types into the current process.
438
439 <p>All parameters are optional; you may pass <code>null</code> and suitable
440 defaults will be used.
441
442 <p>If you opt to provide your own <code>dexDir</code>, take care to ensure
443 that it is not world-writable, otherwise a malicious app may be able
444 to inject code into your process.  A suitable parameter is:
445 <code>getApplicationContext().getDir("dx", Context.MODE_PRIVATE); </code>
446<P>
447<DD><DL>
448<DT><B>Parameters:</B><DD><CODE>parent</CODE> - the parent ClassLoader to be used when loading
449     our generated types<DD><CODE>dexDir</CODE> - the destination directory where generated and
450     optimized dex files will be written.
451<DT><B>Throws:</B>
452<DD><CODE>java.io.IOException</CODE></DL>
453</DD>
454</DL>
455<!-- ========= END OF CLASS DATA ========= -->
456<HR>
457
458
459<!-- ======= START OF BOTTOM NAVBAR ====== -->
460<A NAME="navbar_bottom"><!-- --></A>
461<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
462<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
463<TR>
464<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
465<A NAME="navbar_bottom_firstrow"><!-- --></A>
466<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
467  <TR ALIGN="center" VALIGN="top">
468  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
469  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
470  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
471  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
472  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
473  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
474  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="/help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
475  </TR>
476</TABLE>
477</TD>
478<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
479</EM>
480</TD>
481</TR>
482
483<TR>
484<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
485&nbsp;<A HREF="/com/google/dexmaker/Comparison.html" title="enum in com.google.dexmaker"><B>PREV CLASS</B></A>&nbsp;
486&nbsp;<A HREF="/com/google/dexmaker/FieldId.html" title="class in com.google.dexmaker"><B>NEXT CLASS</B></A></FONT></TD>
487<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
488  <A HREF="/index.html?com/google/dexmaker/DexMaker.html" target="_top"><B>FRAMES</B></A>  &nbsp;
489&nbsp;<A HREF="DexMaker.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
490&nbsp;<SCRIPT type="text/javascript">
491  <!--
492  if(window==top) {
493    document.writeln('<A HREF="/allclasses-noframe.html"><B>All Classes</B></A>');
494  }
495  //-->
496</SCRIPT>
497<NOSCRIPT>
498  <A HREF="/allclasses-noframe.html"><B>All Classes</B></A>
499</NOSCRIPT>
500
501
502</FONT></TD>
503</TR>
504<TR>
505<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
506  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
507<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
508DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
509</TR>
510</TABLE>
511<A NAME="skip-navbar_bottom"></A>
512<!-- ======== END OF BOTTOM NAVBAR ======= -->
513
514<HR>
515
516</BODY>
517</HTML>
518