android-apt が不要となった ButterKnife

Butter Knife - Android library statistics - AppBrain

バージョンを上げてみると落ちるのでなぜかな, と.

これまでAndroid開発でannotation processingを実行したい場合はhvisser/android-aptを利用するのが王道となっていましたが、Android Gradle plugin version 2.2から公式にサポートが開始されました。

android-apt becomes obsolete - Qiita

2016-10-04
From apt to annotationProcessor
As of the Android Gradle plugin version 2.2, all functionality that was previously provided by android-apt is now available in the Android plugin. This means that android-apt is officially obsolete 😉

hvisser / android-apt / wiki / Migration — Bitbucket

Reflection を利用していた ButterKnife も予定通りに,

実行時に全力でReflectionするButter Knifeと違い・・・(c.f. Butter KnifeもAnnotation Processingする方式に切り替えるっぽい? => Split the compiler and runtime into separate artifacts. by serj-lotutovici · Pull Request #323 · JakeWharton/butterknife).

Butter Knife、今までありがとう。 Data Binding、これからよろしく。 - Qiita

JakeWharton on Aug 1, 2015
This dependency can probably be removed

Split the compiler and runtime into separate artifacts. by serj-lotutovici · Pull Request #323 · JakeWharton/butterknife

ButterKnife 8.4.0 で, Gradle Plugin の annotation processor を利用するようになり, android-apt を利用が不要になっていました.


-Note: If you are using the new Jack compiler with version 2.2.0 or newer you do not need the
-'android-apt' plugin and can instead replace `apt` with `annotationProcessor` when declaring the
-compiler dependency.

Just use 'annotationProcessor' for instructions. · JakeWharton/butterknife@716e1f3

この android-apt 利用時の記述が無駄にあると, フィールドにバインドされずにリスナーセットなど操作時に「んおっ?」となります.

まとめ

Gradle Android plugin 2.2.+ で ButterKnife 8.4.+ の場合 android-apt は不要.

以下2行のみ. proguardの記述不要.


dependencies {
  compile 'com.jakewharton:butterknife:8.4.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

Butter Knife

Annotation Processor のこれまで流れを知っておけばハマることもなかったのだろうと思います.

ButterKnife GitHubリポジトリ の issue などから調べようとすると, 謎の漢字での書き込みが激しく逆に混乱してしまいました.

Issues · JakeWharton/butterknife

com.android.support.* の dependencies のバージョンが揃わない件


新しくなった Android Asset Studio でマテリアルアイコンを自在に加工するべし

作者の Roman Nurik さんがつぶやいています.

使ってみましょう.

Android Asset Studio

Google から公開されているマテリアルデザインのアイコンを元に色やサイズやエフェクトをお好みにブラウザ上で設定してダウンロードできます.

編集後は, resディレクトリ以下解像度別のディレクトリの構造に合わせて作成されたzipアーカイブをダウンロードできます.


$ zipinfo -1 ic_launcher.zip
res/mipmap-xxxhdpi/ic_launcher.png
web_hi_res_512.png
res/mipmap-xxhdpi/ic_launcher.png
res/mipmap-xhdpi/ic_launcher.png
res/mipmap-hdpi/ic_launcher.png
res/mipmap-mdpi/ic_launcher.png


$ zipinfo -v ic_launcher.zip
Archive:  ic_launcher.zip
There is no zipfile comment.

End-of-central-directory record:
-------------------------------

  Zip archive file size:                    129862 (000000000001FB46h)
  Actual end-cent-dir record offset:        129840 (000000000001FB30h)
  Expected end-cent-dir record offset:      129840 (000000000001FB30h)
  (based on the length of the central directory and its expected offset)

  This zipfile constitutes the sole disk of a single-part archive; its
  central directory contains 6 entries.
  The central directory is 455 (00000000000001C7h) bytes long,
  and its (expected) offset in bytes from the beginning of the zipfile
  is 129385 (000000000001F969h).


Central directory entry #1:
---------------------------

  res/mipmap-xxxhdpi/ic_launcher.png

  offset of local header from start of archive:   0
                                                  (0000000000000000h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         5e505e31
  compressed size:                                20038 bytes
  uncompressed size:                              20028 bytes
  length of filename:                             34 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #2:
---------------------------

  There are an extra 16 bytes preceding this file.

  web_hi_res_512.png

  offset of local header from start of archive:   20118
                                                  (0000000000004E96h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         bb74dba5
  compressed size:                                74680 bytes
  uncompressed size:                              75392 bytes
  length of filename:                             18 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #3:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-xxhdpi/ic_launcher.png

  offset of local header from start of archive:   94862
                                                  (000000000001728Eh) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         ca100bd5
  compressed size:                                15772 bytes
  uncompressed size:                              15790 bytes
  length of filename:                             33 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #4:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-xhdpi/ic_launcher.png

  offset of local header from start of archive:   110713
                                                  (000000000001B079h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         6551b330
  compressed size:                                8409 bytes
  uncompressed size:                              8404 bytes
  length of filename:                             32 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #5:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-hdpi/ic_launcher.png

  offset of local header from start of archive:   119200
                                                  (000000000001D1A0h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         44371c4a
  compressed size:                                6539 bytes
  uncompressed size:                              6534 bytes
  length of filename:                             31 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #6:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-mdpi/ic_launcher.png

  offset of local header from start of archive:   125816
                                                  (000000000001EB78h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         4fce9139
  compressed size:                                3492 bytes
  uncompressed size:                              3487 bytes
  length of filename:                             31 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

かんたんなアイコンであれば簡単に素早く作成できます.

Windows版デスクトップアプリ(.exe形式)もある模様.

romannurik/AndroidAssetStudio: A set of web-based tools for generating graphics and other assets that would eventually be in an Android application's res/ directory.


LINEbot でオウム返し 2017 PHP版

やり方調べるのになぜか時間がかかる.

なんだかつらたん.

ただ, オウム返ししたいだけなのに!

しくみ

LINEサーバを介して自分のサーバ内のスクリプトで受け取ります.

スクリプト作成の前に LINE管理画面で,

- アクセストークンをもらう
- サーバー内スクリプトまでのURLを教えておく

スクリプト

LINE側 API はわかりやすい仕様で作られています.


<?php

$access_token = /* your access token */;

$url = 'https://api.line.me/v2/bot/message/reply';

// receive json data from line webhook
$raw = file_get_contents('php://input');
$receive = json_decode($raw, true);

// parse received events
$event = $receive['events'][0];
$reply_token  = $event['replyToken'];
$message_text = $event['message']['text'];


// build request headers
$headers = array('Content-Type: application/json',
                 'Authorization: Bearer ' . $access_token);

// build request body
$message = array('type' => 'text',
                 'text' => $message_text);

$body = json_encode(array('replyToken' => $reply_token,
                          'messages'   => array($message)));


// post json with curl
$options = array(CURLOPT_URL            => $url,
                 CURLOPT_CUSTOMREQUEST  => 'POST',
                 CURLOPT_RETURNTRANSFER => true,
                 CURLOPT_HTTPHEADER     => $headers,
                 CURLOPT_POSTFIELDS     => $body);

$curl = curl_init();
curl_setopt_array($curl, $options);
curl_exec($curl);
curl_close($curl);

結果

どんだけつらたんなのか!