react-native run-* で error during initialization or failure to call AppRegistry.registerComponent の対策

エラーログ

APP_NAME has not been registered.
This is either due to a required() error during initialization or failure to call AppRegistry.registerComponent

対策

node プロセスが干渉しているので kill する.

$ ps aux | grep node
$ sudo kill -9 PROCESS_ID

参考

https://github.com/jhabdas/react-native-webpack-starter-kit/issues/30#issuecomment-180838137

react プロセスのパターンもあるみたい.

react−nativeの最初につまずいたところメモφ(。_。 ) - Qiita

input type="file" accept で .m4a 形式のファイルをデフォルトの選択対象にする場合は audio/x-m4a を使う

タイトルが本文.

実現したかったこと

<input type="file">

でデフォルトでは .m4a 形式のファイルだけを選択対象にする.

.m4a とは

非圧縮ファイル(WAVやAIFF)を音質の劣化なく70%から50%程圧縮する。通常はQuickTimeのMOVファイル(.mov)かMP4ファイル(.m4a)に格納される。

ロスレスで50%サイズダウンすごい.

試したこと

素直に <input type="file" accept="audio/m4a">

-> 全てのファイル形式が対象になる: ☓

あ, m4a は mp4 ベースの拡張だから <input type="file" accept="audio/mp4">

-> .mp4 が対象になる: ☓

-もう <input type="file" accept="audio/*"> で妥協しよう

-> ☓

結論

<input type="file" accept="audio/x-m4a">

なぞは残る

Media Types

developer.mozilla.org

あたりを探しても関する情報はなく...

help.dottoro.com

に audio/m4a の Aliases として audio/x-m4a があったので試してみたらいけた.

現行の Chrome 63 と Safari 11.0.2 では実現できた.

Web 標準ではないけど各ブラウザが実装している..?

優先度は高くないので, 時間あるときにでも調べていきたい.

React Native で実行対象の Android デバイスを選択してビルドする

blog.morugu.com

↑を乗り越えた後に, emulator を起動しつつリアルデバイスも繋いだ状態で

react-native run-android したところ emulator が優先された.

なので明示的に実行対象を指定する方法.

実行可能な一覧を取得

adb devices で使用可能な( adb サーバに接続された ) emulator/device が表示される.

$ adb devices
List of devices attached
adb server version (39) doesn't match this client (36); killing...
adb E 54586 8413562 usb_osx.cpp:147] Unable to create an interface plug-in (e00002be)
* daemon started successfully *

emulator-xxxx   device
xxxxxyyyyy      device

emulator-xxxx はその名の通りなので, 実機ビルドしたい場合は xxxxxyyyyy の方をコピーしておく.

実行

react-native run-android --deviceId xxxxxyyyyy

--deviceId で対象を指定. 以上!

参考

https://facebook.github.io/react-native/docs/running-on-device.html

http://android.keicode.com/devenv/what-is-adb.php

Redis でワイルドカードを使った複数 key の一括削除

Redis で key_name_* で一致する key を削除したいときに

key に使用している文字列によって最適な方法が違うのでまとめておく.

だいたいは redis-cli コマンドで ok

redis-cli KEYS "key_name_*" | xargs redis-cli DEL

基本的にはこれを使えば問題ない.

クォートを使った文字列の場合

key にクォートが含まれていると xargs が文字列を処理できずエラーになる.

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

Linux 環境

redis-cli KEYS "key_name_*" | xargs -d '\n' redis-cli DEL
-d オプション について

every character in the input is taken literally.

文字列がそのまま解釈されるようになる.

xargs(1) - Linux manual page

macOS 環境

redis-cli KEYS "key_name_*" | xargs -0 redis-cli DEL

macOS の xargs には -d オプションがない.

xargs(1) Mac OS X Manual Page

その他

Lua

Redis 2.6 以降では EVAL コマンドで Lua Scripting で操作することができ, それを使った方法.

redis-cli EVAL "return redis.call(\'DEL\', unpack(redis.call(\'KEYS\', ARGV[1])))" 0 "key_name_*";

ただし, 1024件以上のデータ量になる場合 too many results to unpack エラーが発生する.

Lua の Default Stack Size が 1024 で定義されているため.

Lua 4.0.1 source code - llimits.h

対策( Feature request, zrevrangebyscore with STORE option · Issue #678 · antirez/redis · GitHub )はあるけど

素直に xargs 使ったほうが良さそう.

参考

Delete redis keys with unmatched single quotes · GitHub

React Native で run-adnroid したときに発生しがちな3つのエラーと対策

背景

久しぶりに react-native run-android したらエラーが出て

以前にも同じようなエラーに遭遇した記憶があるので, 内容と対策をまとめておく.

環境

  • macOS: 10.13.2
  • react-native-cli: 2.0.1
  • react-native: 0.42.3
  • node: v8.9.1

エラー その1: SDK location not found.

ログ
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
対策

app/android/local.properties に以下を追加. (なければ作成)

sdk.dir = /Users/{USER_NAME}/Library/Android/sdk

※Mac で ~/ はホームディレクトリとして認識されないので, 必ずフルパスで設定する.

参考

stackoverflow.com

エラー その2: The SDK Build Tools revision (23.0.1) is too low for project

ログ
The SDK Build Tools revision (23.0.1) is too low for project ':{PROJECT_NAME}'. Minimum required is 25.0.0
対策

app/android/build.gradle

'com.android.tools.build:gradle:2.3.0'

'com.android.tools.build:gradle:2.2.3' に変更.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        // classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}
参考

github.com

エラー その3: No connected devices!

ログ
com.android.builder.testing.api.DeviceException: No connected devices!
対策

Android Emulatorを先に起動しておく.

$ cd ~/Library/Android/sdk/tools
$ ./emulator -list-avds
Galaxy_Nexus_API_23
Nexus_5X_API_23

$ ./emulator -avd Nexus_5X_API_23
参考

Build Your App from the Command Line | Android Studio