[Mac] 開発環境のセットアップ手順メモ

Mac に開発環境をセットアップしたので、やったことと手順をメモ。

GCC をインストール
kennethreitz/osx-gcc-installer

[Mac] Homebrew をインストール(ついでにGitもインストール)

[Mac] zsh のインストール手順と設定メモ

[SSH] 秘密鍵を Dropbox にバックアップしつつ、シンボリックリンクを張って使えるようにする設定

$ ln -s ~/Dropbox/dotfiles/_gitconfig ~/.gitconfig

[Android] FILL_PARENT は非推奨(deprecated)なので MATCH_PARENT を使う(Android2.2以降)

Android アプリ開発にて、2.2以降 は FILL_PARENT は非推奨(deprecated)なので MATCH_PARENT を使うべきだそうです。

ただ、名前変更だけのリファクタリングらしいですが。

[参考]

Yukiの枝折: Android:match_parentとfill_parent

[Android] Crittercism でリアルタイムにクラッシュレポートを把握する

Android アプリに、リアルタイムにクラッシュレポートを把握できる「Crittercism」というサービスを導入しました。

Crittercism | Mobile Application Performance Management

無料版でも、充分使えてかなり助かってます。

今回は、公式ドキュメントに書かれている内容に自分で調べたメモを追加しました。

Crittercism – Installation Instructions

以下、実際に使ってるコードをメモ。

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

READ_LOGS パーミッションについては、ユーザの半分以上が Android 4.1 以上の端末を使っていたので、付与しませんでした。

Android 4.1 以上での動作について Android 4.1 (Jelly Bean) 以上の端末では、この設定を行わなくてもリモート LogCat は機能します。一方、セキュリティ上の理由から、アプリ自身のプロセスから出力されたログ以外は、参照することができません。

[引用]:リモートLogCatの有効化 – DeployGate

MainActivity.java

initCrittercism メソッドは、onCreate メソッドから呼び出します。

import com.crittercism.app.Crittercism;
 
/**
 * Initialize Crittercism (Error reporting and monitoring tool.)
 * http://www.crittercism.com
 */
private void initCrittercism() {
    JSONObject crittercismConfig = new JSONObject();
    try {
        // include version code in version name
        crittercismConfig.put("includeVersionCode", true);
        // necessary for collecting logcat data on Android Jelly Bean devices.
        crittercismConfig.put("shouldCollectLogcat", true);
    } catch (JSONException je) {
    }
 
    Crittercism.init(getApplicationContext(), "<CRITTERCISM_APP_ID>", crittercismConfig);
}

proguard.cfg

proguard を使う場合は、下記の設定も追加しておきましょう。

-keep public class com.crittercism.**
 
-keepclassmembers public class com.crittercism.*
{
    *;
}

最後に、READ_LOGS パーミッションについてよく分からなくて、サポートに問い合わせた時の返信内容をメモ。

Hey,

I’ll try to give you a brief tour of this permission and how it interacts with Crittercism.

Crittercism does not require the READ_LOGS permission in order to function correctly. However, by enabling this permission (where applicable), it can provide additional useful information with every crash and exception report that Crittercism receives.

The Android API:

The logs permission functions in two very different ways depending on the version of the Android API. For versions 15 and lower, any access to the logs requires this permission, and its inclusion gives complete access to all log entries.

As you mentioned, such a global permission poses a potential security risk, and at the very least raises questions about data separation. For this reason, starting in Jelly Bean (API version 16 and higher), Google changed its policy about log access.

After the policy change READ_LOGS no longer works for API Level 16 and higher. With these versions, each app has access to log entries generated by the app itself.

To enable logcat collection for newer devices, you need to include the following code in the onCreate() method of your main activity:

// create the JSONObject. (Do not forget to import org.json.JSONObject!) 
JSONObject crittercismConfig = new JSONObject(); 
try 
{ 
crittercismConfig.put("shouldCollectLogcat", true); // send logcat data for devices with API Level 16 and higher 
} 
catch (JSONException je){}
 
Crittercism.init(getApplicationContext(), "<CRITTERCISM_APP_ID>", crittercismConfig);

Does that answer your questions? For further details, please refer to our documentation, here https://app.crittercism.com/developers/docs-android#including_logcat .

Best regards,

以上です。

[iOS] URL scheme の設定方法

iOS アプリの URLスキームの設定方法をメモ。

URLスキームの設定は下記のサイトを参考にしました。

iOSアプリにとりあえずでもカスタムURLスキームをつけるべし | Technology-Gym

URL Schemes の設定について ios iPhone xcode | Linux & App Labs By pt106

URLスキームでアプリを起動するだけでなく、アプリ起動&指定した動作をさせることもできます。

その際のパスやパラメータの定義は、FacebookアプリのURLスキームの定義が参考になってよさそうです。

IPhone URL Schemes – akosma wiki

以上です。

[Mac] Finder の環境設定メモ [2013年版]

Mac の Finder の環境設定をメモ。

finde_config1

finder-config2

finder-config3

以上です。

[MacOS] システム環境設定の設定メモ [2013年版]

Mac の「システム環境設定」の個人用設定メモをご紹介します。

system-config

続きを読む

[Android] Google Analytics の使い方の参考情報

Android アプリで、Google Analytics を使うために参考にした情報をまとめました。

Google Analytics 公式ドキュメント

Google Analytics SDK for Android v2 (Beta) – Overview

Google Play のダウンロードがどこ経由かトラッキングするためのキャンペーンのパラメータ付きURLを簡単に生成できるツール
Campaign Measurement – Android SDK – Google Analytics

チームEGGによる翻訳ドキュメント

① 「概要」
②「高度な設定」
③「キャンペーントラッキング」
④「クラッシュと例外」
⑤「ディスパッチング」
⑥「eコマーストラッキング」
⑦「イベント」
⑧「スクリーン」
⑨「セッション」
⑩「ユーザータイミング」
⑪「EasyTrackerパラメータ」

[Android] Facebook SDK でエラー : Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {com.example/com.facebook.LoginActivity}: java.lang.NullPointerException

Facebook SDK for Android v3.0 でログイン処理時に NullPointerException エラーが発生しました。

Stack Trace
0	java.lang.RuntimeException: 
Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null}
to activity {com.example/com.facebook.LoginActivity}: java.lang.NullPointerException
1		at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
2		at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
3		at android.app.ActivityThread.access$1100(ActivityThread.java:123)
4		at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
5		at android.os.Handler.dispatchMessage(Handler.java:99)
6		at android.os.Looper.loop(Looper.java:137)
7		at android.app.ActivityThread.main(ActivityThread.java:4424)
8		at java.lang.reflect.Method.invokeNative(Native Method)
9		at java.lang.reflect.Method.invoke(Method.java:511)
10		at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11		at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12		at dalvik.system.NativeStart.main(Native Method)
13	Caused by: java.lang.NullPointerException
14		at com.facebook.AuthorizationClient$KatanaProxyAuthHandler.onActivityResult(SourceFile:645)
15		at com.facebook.AuthorizationClient.onActivityResult(SourceFile:142)
16		at com.facebook.LoginActivity.onActivityResult(SourceFile:134)
17		at android.app.Activity.dispatchActivityResult(Activity.java:4676)
18		at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
19		... 11 more
20	java.lang.NullPointerException
21		at com.facebook.AuthorizationClient$KatanaProxyAuthHandler.onActivityResult(SourceFile:645)
22		at com.facebook.AuthorizationClient.onActivityResult(SourceFile:142)
23		at com.facebook.LoginActivity.onActivityResult(SourceFile:134)
24		at android.app.Activity.dispatchActivityResult(Activity.java:4676)
25		at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
26		at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
27		at android.app.ActivityThread.access$1100(ActivityThread.java:123)
28		at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
29		at android.os.Handler.dispatchMessage(Handler.java:99)
30		at android.os.Looper.loop(Looper.java:137)
31		at android.app.ActivityThread.main(ActivityThread.java:4424)
32		at java.lang.reflect.Method.invokeNative(Native Method)
33		at java.lang.reflect.Method.invoke(Method.java:511)
34		at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
35		at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
36		at dalvik.system.NativeStart.main(Native Method)

Facebook SDK for Android v3.0 のバグらしいので、v3.0.1 にアップデートすることで解決します。

参考情報

[Node.js] コマンドライン引数をカンタンに扱えるモジュール「commander.js」

Node.js で、コマンドライン引数をカンタンに扱えるモジュール「commander.js」がとても便利です!

visionmedia/commander.js · GitHub

[Node.js] http.request で [Error: socket hang up] code: ‘ECONNRESET’

Node.js で HTTPS リクエストを生成するコードで [Error: socket hang up] code: ‘ECONNRESET’ というエラーが発生しました。

エラーメッセージ

Error: socket hang up
    at createHangUpError (http.js:1124:15)
    at Socket.socketOnEnd [as onend] (http.js:1272:23)
    at TCP.onread (net.js:389:26)

HTTPS リクエストを送るのに、https モジュールじゃなく http モジュールを使っていたのが原因でした…

なので、下記のようにちゃんと https モジュールを使えばOKです。

var https = require('https');
 
/**
 * HTTPS POST (JSON)
 *
 * @param {Object} jsonData
 * @param {Function} callback
 * @param {String} encoding
 */
function httpJsonPost(jsonData, callback, encoding) {
  jsonData = jsonData || {};
  encoding = encoding || 'utf8';
 
  var jsonDataString = JSON.stringify(jsonData);
 
  var headers = {
    'Content-Type': 'application/json',
    'Content-Length': jsonDataString.length
  };
 
  var options = {
    host: 'api.example.com',
    port: 443,
    path: '/1/push',
    method: 'POST',
    headers : headers
  };
 
  var req = https.request(options, function(res) {
    res.setEncoding(encoding);
 
    var responseString = '';
 
    res.on('data', function(chunk) {
      responseString += chunk;
    });
 
    res.on('end', function() {
      var resultObject = JSON.parse(responseString);
      return callback(null, resultObject, res.statusCode, JSON.stringify(res.headers));
    });
  });
 
  req.on('error', function(e) {
    return callback(e);
  });
 
  req.write(jsonDataString);
  req.end();
}

[参考情報]

HTTPS Node.js v0.11.2 Manual & Documentation