DexMaker.html revision 5692b3b0303c55524ff206dc7840ffdb1fa47628
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 Tue Jan 10 12:29:36 EST 2012 --> 6<TITLE> 7DexMaker (dexmaker) 8</TITLE> 9 10<META NAME="date" CONTENT="2012-01-10"> 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> </TD> 41 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 42 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 43 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 44 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="/deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 45 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="/index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 46 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="/help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </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 <A HREF="/com/google/dexmaker/Comparison.html" title="enum in com.google.dexmaker"><B>PREV CLASS</B></A> 58 <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> 61 <A HREF="DexMaker.html" target="_top"><B>NO FRAMES</B></A> 62 <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: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD> 79<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 80DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <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> 94<A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A> 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 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></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 < 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<?> 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 < 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 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true" title="class or interface in java.lang.reflect"><CODE>Modifier</CODE></A>. 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<?, Integer> 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<Integer> i = code.getParameter(0, TypeId.INT); 180 Local<Integer> constant1 = code.newLocal(TypeId.INT); 181 Local<Integer> constant2 = code.newLocal(TypeId.INT); 182 Local<Integer> a = code.newLocal(TypeId.INT); 183 Local<Integer> b = code.newLocal(TypeId.INT); 184 Local<Integer> c = code.newLocal(TypeId.INT); 185 Local<Integer> d = code.newLocal(TypeId.INT); 186 Local<Integer> 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()</CODE></A> which takes the class loader that will be used as our 215 generated code's parent class loader. It also requires a directory where 216 temporary files can be written. <pre> <code>ClassLoader loader = dexMaker.generateAndLoad( 217 FibonacciMaker.class.getClassLoader(), getDataDirectory()); 218 </code></pre> 219 Finally we'll use reflection to lookup our generated class on its class 220 loader and invoke its <code>fib()</code> method: <pre> <code>Class<?> fibonacciClass = loader.loadClass("com.google.dexmaker.examples.Fibonacci"); 221 Method fibMethod = fibonacciClass.getMethod("fib", int.class); 222 System.out.println(fibMethod.invoke(null, 8)); 223 </code></pre> 224<P> 225 226<P> 227<HR> 228 229<P> 230 231<!-- ======== CONSTRUCTOR SUMMARY ======== --> 232 233<A NAME="constructor_summary"><!-- --></A> 234<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 235<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 236<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> 237<B>Constructor Summary</B></FONT></TH> 238</TR> 239<TR BGCOLOR="white" CLASS="TableRowColor"> 240<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#DexMaker()">DexMaker</A></B>()</CODE> 241 242<BR> 243 Creates a new <code>DexMaker</code> instance, which can be used to create a 244 single dex file.</TD> 245</TR> 246</TABLE> 247 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> 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><?,?> fieldId, 260 int flags, 261 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> staticValue)</CODE> 262 263<BR> 264 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> <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><?,?> method, 270 int flags)</CODE> 271 272<BR> 273 Declares a method or constructor.</TD> 274</TR> 275<TR BGCOLOR="white" CLASS="TableRowColor"> 276<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 277<CODE> 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><?> type, 279 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> sourceFile, 280 int flags, 281 <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A><?> supertype, 282 <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A><?>... interfaces)</CODE> 283 284<BR> 285 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> byte[]</CODE></FONT></TD> 290<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#generate()">generate</A></B>()</CODE> 291 292<BR> 293 Generates a dex file and returns its bytes.</TD> 294</TR> 295<TR BGCOLOR="white" CLASS="TableRowColor"> 296<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 297<CODE> <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html?is-external=true" title="class or interface in java.lang">ClassLoader</A></CODE></FONT></TD> 298<TD><CODE><B><A HREF="/com/google/dexmaker/DexMaker.html#generateAndLoad(java.lang.ClassLoader, java.io.File)">generateAndLoad</A></B>(<A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html?is-external=true" title="class or interface in java.lang">ClassLoader</A> parent, 299 <A HREF="http://download.oracle.com/javase/6/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io">File</A> dexDir)</CODE> 300 301<BR> 302 Generates a dex file and loads its types into the current process.</TD> 303</TR> 304</TABLE> 305 <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> 306<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 307<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> 308<TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH> 309</TR> 310<TR BGCOLOR="white" CLASS="TableRowColor"> 311<TD><CODE><A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD> 312</TR> 313</TABLE> 314 315<P> 316 317<!-- ========= CONSTRUCTOR DETAIL ======== --> 318 319<A NAME="constructor_detail"><!-- --></A> 320<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 321<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 322<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 323<B>Constructor Detail</B></FONT></TH> 324</TR> 325</TABLE> 326 327<A NAME="DexMaker()"><!-- --></A><H3> 328DexMaker</H3> 329<PRE> 330public <B>DexMaker</B>()</PRE> 331<DL> 332<DD>Creates a new <code>DexMaker</code> instance, which can be used to create a 333 single dex file. 334<P> 335</DL> 336 337<!-- ============ METHOD DETAIL ========== --> 338 339<A NAME="method_detail"><!-- --></A> 340<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 341<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 342<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 343<B>Method Detail</B></FONT></TH> 344</TR> 345</TABLE> 346 347<A NAME="declare(com.google.dexmaker.TypeId, java.lang.String, int, com.google.dexmaker.TypeId, com.google.dexmaker.TypeId...)"><!-- --></A><H3> 348declare</H3> 349<PRE> 350public void <B>declare</B>(<A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A><?> type, 351 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> sourceFile, 352 int flags, 353 <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A><?> supertype, 354 <A HREF="/com/google/dexmaker/TypeId.html" title="class in com.google.dexmaker">TypeId</A><?>... interfaces)</PRE> 355<DL> 356<DD>Declares <code>type</code>. 357<P> 358<DD><DL> 359<DT><B>Parameters:</B><DD><CODE>flags</CODE> - a bitwise combination of <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#PUBLIC" title="class or interface in java.lang.reflect"><CODE>Modifier.PUBLIC</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#FINAL" title="class or interface in java.lang.reflect"><CODE>Modifier.FINAL</CODE></A> and <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#ABSTRACT" title="class or interface in java.lang.reflect"><CODE>Modifier.ABSTRACT</CODE></A>.</DL> 360</DD> 361</DL> 362<HR> 363 364<A NAME="declare(com.google.dexmaker.MethodId, int)"><!-- --></A><H3> 365declare</H3> 366<PRE> 367public <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><?,?> method, 368 int flags)</PRE> 369<DL> 370<DD>Declares a method or constructor. 371<P> 372<DD><DL> 373<DT><B>Parameters:</B><DD><CODE>flags</CODE> - a bitwise combination of <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#PUBLIC" title="class or interface in java.lang.reflect"><CODE>Modifier.PUBLIC</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#PRIVATE" title="class or interface in java.lang.reflect"><CODE>Modifier.PRIVATE</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#PROTECTED" title="class or interface in java.lang.reflect"><CODE>Modifier.PROTECTED</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#STATIC" title="class or interface in java.lang.reflect"><CODE>Modifier.STATIC</CODE></A>, 374 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#FINAL" title="class or interface in java.lang.reflect"><CODE>Modifier.FINAL</CODE></A> and <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#SYNCHRONIZED" title="class or interface in java.lang.reflect"><CODE>Modifier.SYNCHRONIZED</CODE></A>. 375 <p><strong>Warning:</strong> the <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#SYNCHRONIZED" title="class or interface in java.lang.reflect"><CODE>Modifier.SYNCHRONIZED</CODE></A> flag 376 is insufficient to generate a synchronized method. You must also use 377 <A HREF="/com/google/dexmaker/Code.html#monitorEnter(com.google.dexmaker.Local)"><CODE>Code.monitorEnter(com.google.dexmaker.Local<?>)</CODE></A> and <A HREF="/com/google/dexmaker/Code.html#monitorExit(com.google.dexmaker.Local)"><CODE>Code.monitorExit(com.google.dexmaker.Local<?>)</CODE></A> to acquire 378 a monitor.</DL> 379</DD> 380</DL> 381<HR> 382 383<A NAME="declare(com.google.dexmaker.FieldId, int, java.lang.Object)"><!-- --></A><H3> 384declare</H3> 385<PRE> 386public void <B>declare</B>(<A HREF="/com/google/dexmaker/FieldId.html" title="class in com.google.dexmaker">FieldId</A><?,?> fieldId, 387 int flags, 388 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> staticValue)</PRE> 389<DL> 390<DD>Declares a field. 391<P> 392<DD><DL> 393<DT><B>Parameters:</B><DD><CODE>flags</CODE> - a bitwise combination of <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#PUBLIC" title="class or interface in java.lang.reflect"><CODE>Modifier.PUBLIC</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#PRIVATE" title="class or interface in java.lang.reflect"><CODE>Modifier.PRIVATE</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#PROTECTED" title="class or interface in java.lang.reflect"><CODE>Modifier.PROTECTED</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#STATIC" title="class or interface in java.lang.reflect"><CODE>Modifier.STATIC</CODE></A>, 394 <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#FINAL" title="class or interface in java.lang.reflect"><CODE>Modifier.FINAL</CODE></A>, <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#VOLATILE" title="class or interface in java.lang.reflect"><CODE>Modifier.VOLATILE</CODE></A>, and <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Modifier.html?is-external=true#TRANSIENT" title="class or interface in java.lang.reflect"><CODE>Modifier.TRANSIENT</CODE></A>.<DD><CODE>staticValue</CODE> - a constant representing the initial value for the 395 static field, possibly null. This must be null if this field is 396 non-static.</DL> 397</DD> 398</DL> 399<HR> 400 401<A NAME="generate()"><!-- --></A><H3> 402generate</H3> 403<PRE> 404public byte[] <B>generate</B>()</PRE> 405<DL> 406<DD>Generates a dex file and returns its bytes. 407<P> 408<DD><DL> 409</DL> 410</DD> 411</DL> 412<HR> 413 414<A NAME="generateAndLoad(java.lang.ClassLoader, java.io.File)"><!-- --></A><H3> 415generateAndLoad</H3> 416<PRE> 417public <A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html?is-external=true" title="class or interface in java.lang">ClassLoader</A> <B>generateAndLoad</B>(<A HREF="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html?is-external=true" title="class or interface in java.lang">ClassLoader</A> parent, 418 <A HREF="http://download.oracle.com/javase/6/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io">File</A> dexDir) 419 throws <A HREF="http://download.oracle.com/javase/6/docs/api/java/io/IOException.html?is-external=true" title="class or interface in java.io">IOException</A></PRE> 420<DL> 421<DD>Generates a dex file and loads its types into the current process. 422 423 <p>All parameters are optional; you may pass <code>null</code> and suitable 424 defaults will be used. 425 426 <p>If you opt to provide your own <code>dexDir</code>, take care to ensure 427 that it is not world-writable, otherwise a malicious app may be able 428 to inject code into your process. A suitable parameter is: 429 <code>getApplicationContext().getDir("dx", Context.MODE_PRIVATE); </code> 430<P> 431<DD><DL> 432<DT><B>Parameters:</B><DD><CODE>parent</CODE> - the parent ClassLoader to be used when loading 433 our generated types<DD><CODE>dexDir</CODE> - the destination directory where generated and 434 optimized dex files will be written. 435<DT><B>Throws:</B> 436<DD><CODE><A HREF="http://download.oracle.com/javase/6/docs/api/java/io/IOException.html?is-external=true" title="class or interface in java.io">IOException</A></CODE></DL> 437</DD> 438</DL> 439<!-- ========= END OF CLASS DATA ========= --> 440<HR> 441 442 443<!-- ======= START OF BOTTOM NAVBAR ====== --> 444<A NAME="navbar_bottom"><!-- --></A> 445<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> 446<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 447<TR> 448<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 449<A NAME="navbar_bottom_firstrow"><!-- --></A> 450<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 451 <TR ALIGN="center" VALIGN="top"> 452 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="/overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 453 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 454 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 455 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 456 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="/deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 457 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="/index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 458 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="/help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 459 </TR> 460</TABLE> 461</TD> 462<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 463</EM> 464</TD> 465</TR> 466 467<TR> 468<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 469 <A HREF="/com/google/dexmaker/Comparison.html" title="enum in com.google.dexmaker"><B>PREV CLASS</B></A> 470 <A HREF="/com/google/dexmaker/FieldId.html" title="class in com.google.dexmaker"><B>NEXT CLASS</B></A></FONT></TD> 471<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 472 <A HREF="/index.html?com/google/dexmaker/DexMaker.html" target="_top"><B>FRAMES</B></A> 473 <A HREF="DexMaker.html" target="_top"><B>NO FRAMES</B></A> 474 <SCRIPT type="text/javascript"> 475 <!-- 476 if(window==top) { 477 document.writeln('<A HREF="/allclasses-noframe.html"><B>All Classes</B></A>'); 478 } 479 //--> 480</SCRIPT> 481<NOSCRIPT> 482 <A HREF="/allclasses-noframe.html"><B>All Classes</B></A> 483</NOSCRIPT> 484 485 486</FONT></TD> 487</TR> 488<TR> 489<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 490 SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD> 491<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 492DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD> 493</TR> 494</TABLE> 495<A NAME="skip-navbar_bottom"></A> 496<!-- ======== END OF BOTTOM NAVBAR ======= --> 497 498<HR> 499 500</BODY> 501</HTML> 502