Android Studio の セキュリティアラート が発令中!!

今, メール受信したけど.

alert

Dear Android Studio Developer,

As an app developer on Google Play, we wanted to make you aware of an important security update for Android Studio.

On May 11th, we released the Android Studio 2.1.1 update. This incremental update addresses a security vulnerability in the underlying IntelliJ platform that affects all previous versions of Android Studio. The vulnerability concerns the IDE itself and has no effect on individual apps.

Please update to Android Studio 2.1.1 as soon as possible. More information about the vulnerability can be found in this G+ posting. JetBrains has also released more details on the vulnerability.

To address this security vulnerability, simply go into Android Studio and check updates. For OS X users, navigate to the Android Studio Menu and click Check for Updates. For Windows or Linux users, navigate to the Help menu and click Check for Updates. You should be running at least Android Studio 2.1.1. The update message was sent as a in-product notification to all users of Android Studio. If you want a new install, you can download v2.1.1 from the Android Studio website.

If you’re still using v1.5.x and not able to switch to v2.x immediately, please download Android Studio v1.5.2 from the Android Studio tools website.

Regards,

The Android Studio Team

正直, このメールさえもなんだかクリックするのが怖い...

以下, HTMLメールに掲載されているリンク先一覧.

Download Android Studio and SDK Tools | Android Developers

Please update to Android Studio v2.1.1 We wanted to make you aware of an imp...

Security update for IntelliJ-based IDEs v2016.1 and older versions | Company Blog

Android Studio 1.5.2 - Android Studio Project Site

どのリンクもクリックするとまともなサイトが表示されるのですが, どのリンクもリダイレクトされているのが, なんとなくきもい.

curl

バージョン 2.1.1 にしておけばいいということですかね.

いまやメールもすぐには信じられなくなってるのは私だけでしょうか.

きもくないすか?


【Android Studio】idea.vmoptions の設定

少し遅すぎないかと思い, ビルド時間を短縮しようとな.

~/Library/Preferences/AndroidStudio2.1/idea.vmoptions

デフォルトで以下でした.


-Xms128m      
-Xmx750m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=96m
-XX:+UseCompressedOopseservedCodeCacheSize=96m
-XX:+UseCompressedOops

他人の設定を見てみる.


-Xms128m
-Xmx1024m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=64m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
-Dfile.encoding=UTF-8
-Dgroovy.source.encoding=UTF-8

Tips: Android StudioのIDEのメモリ割り当てを増やす(Xmxはどこやねん) - sos の 作業メモ


-Xms512m
-Xmx1024m
-XX:MaxPermSize=512m
-XX:ReservedCodeCacheSize=128m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
-Dgroovy.source.encoding=UTF-8
-Dfile.encoding=UTF-8

[Android Studio] 起動時のメモリ割り当てサイズを変更する / コンパイラのエンコーディングを変更する | Developers.IO


-Xms2048m
-Xmx8192m
-XX:MaxPermSize=2048m
-XX:ReservedCodeCacheSize=1024m

PSA: Apparently assigning a ton of memory to gradle makes it noticeably faster.. : androiddev


-server
-Xms2g
-Xmx2g
-XX:NewRatio=3
-Xss16m
-XX:+UseConcMarkSweepGC
-XX:+CMSParallelRemarkEnabled
-XX:ConcGCThreads=4
-XX:ReservedCodeCacheSize=240m
-XX:+AlwaysPreTouch
-XX:+TieredCompilation
-XX:+UseCompressedOops
-XX:SoftRefLRUPolicyMSPerMB=50
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Djsse.enableSNIExtension=false
-ea

One and the only one reason to customize IntelliJ IDEA memory settings - Tomasz Dziurko


-server
-Xms2048m
-Xmx2048m
-XX:NewSize=512m
-XX:MaxNewSize=512m
-XX:PermSize=512m
-XX:MaxPermSize=512m
-XX:+UseParNewGC
-XX:ParallelGCThreads=4
-XX:MaxTenuringThreshold=1
-XX:SurvivorRatio=8
-XX:+UseCodeCacheFlushing
-XX:+UseConcMarkSweepGC
-XX:+AggressiveOpts
-XX:+CMSClassUnloadingEnabled
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:+CMSParallelRemarkEnabled
-XX:CMSInitiatingOccupancyFraction=65
-XX:+CMSScavengeBeforeRemark
-XX:+UseCMSInitiatingOccupancyOnly
-XX:ReservedCodeCacheSize=64m
-XX:-TraceClassUnloading
-ea
-Dsun.io.useCanonCaches=false

Prashanth's Blog: Performance Tuning of IntelliJ IDEA startup options

こんなグラフあったけども, そんなにデフォルトではとろいのか?

One_and_the_only_one_reason_to_customize_IntelliJ_IDEA_memory_settings_-_Tomasz_Dziurko

きっと多くの環境で稼働できるようにやわらかめの設定なのでしょうね, デフォルトって.

Configuring JVM options and platform properties – JetBrains Support

Android Studio の ビルド がやけにトロい


ButterKnife 8.0 に更新で @Bind → @BindView など

更新されています.

Butter_Knife

Version 8.0.0 (2016-04-25)

- @Bind becomes @BindView and @BindViews (one view and multiple views, respectively).
- Calls to bind now return an Unbinder instance which can be used to null references. - This replaces the unbind API and adds support for being able to clear listeners.
- New: @BindArray binds String, CharSequence, and int arrays and TypeArray to fields.
- New: @BindBitmap binds Bitmap instances from resources to fields.
- @BindDrawable now supports a tint field which accepts a theme attribute.

-The runtime and compiler are now split into two artifacts.

compile 'com.jakewharton:butterknife:8.0.0'
apt 'com.jakewharton:butterknife-compiler:8.0.0'

- New: apply overloads which accept a single view and arrays of views.
- ProGuard rules now ship inside of the library and are included automatically.
- @Optional annotation is back to mark methods as being optional.

butterknife/CHANGELOG.md at master · JakeWharton/butterknife

明示することで, バインドできるリソース範囲を広げながら処理速度は落とさない.

あと, proguard 記述は不要なのだとさ.

Butter Knife


苦労した経験から学んだ Androidアプリを作る際の30のこと

Building Android Apps — 30 things that experience made me learn the hard way — Medium

読んでみましたが, 納得できることばかりです.

一読の価値はあると思います.

実際は, 35個ありました.

1. サード・パーティのライブラリを追加する前に2度考えよう. それは本当に重要な決意なのです.

2. ユーザーがそれを見ることができないならば, 描画してはならない.

見えないところは塗りつぶすな – 不要なオーバードロー削除で高速化

3. 本当に必要でなければデータベースは使うな.

4. メソッド数 65000個はすぐに到達するが MultiDex が助けてくれる.

[DEX] Sky’s the limit? No, 65K methods is — Medium

5. AsyncTask のベストな代替は RxJava でこれのほうがかなりよい.

Party tricks with RxJava, RxAndroid & Retrolambda — The Startup — Medium

6. Retrofit がベストなネットワークライブラリである.

Retrofit

7. Retrolambda でコードを短縮しよう.

Retrolambda on Android — Android & Tech — Medium

8. RxJava と Retrofit と Retrolambda を一緒につかうと最強.

Party tricks with RxJava, RxAndroid & Retrolambda — The Startup — Medium

9. EventBus は素晴らしいが, コードが乱雑になるので多用するのは控えている.

greenrobot/EventBus: Android optimized event bus that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

10. レイヤーでなく機能によって構成する.

ソースディレクトリの構成時にもっておくべき「会社別」のイメージ

11. アプリケーションスレッドのすべてをOFFにしろ.

12. レイアウトとそのヒエラルヒーを最適化するために lint するべし. 削除できる不要なレイアウトを特定できる.

layoutopt | Android Developers

13. Gradle を使っているなら, いろんな方法でスピードアップしよう.

Android お手軽なビルド時間の短縮メモ

14. ビルド時には プロファイルレポートを使え, それぞれのビルドにかかった時間が分かる.

オプションに「–profile」をつけて Run時間が1分から2秒になった話

15. 有名なアーキテクチャーを使え.

Architecting Android…The evolution – Fernando Cejas

16. テストは時間がかかるが, 一度コツを掴むとテストしないときより高速で堅牢となる.

Is Unit Testing worth the effort? - Stack Overflow

17. Dependency Injection を使え. よりモジュール化されテストしやすくなる.

Tasting Dagger 2 on Android – Fernando Cejas

18. Fragmented の podcast を聞け. きっとあなたにとって素晴らしいものとなる.

Fragmented_–_An_Android_Developer_Podcast

Fragmented – An Android Developer Podcast

19. 個人的メールアドレスは Android Market の公開アカウントに使うな.

Google Play - Only one strike is needed to ruin you : Android

20. 常に適切な入力タイプを使え.

Specifying the Input Method Type | Android Developers

21. (Google) Analytics を使って利用パターンを見つけバグを隔離すべし.

22. 新しいライブラリの人気のあるやつを使え. (dryrun を使って出力をより速く)

【AndroidStudio 不要】サンプルアプリは「dryrun」で試してすぐ捨てよう

cesarferreira/dryrun: Try the demo project of any Android Library

23. Service はできるだけ素早く処理して終了しろ.

24. ユーザ名やメールアドレスのサジェストにアカウントマネージャーを使え.

AccountManager | Android Developers

25. ビルドやベータ版の配布や apk の作成にはCIを使え.

26. 自分の CIサーバは使うな. サーバーのメンテに時間を使う. ディスク容量・セキュリテイの問題・SSL攻撃防御のサーバの更新なども. Circle CI や travis, shippabele を使え. これらは 安価で手間も少ない.

27. PlayStore へのデプロイは自動化しよう.

Triple-T/gradle-play-publisher: Gradle Plugin to upload your APK and metadata to the Google Play Store

28. ライブラリが巨大でその一部しか使ってない場合は, より小さくなる方法を探せ(例えば プロガードを利用する)

Shrink Your Code and Resources | Android Developers

29. 実際に必要以上なモジュールを使うな. もしそのモジュールを頻繁に更新していないのなら, コードからそれらをコンパイルする時間や, 以前のそれぞれのモジュールのビルドが最新版であるかチェックも必要となることについて考えることが重要です. バイナリ .jar/.aar の簡単な読込みにすると4倍くらい向上できます.

30. PNGを捨ててSVG化することを考え始めよう.

Vector Asset Studio | Android Developers

31. ライブラリの抽象化クラスを作れ. ライブラリを変更するときに一箇所の変更で簡単に行うことができる.

JakeWharton/timber: A logger with a small, extensible API which provides utility on top of Android's normal Log class.

32. Connectivity とその種類を監視しろ. (WiFi のときにより多くのデータを更新しているか?)

33. 電源とバッテリーを監視しろ. (充電中に更新データを多くしているか, バッテリーが少ないときには更新を停止しているか?)

34. UIとはジョークのようなものだ. 説明が必要であればそれは良くない.

35. テストのパフォーマンスは偉大です. テストで何も壊れないか確認し、その後ゆっくりと正しい実装を記述する → 最適化

Dan LewさんはTwitterを使っています: "Tests are great for performance: Write slow (but correct) implementation then verify optimizations don't break anything with tests."

しかし, Medium ていい記事ばかりあるけどなぜなのかな.


ゲージ付の折れ線グラフをすばやくつくれるライブラリ「Spark」

折れ線グラフをすばやくつくりましょう.

Introducing_Spark_—_Robinhood_Engineering_—_Medium

Introducing Spark — Robinhood Engineering — Medium

手順

1. ライブラリを追加する.


compile ‘com.robinhood.spark:spark:{latest release}’

2. View を設置する.


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.robinhood.spark.SparkView
        android:id="@+id/sparkview"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        app:spark_lineColor="@color/colorAccent"
        app:spark_scrubEnabled="true"
        app:spark_animateChanges="true"/>
...

3. データ float[] を渡す Adapter を作る.


public class MyAdapter extends SparkAdapter {
    private float[] yData;

    public MyAdapter(float[] yData) {
      this.yData = yData;
    }

    @Override
    public int getCount() {
      return yData.length;
    }

    @Override
    public Object getItem(int index) {
      return yData[index];
    }

    @Override
    public float getY(int index) {
      return yData[index];
    }
}

4. Adapter を View にセットして, ゲージをタッチしたときの Listener をつける.


SparkView sparkView = (SparkView) findViewById(R.id.sparkview);
sparkView.setAdapter(new MyAdapter(data));
sparkView.setScrubListener(new SparkView.OnScrubListener() {
    @Override
    public void onScrubbed(Object value) {
        if (value == null) {
            scrubInfoTextView.setText(R.string.scrub_empty);
        } else {
            scrubInfoTextView.setText(getString(R.string.scrub_format, value));
        }
    }
});

5. 出来上がり

20160419-072257_1

数値の推移を確認するには折れ線グラフは非常にわかりやすく, タップしてその時点の数値も簡単に表示できてしまうこのライブラリは非常に重宝するものだと思われます.

robinhoodmarkets/spark: A simple Android sparkline chart view.