Home | History | Annotate | Download | only in platform
      1 page.title=Tnh nng ca Ngn ng Java 8
      2 page.keywords="android N", "Java 8", "Jack"
      3 @jd:body
      4 
      5 <div id="qv-wrapper">
      6   <div id="qv">
      7     <ol>
      8       <li>
      9         <a href="#supported-features">Cc tnh nng v API ca Ngn ng Java 8 c h tr</a>
     10       </li>
     11       <li>
     12         <a href="#configuration">Kch hot cc tnh nng ca Java 8 v Jack Toolchain</a>
     13       </li>
     14     </ol>
     15   </div>
     16 </div>
     17 
     18 <p>Android N cung cp h tr cho cc tnh nng ca ngn ng Java 8
     19    m bn c th s dng khi pht trin cc ng dng nhm mc tiu Android N.
     20   Trang ny m t cc tnh nng ngn ng mi c h tr trong Bn xem trc
     21   Android N, cch thit lp d n ng  s dng chng v cc vn 
     22    bit m bn c th gp phi.
     23 </p>
     24 
     25 <p> bt u s dng cc tnh nng ny, bn cn ti xung v ci t Android
     26 Studio 2.1 (bn xem trc) v SDK ca Bn xem trc Android N gm c Jack toolchain
     27 cn thit v B tr Android c cp nht cho Gradle. Nu bn cha
     28 ci t SDK Bn xem trc Android N, hy xem <a href="{@docRoot}preview/setup-sdk.html">Thit lp  Pht trin dnh cho Android N</a>.</p>
     29 
     30 
     31 
     32 <p class="note">
     33   <strong>Lu :</strong> S dng cc tnh nng mi ca ngn ng Java 8 khng phi l mt
     34   yu cu  pht trin cc ng dng nhm mc tiu nn tng Android N. Nu bn
     35    khng mun vit m vi cc tnh nng ca ngn ng Java 8 th bn c t cc gi tr
     36   m ngun v tng thch mc tiu thnh Java 7. Tuy nhin, bn vn
     37   phi bin dch vi JDK 8  dng cho nn tng Android N.
     38 </p>
     39 
     40 <h2 id="supported-features">
     41   Cc tnh nng v API ca Ngn ng Java 8 c h tr
     42 </h2>
     43 
     44 <p>
     45   Hin thi, Android khng h tr tt c cc tnh nng ca ngn ng Java 8. Tuy nhin,
     46   cc tnh nng sau s s dng c khi pht trin ng dng nhm mc tiu
     47   Bn xem trc Android N:
     48 </p>
     49 
     50 <ul>
     51   <li>
     52     <a class="external-link" href="https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html">Cc
     53    phng thc giao din mc nh v tnh</a>
     54   </li>
     55 
     56   <li>
     57     <a class="external-link" href="https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html">
     58     Biu thc Lambda</a>
     59   </li>
     60 
     61   <li>
     62     <a class="external-link" href="https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html">Ch gii
     63     lp li</a>
     64   </li>
     65 </ul>
     66 
     67 
     68 <p>
     69   Ngoi ra, cc API tnh nng ca ngn ng Java 8 cng c h tr:
     70 </p>
     71 
     72 <ul>
     73   <li>Cc API phn chiu v lin quan n ngn ng:
     74   </li>
     75 
     76   <li style="list-style: none; display: inline">
     77     <ul>
     78       <li>{@code java.lang.FunctionalInterface}
     79       </li>
     80 
     81       <li>{@code java.lang.annotation.Repeatable}
     82       </li>
     83 
     84       <li>{@code java.lang.reflect.Method.isDefault()}
     85       </li>
     86 
     87       <li>v cc API Phn chiu lin quan ti cc ch gii lp li, nh
     88 {@code AnnotatedElement.getAnnotationsByType(Class)}
     89       </li>
     90     </ul>
     91   </li>
     92   <li>Cc API tin ch:
     93   </li>
     94 
     95   <li style="list-style: none; display: inline">
     96     <ul>
     97       <li>{@code java.util.function}
     98       </li>
     99     </ul>
    100   </li>
    101 </ul>
    102 
    103 <p class="note">
    104   <strong>Lu :</strong> Android N k tha vic trin khai cc
    105    biu thc lambda trn cc lp n danh. Phng php ny cho php chng
    106   tng thch ngc v c th chy trn cc phin bn Android c hn.  kim th
    107   cc biu thc lambda trn cc phin bn c hn, hy nh vo tp {@code
    108   build.gradle} v t {@code compileSdkVersion} v {@code
    109   targetSdkVersion} thnh 23 hoc thp hn.
    110 </p>
    111 
    112 <h2 id="configuration">
    113   Kch hot cc tnh nng ca Java 8 v Jack Toolchain
    114 </h2>
    115 
    116 <p>
    117    s dng cc tnh nng mi ca ngn ng Java 8 bn cng cn s dng
    118   <a class="external-link" href="https://source.android.com/source/jack.html">Jack toolchain</a> mi. Toolchain Android
    119   mi s bin dch m ngun ca ngn ng Java sang m bytecode
    120    dex c c ca Android, c nh dng th vin {@code .jack}  ring ca n v cung cp hu ht cc tnh nng
    121    toolchain di dng mt phn ca cng c ring l: ng gi li, thu gn, lm ri m v
    122   multidex.
    123 </p>
    124 
    125 <p>Sau y l phn so snh hai toolchain c s dng  dng cc tp DEX Android:</p>
    126 <ul>
    127   <li>Javac toolchain c:<br>
    128   <b>javac</b> ({@code .java} --&gt; {@code .class}) --&gt; <b>dx</b> ({@code
    129   .class} --&gt; {@code .dex})
    130   </li>
    131 
    132   <li>Jack toolchain mi:<br>
    133   <b>Jack</b> ({@code .java} --&gt; {@code .jack} --&gt; {@code .dex})
    134   </li>
    135 </ul>
    136 
    137 <h3>
    138   Cu hnh Gradle
    139 </h3>
    140 
    141 <p>
    142    kch hot cc tnh nng ngn ng Java 8 v Jack cho d n ca bn, hy nhp
    143    ni dung sau vo tp {@code build.gradle} theo m-un:
    144 </p>
    145 
    146 <pre>
    147 android {
    148   ...
    149   defaultConfig {
    150     ...
    151     jackOptions {
    152       enabled true
    153     }
    154   }
    155   compileOptions {
    156     sourceCompatibility JavaVersion.VERSION_1_8
    157     targetCompatibility JavaVersion.VERSION_1_8
    158   }
    159 }
    160 </pre>
    161 
    162 <h3>
    163   Vn   bit
    164 </h3>
    165 
    166 <p>
    167   Instant Run, c gii thiu trong Android Studio 2.0 (Beta), hin khng hot ng
    168   vi Jack v s b v hiu ha khi s dng toolchain mi.
    169 </p>
    170 
    171 <p>Bi v Jack khng to ra cc tp lp trung gian khi bin dch mt
    172 ng dng, cc cng c ph thuc vo nhng tp ny hin thi khng hot ng vi Jack. Mt s
    173 v d v cc cng c ny l:</p>
    174 
    175 <ul>
    176   <li>B d Lint hot ng trn cc tp lp
    177   </li>
    178 
    179   <li>Cc cng c v th vin i hi cc tp lp ca ng dng (nh JaCoCo
    180   v Mockito)</li>
    181 </ul>
    182 
    183 <p><a href="http://tools.android.com/filing-bugs">Vui lng thng bo li</a> nu bn pht hin cc vn  khc khi s dng Jack.</p>