matthew as a q.

競技プログラミングメイン

Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style

前提

  • 開発端末: Windows 10
  • エディタ: Atom(editorconfig対応エディタ)
  • 静的解析: eslint
    • .eslintrc.jsにて設定を書いている

どんなエラー?

  • eslintの出す警告
  • 期待する改行コードが"LF"にも関わらず、"CRLF"が改行コードとなっている場合に発生。

解決策

大きく2つある。

Editorで使用する改行コードを"LF"に変更する。

「.editorconfig」に以下を追記。

[*]
end_of_line = lf

期待する改行コードを"CRLF"にする

「.eslintrc.js」に以下を追記

module.exports = {
    "extends": "airbnb",
    "rules": {
      ...
      "linebreak-style": ["error", "windows"], //この行を追記
    },
};

How to solve the failure with react-native run-android

Error Message

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preparePocketsecReactNativeVectorIconsUnspecifiedLibrary'.
> Could not expand ZIP '${your_application_path}\node_modules\react-native-vector-icons\android\build\outputs\aar\react-native-vector-icons-release.aar'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 14.768 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

Assumption

Spec

State

  • Android Emulator has beed executed.

How to solve

  • execute following:
adb devices

This command finds and shows a list of android devices. In addition, if daemon is not running, this command make it running. The error I experienced is caused by not running daemon. Therefore, this command helps me.

React Nativeをブラウザでデバッグする

前提

手順

  • Chromeで以下にアクセス

http://localhost:8081/debugger-ui/

  • Android Emulator上で「Ctrl + m」→ 「Debug JS Remotely」

.jsファイルにJSXを書いても怒られないようにする

なぜやるか

  • React Nativeでは、.jsxを扱えないため、.jsファイルにJSX記法を書く必要がある(2018/1/3現在)

前提

  • 既に、.eslintrc.jsが存在するものとする(つまり、eslint --initは実行済みであること)

手順

  • .eslintrc.jsを以下のように修正
module.exports = {
    "extends": "airbnb",
    "rules": {
      "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
    }
};

Network response timed out.

何の記事?

下記の記事の通り「create-react-native-app」を用いて、React Nativeの開発環境を作成していたところ、タイトルのエラーが発生し、Android端末からアプリの動作確認ができなかったため、その解決策を記載しておくもの。

mae.chab.in

動作環境

- Node: v8.2.1
- NPM: 4.6.1(2017/12/17現在、NPMv5はReact Nativeのサポート対象外で、NPMv5だとcreate-react-native-appコマンドが完了できない)

  • アプリ動作環境:Android 7.0 Galaxy S8
  • 開発環境とアプリ動作環境であるAndroid端末は同じLAN(今回は同一のmobile wifiネットワーク)に繋がっている前提

エラーの発生状況

再現手順

  • 開発環境で以下コマンドを実行(すでにcreate-react-native-appはインストール済みとする。)
  create-react-native-app sample-app
  cd sample-app
  npm start

- 事前にExpoアプリインストール済み
Expo - Google Play の Android アプリ

- エラー画面
f:id:takeknock:20171217181802p:plain

原因と解決策

原因

解決策

  • mobile wifiネットワークで割り振られているローカルipアドレスで起動されるように設定する。
  • 具体的な設定コマンド
set REACT_NATIVE_PACKAGER_HOSTNAME=xxx.xxx.xxx.xxx
  • xxx.xxx.xxx.xxxには、ipconfigコマンドを実行した際に表示される「Wireless LAN adapter Wifi」の「IPv4 アドレス」に表示されているIPアドレスを記載する。