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

開発中に何十回, 何百回と端末またはエミュレータで動かしてテストしていると思います.

回数が多い分, 数十秒でも大きく生産性に影響します.

Terminal からの選択しながらのビルドや Gradle コンソールで詳細を確認したりする方法は, まあ, あるっちゃああるけどもいちいちそんなの調べてやるのもなんだかめんどくさかったりして.

「ビルド時間の短縮」というようなキーワードでググればまあそれなりに似たような結果がみつかる.

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

今回, なんとなくいちいちHTMLで結果が出力されるという

「コマンドラインオプションに --profile をつける」

というのをなんとなくやってみたら, Runから実行までの時間が 1分から2秒 になったのでまあ書いてみるが.

Preferences

とするだけ.

「Run」するたびにHTMLで, build/reports/profile/ 以下 にそれぞれにかかった時間をまとめたHTMLファイルが出力される.

AnalyticsApplication_java_-_Android_Studio_2_0_Beta_6

閲覧するには, Run後出力されたHTMLから右クリックでブラウザを起動するといい.

Android_Studio_2_0_Beta_6

こんなかんじで出力された.

Profile_report

Profile_report

50秒のうち45秒が「Crashlystis」の処理に使われている.

デバッグ時には, このような処理は当然必要ない.

しかも謎なのは Fabric は使っているが Crashlytics は使っていないのだが.

この処理を殺す.

-_Android_Studio_2_0_Beta_6

その後結果.

Profile_report

Profile_report

いろいろ謎なことは多いが, オプション「--profile」をつけるだけで一回の「ビルド→実行」時間が数十倍に短縮された.

やみくもにググるよりか, いわゆる「ログ」のような「profile」を見ながらググるほうが効率的.

なぜなら, GUIダイアログから「--profile」と入力しておくだけだもの.


Swift が Android 上で動き始めてよく分かる Kotlin の素晴らしさ

Swift がAndroid上で動き始めており,

_RFC__Port_to_Android_by_modocache_·_Pull_Request__1442_·_apple_swift

[RFC] Port to Android by modocache · Pull Request #1442 · apple/swift

Hacker News でも少し話題になっていたので眺めておりました.

Swift_Ported_to_Android___Hacker_News

Swift Ported to Android | Hacker News

「Swift が Android上で動くこと」について話題がされているかと思いきや Kotlin と比較され, Kotlin のAndroid上で動かすことの良さがはっきりと分かるスレになっておりました.

Surprised noone mentions Kotlin. It's quite Swift-like, backed by JetBrains (Android Studio is based on their IntelliJ Idea), and 1.0 has only just been released. It has full interoperability with Java.

Kotlin に誰も言及していないのが驚き. Kotlin は Swift によくにており, JetBrains (AndroidStidioのベースとなるIntelliJ Idea の開発元)がバックアップしており, 1.0 がリリースされたばかりのもので Java と完全に相互連携ができる.

I love Kotlin, but being able to develop libraries in one language and use them in both Android and iOS is huge. I have been using J2Objc for this until now, and while it's a great tool, it forces me to use Java, which I don't love. I would prefer being able to use Kotlin on iOS, but using Swift for Android development is a great boon.

私はKotlinが好きだが, ひとつの言語でAndroidとiOSで開発ライブラリを利用可能にすることは大変だ. いままで J2Ojc を使っておりこれは素晴らしいツールでJavaを使うことを強いられるが私は好きではない. それより Kotlin を iOS上で利用可能にするほうがいい. Android開発にSwiftを使うのは 非常にありがたいのだが...

Kotlin emits bytecode. It is entirely interoperable with Java. All the Java APIs of the platform are accessible in Kotlin.
Swift on the other end can only target the NDK, which limits it to a very specific niche on Android.

Kotlin はバイトコードを吐く, これは Java と完全に相互連携できること. すべてのJavaAPI はKotlin で利用できる.
一方 Swift は Android上では NDKのみに限定され非常に狭い.

What helps a lot is that the kotlin team has written many helper methods allowing a better flow between the android API and kotlin code : while you don't need it in order to get interop, it allows to more easily write idiomatic kotlin code while interacting with Android.

Kotlin チームの書いたたくさんのヘルパーメソッドは, Android API と Kotlin 間の流れをより良くしており, Swift ユーザがそれを利用しないことと対照的に, Androidと連携しながらより簡単に慣用的な Kotlin コードを書くことができる.

The main problem with Swift on Android is that AFAIK it is going to be limited to NDK.
There is certainly a niche where it can be useful, but for most developers, it makes it a no go.
Kotlin on the other end is indeed a very good stand-in replacement for java on Android.

私の知る限りSwift を Android上で動かすことの大きな問題は NDKに限定されることだ. このことは確実に便利さを狭めておりそれが進行を妨げている. 一方, Kotlin は確かに Android 上での Java の代替となる.

No one cares if you don't use Swift. Go with Kotlin. It's probably a great choice for you. It seems like a great language and I hope it gains traction.

Swift は使わなくて良い. Kotlin でいこう. あなたにとって素晴らしい選択となる. 偉大な言語で勢いを増すことを願っている.

If all you're doing is Android programming Kotlin is probably a better choice at this time. If you're a Java programmer, Kotlin is probably a better choice. If you're already a Swift programmer...
Also, let's see how both languages gain traction in the next 3-5 years.

Androidプログラミングのみを行っていたり, Javaプログラマーであるなら Kotlin はおそらくより良い選択です. もしあなたがすでにSwiftプログラマーであるなら...
次の3-5年でそれぞれがどのように勢いを増すかを見ておきましょう.

しかし,「ことりん」て名前. かわいいよなあ.

あの「Hacker News」で ベストなストーリーを見つける方法


Stackoverflow の短い公式URLでコピペ用ブックマークレットを作る

例えば, この非常に有益なこのページ.

Difference between px, dp, dip and sp on Android? - Stack Overflow

コードの中に参照先として貼り付けていましたが長いのでどうにかならないものかな,と.

long_url

フツーにブラウザのURLバーから取得できるURLはこのような以下のような形式.

Question
http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android

Answer
http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android/2025541#2025541

調べてみると, URLの書式はたくさん存在していて以下のURLは すべて同じ Question「2025282」の Answer「2025541」を参照している.

http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android#answer-2025541

http://stackoverflow.com/questions/2025282/2025541#2025541

http://stackoverflow.com/questions/2025282/#2025541

http://stackoverflow.com/questions/2025541

http://stackoverflow.com/q/2025282/#2025541

http://stackoverflow.com/a/2025282/#2025541

Google ShortURL や TinyUrl などサービスを使わずに, ページ内「share」のリンクから取得できる形式の公式の短縮URLを利用したい.

Difference_between_px__dp__dip_and_sp_on_Android__-_Stack_Overflow

ログインしていない場合は,

Question:
http://stackoverflow.com/q/2025282

Answer:
http://stackoverflow.com/a/2025541

この場合,
「2025282」は, Question投稿のID.
「2025541」は, Answer投稿のID.

ログインしている場合だと,

Question:
http://stackoverflow.com/q/2025282/000000

Answer:
http://stackoverflow.com/a/2025541/000000

この場合,「000000」はログインしているユーザのID.

ということで, ログインしていないときの公式のshareリンククリックからのダイアログに表示するURL形式に合わせてURLバーのURL文字列から公式の短いURLに変換した文字列に「タイトル」を加えたものをすばやくコピーできるブックマークレットを作る.

[Title]
http://stackoverflow.com/q/[question_id]

[Title]
http://stackoverflow.com/a/[answer_id]

Question へのリンクであれば,

http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android

Difference between px, dp, dip and sp on Android?
http://stackoverflow.com/q/2025282

Answer へのリンクであれば,

http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android/2025541#2025541

Difference between px, dp, dip and sp on Android?
http://stackoverflow.com/a/2025541

で,

こんなブックマークレットに.

javascript:
var pathinfo = window.location.pathname.split('/');
window.prompt('', document.title + '\n' + 
  location.protocol + '//'+ location.host +
    (pathinfo[4] ? '/a/' + pathinfo[4] : '/q/' + pathinfo[2]));
void(0);

結果.

Difference_between_px__dp__dip_and_sp_on_Android__-_Stack_Overflow

ここで, コピーして貼る.

short_url

と短く収まるようになりました.

ログイン中でもユーザIDを含めずにタイトルを付けてかんたんにコピペできます.

ちなみに,

http://s.tk/so

http://stackoverflow.com/#

What shortened URLs are available through s.tk? - Meta Stack Exchange

とホスト部分も短縮できたりするらしいがまあいいか.

👉 まとも検索 検索オプション追加 のブックマークレット