LoginSignup
71

More than 5 years have passed since last update.

Android Gradle Plugin 0.13 → 0.14の変更点

Last updated at Posted at 2014-11-01

2014/10/31にAndroid Gradle Plugin 0.14.0がリリースされていましたので、変更点を確認してみました。
http://tools.android.com/tech-docs/new-build-system

(ただ訳しただけのものもありますが)

※(2014/11/4追記) 早速、0.14.1がリリースされています。(詳細未確認)

0.14.0の変更点

Android Studio 0.9が必要

そのままですが、現在β版として下記ページからダウンロードできるのは、
つい先日までCanary Channelでリリースされていた0.8.14です。
https://developer.android.com/sdk/installing/studio.html

Android Studio 0.9はCanary Channelでリリースされています。
http://tools.android.com/download/studio/canary/latest

ProGuardとコードカバレッジ計測が連携可能

ProGuardを有効にしていてもカバレッジ計測できるようです。
おそらく以下の問題だと思われます。
https://code.google.com/p/android/issues/detail?id=76609

Android 5.0の端末からでもカバレッジデータをpull可能

これはAndroid L Previewを使っていて困っていたことですが
カバレッジ計測を有効にした場合テストが失敗する問題がありました。
今回のアップデートでカバレッジデータを取れるようになったようです。

自作のライブラリのテストで試したところ、確かにpullは成功し下記のようなエラーは出なくなりました。

Error during Sync: Remote object doesn't exist!
null
java.io.IOException: Failed to pull /data/data/com.simplealertdialog.test/coverage.ec from device

…ですが、肝心のカバレッジが全くとれなくなっていました。
(テストは実行できているのにカバレッジ0%。coverage.ecファイルが空でした)

テストカバレッジを計測しているプロジェクトでは、このバージョンを適用する前に
正しく計測できているか確認した方が良さそうです。

※類似の問題が見当たらなかったので、バグレポートしました。
https://code.google.com/p/android/issues/detail?id=78556

※(2014/11/4追記) 0.14.1がリリースされ、この問題は修正されたようです。

環境変数ANDROID_SERIALで端末を制限

環境変数ANDROID_SERIALが定義されている場合は、そのシリアルナンバーの機種にインストール、テスト実行を制限することができるようです。

実際、以下のように実行してみると指定の端末のみでテストが実行されました。

$ ANDROID_SERIAL=xxxxxxx ./gradlew connectedCheck

MultiDexサポート

メソッド数が65Kを超えるとビルドが失敗する問題へのサポートです。

  • multiDexEnabled = trueでサポートされる
  • 有効にするにはBuild-Tools 21.1.0とSupport Repository rev8が必要
  • defaultConfig, ProductFlavor, BuildTypeに記述可能
  • minSdkVersion 21+はネイティブでサポートされ、21未満はcom.android.support:multidex:1.0.0のdependencyが自動的に追加される

こちらに詳しく説明がありました。
Building Apps with Over 65K Methods

未使用のリソースを自動的に削除

未使用のリソースを削除する機能が追加されたようです。
(デフォルトではOFF)

以下のようにすれば有効になります。

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
    }
}

試しに、あるアプリで試してみると以下のように出力されました。
もちろん内容によるのでしょうが、以下の場合では20%ほど小さくなりました。

:app:shrinkProdReleaseResources
Removed unused resources: Binary resource data reduced from 1426KB to 1141KB: Removed 19%
Note: If necessary, you can disable resource shrinking by adding
android {
    buildTypes {
        release {
            shrinkResources false
        }
    }
}

DSL/APIの変更

プロパティのリネーム

  • BuildType.runProguard -> minifyEnabled
  • BuildType.zipAlign -> zipAlignEnabled
  • BuildType.jniDebugBuild -> jniDebuggable
  • BuildType.renderscriptDebug -> renderscriptDebuggable
  • ProductFlavor.renderscriptSupportMode -> renderscriptSupportModeEnabled
  • ProductFlavor.renderscriptNdkMode -> renderscriptNdkModeEnabled

variant/variantFilter APIで取得できるBuildType/ProductFlavor/SigningConfigは読取専用に

  • これらのオブジェクトはグローバルだったため、変更すると他のVariantに副作用が生じる
  • Merged flavorはVariantごとの値であり変更可能

Variant/VariantOutput APIの変更

DensityやABIを以下のAPIで取得できるようです。

  • output.getFilter(com.android.build.OutputFile.DENSITY)
  • output.getFilter(com.android.build.OutputFile.ABI)

以上

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
71