ようへい
ラベル Ruby の投稿を表示しています。 すべての投稿を表示
ラベル Ruby の投稿を表示しています。 すべての投稿を表示

2020年5月2日土曜日

[Windows 10] Ruby 2.7 & RMagick (ImageMagick) 環境構築

そろそろ Ruby 2.7 環境を作ろうと思ったので、ついでに RMagick を使える環境を構築。

準備するファイル

Ruby 2.7 + Devkit
WITH DEVKIT の方をダウンロードする。
Ruby Installer for WIndows
https://rubyinstaller.org/downloads/
ImageMagick
RMagick の GitHub をチェックすると、
ImageMagick Version 6.7.7 or later (6.x.x). Version 7 has beta support in version 4.1.0.rc2 (#256).
rmagick/rmagick: Ruby bindings for ImageMagick
https://github.com/rmagick/rmagick
と書かれているため、6系の最新をインストールすることにする。
6系は公式サイトからではなく、以下からダウンロードする。
ImageMagick binaries
http://www.imagemagick.org/download/binaries/ 今回は 6.9.11-10 を使用

セットアップ

  1. Ruby 2.7 をインストール
    • Select ComponentsMSYS2 development toolchain yyyy-mm-dd にチェックを付ける
    • セットアップ後、MSYS2 のセットアップ画面が表示されます。
      閉じてしまった場合は以下を実行
      $ ridk install
      Which components shall be installed? If unsure press ENTER [1,3] と表示されるので 1,2,3 と入力してセットアップしてください。
  2. ImageMagick をインストール
    • Select Additional TasksAdd application directory to your system pathInstall development headers and libraries for C and C++ にチェックを付ける
  3. RMagick をインストール
    • ターミナルを起動し、gem をインストール
      $ ruby -v
      ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
      $ gem install rmagick
      Fetching rmagick-4.1.2.gem
      Temporarily enhancing PATH for MSYS/MINGW...
      Building native extensions. This could take a while...
      Successfully installed rmagick-4.1.2
      Parsing documentation for rmagick-4.1.2
      Installing ri documentation for rmagick-4.1.2
      Done installing documentation for rmagick after 2 seconds
      1 gem installed

動作確認

$ ruby -r rmagick -e "puts Magick::colors"
上記で結果がズラズラ出ればとりあえず良さそう。
ただ、昔、rmagick と ImageMagick の相性問題に悩まされた記憶があるので、画像も読み込めるか確認。
$ ruby -r rmagick -e "Magick::Image.read('C:/Program Files/ImageMagick-6.9.11-Q16/images/logo-sm.png').map{|im| puts im.columns, im.rows }"
128
96
大丈夫そうですね。

まとめ

相性問題もあるので情報をまとめておきます。
  • Ruby 2.7.1p83
  • ImageMagick-6.9.11-10-Q16-x64-dll.exe
  • RMagick 4.1.2
関連記事

2017年9月19日火曜日

カッコいいスライドが作れる! reveal-ck 環境構築 (Windows編)

最近になって、reveal-ck という、Markdown でカッコいいスライドが作れるツールを知った。
GitHub - jedcn/reveal-ck: Create slides with markdown
https://github.com/jedcn/reveal-ck reveal-ck は reveal.js のスライドを簡単に作れるようにしたものらしい。

reveal.js のデモ
reveal.js – The HTML Presentation Framework
http://lab.hakim.se/reveal-js/ ということで早速環境を作ってスライドを作ってみようと思う。

準備するもの

Ruby 2.4
以下からダウンロード
RubyInstaller for Windows - Downloads
https://rubyinstaller.org/downloads/

Ruby インストール

Ruby・MSYS
Ruby のインストーラを起動し、Ruby をインストール。
カッコいいスライドが作れる! reveal-ck 環境構築 (Windows編)
インストーラの最後の画面で ridk で MSYS インストールするか みたいなチェックボックスが出てくるのでチェックがついていることを確認して Finish
 _____       _           _____           _        _ _         ___
|  __ \     | |         |_   _|         | |      | | |       |__ \
| |__) |   _| |__  _   _  | |  _ __  ___| |_ __ _| | | ___ _ __ ) |
|  _  / | | | '_ \| | | | | | | '_ \/ __| __/ _` | | |/ _ \ '__/ /
| | \ \ |_| | |_) | |_| |_| |_| | | \__ \ || (_| | | |  __/ | / /_
|_|  \_\__,_|_.__/ \__, |_____|_| |_|___/\__\__,_|_|_|\___|_||____|
                    __/ |           _
                   |___/          _|_ _  __   | | o __  _| _     _
                                   | (_) |    |^| | | |(_|(_)\^/_>

   1 - MSYS2 base installation
   2 - MSYS2 system update
   3 - MSYS2 and MINGW development toolchain

Which components shall be installed? If unsure press ENTER [1,2,3]
と表示されるので、1 → 2 → 3 の順で実行
うっかり画面を閉じてしまったりした場合は
> C:\Ruby24-x64\bin\ridk install
のような感じで ridk を起動すれば良い。
Ruby 環境設定
gem のドキュメントをインストールしたくない場合は以下のファイルを作成。
(私は今まで必要になったことはないです)

%USERPROFILE%\.gemrc
install: --no-document
update: --no-document
MSYS 環境設定
MSYS で Ruby に PATH を通すため以下を設定

C:\msys64\home\<ユーザ名>\.bash_profile
PATH="/c/Ruby24-x64/bin:${PATH}"

reveal-ck インストール

MSYS を実行し、一応 .bash_profile 再読み込み。
$ source ~/.bash_profile
reveal-ck インストール
$ gem install reveal-ck
依存関係を解決しながらズラズラとインストールされます。

試す

さっそく reveal-ck を試します
インストールディレクトリで slides.md を作成
## Hello World!
:smile:

***

### vertical 1

---

### vertical 2

***

### horizontal 1

---

### horizontal 2
以下のコマンドで generate してスライドのデータを作成します
$ reveal-ck generate
以下のコマンドで、slides.md の変更を監視し、ライブリロード(リアルタイムでブラウザで表示)させることができます。
$ reveal-ck serve
面倒なので以下のようなバッチを作っておくと楽
set PATH=C:\Ruby24-x64\bin;%PATH%
reveal-ck generate
set PATH=C:\Ruby24-x64\bin;%PATH%
"%PROGRAMFILES(X86)%\Google\Chrome\Application\chrome.exe" http://localhost:10000
reveal-ck serve

トラブル

reveal-ck serve でエラーが表示される
こんなエラー
[ reveal-ck ] Getting Ready to Reload Browsers.
[ reveal-ck ] Getting Ready to Rebuild Slides.
  Please add the following to your Gemfile to avoid polling for changes:
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
[ reveal-ck ] Starting Webserver.
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
[   reload  ] Run 'gem install win32console' to use color on Windows
[   reload  ] Could not load 'guard/livereload' or find class Guard::Livereload
[   reload  ] Error is: cannot load such file -- 2.4/rubyeventmachine
[   reload  ] C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
> [#] C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
見た感じ、いくつか gem が足りてなさそう。
wdm と eventmachine を入れる
$ gem install wdm eventmachine
再実行
[ reveal-ck ] Starting Webserver.
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
[   reload  ] Run 'gem install win32console' to use color on Windows
[   reload  ] Could not load 'guard/livereload' or find class Guard::Livereload
[   reload  ] Error is: cannot load such file -- 2.4/rubyeventmachine
[   reload  ] C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
> [#] C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
またエラー
win32console が足りないらしい。
Could not load 'guard/livereload' or find class Guard::Livereload は eventmachine が 1.0.9.1 より新しいバージョンを使用すると発生するらしい。
$ gem install win32console
$ gem install eventmachine --version 1.0.9.1
$ gem uninstall eventmachine

Select gem to uninstall:
 1. eventmachine-1.0.9.1
 2. eventmachine-1.2.5-x64-mingw32
 3. All versions
> 2
Successfully uninstalled eventmachine-1.2.5-x64-mingw32
無事エラーが出なくなりました。
Gemfile つくるなら
source "https://rubygems.org"

gem 'wdm'
gem 'eventmachine', '1.0.9.1'
gem 'reveal-ck'
gem 'win32console'
みたいなの作って bundle install してもいい
スライドが1ページしか作られない
slides.md の改行コードが CRLF だとスライドが正常に作られません
LF で保存しなおすと、ちゃんと生成されるはず
関連記事

2013年8月6日火曜日

Rubyで、パスに特殊文字を含むファイルの存在確認を行う

ファイルがあるのに「No such file or directory」

Windows上でRubyを使っていると、ファイルパスに特殊文字を含んだファイルを扱う事がある。
e.g.,
».htm
®.htm
™.htm
これらのファイルをRubyスクリプトの引数で渡してもファイル名が化けてしまったりしてうまく扱えない。
こんなRubyスクリプトに渡してみる。
#!ruby
# -*- coding: utf-8 -*-

puts File.basename( ARGV[0] )
puts File.exist?( ARGV[0] )
puts File.exist?( ARGV[0].dup.force_encoding( 'utf-8' ) )
puts ARGF.path
環境はWindows 7、Ruby 1.9.3、Encoding.locale_charmapCP932。 このスクリプトに先のファイル名を与えると以下のような結果になる。
».htm
≫.htm
false
false
file_check.rb:7:in `path': No such file or directory - ≫.htm (Errno::ENOENT)
 from file_check.rb:7:in `<main>'
®.htm
R.htm
false
false
file_check.rb:7:in `path': No such file or directory - R.htm (Errno::ENOENT)
 from file_check.rb:7:in `<main>'
™.htm
R.htm
false
false
file_check.rb:7:in `path': No such file or directory - R.htm (Errno::ENOENT)
 from file_check.rb:7:in `<main>'
UTF-8のバイナリで表すと、以下のように文字が変化してしまっている。
».htm -> ».htm (0xC2 0xBB -> 0xE2 0x89 0xAB)
®.htm -> R.htm (0xC2 0xAE -> 0x52)
™.htm -> R.htm (0xC2 0xE2 0x84 0xA2 -> 0x52)
どーしたらいいんでしょうか。

できる対処法

とりあえず、Rubyをキックするバッチを作って、その中でテンポラリディレクトリにファイルを複製、リネームして、そのファイルをRubyスクリプトに与えることで対処。
こんなかんじ。
SET FDATE=%date:~2%
SET FTIME=%time:.=-%
SET FTIME=%FTIME: =%
SET TEMP_F="%TEMP%\%FDATE:/=-%_%FTIME::=-%%~x1"

COPY %1 %TEMP_F%
C:\Ruby193\bin\ruby file_check.rb %TEMP_F%
DEL %TEMP_F%
Rubyの中で、オリジナルのパス名が必要なら、こんなカンジ。
SET FDATE=%date:~2%
SET FTIME=%time:.=-%
SET FTIME=%FTIME: =%
SET TEMP_F="%TEMP%\%FDATE:/=-%_%FTIME::=-%%~x1"

COPY %1 %TEMP_F%
C:\Ruby193\bin\ruby file_check.rb %TEMP_F% %1
DEL %TEMP_F%
とりあえずファイル読めるようになる。
もっと効率良い方法あると思うので、教えてください。
関連記事

2012年10月31日水曜日

ruby_apk v0.4.1 を試す

Androidのパッケージファイル(apk)をAndroid SDK無しで解析できるRuby Gemが公開されたようなので試してみました。

準備

Ruby 1.9 系のインストーラをダウンロードしインストールする。
rubyinstaller-1.9.3-p286.exe をダウンロードしました。
RubyForge: Ruby Installer for Windows: ファイルリスト
http://rubyforge.org/frs/?group_id=167 コマンドプロンプトを起動する。
プロクシ環境配下の場合は、プロクシ設定を行う。
>set http_proxy=proxy.example.com:8080
色々入れる前にアップデート
>gem update --system --platform=mswin32
Latest version currently installed. Aborting.
rubyzipのインストール
>gem install rubyzip --platform=mswin32 --verbose
GET http://rubygems.org/latest_specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
200 OK
GET http://rubygems.org/quick/Marshal.4.8/rubyzip-0.9.9.gemspec.rz
302 Moved Temporarily
GET http://tokyo-m.rubygems.org/quick/Marshal.4.8/rubyzip-0.9.9.gemspec.rz
200 OK
Installing gem rubyzip-0.9.9
Downloading gem rubyzip-0.9.9.gem
GET http://rubygems.org/gems/rubyzip-0.9.9.gem
302 Moved Temporarily
GET http://tokyo-m.rubygems.org/gems/rubyzip-0.9.9.gem
200 OK
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/samples/example.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/samples/example_filesystem.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/samples/example_recursive.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/samples/gtkRubyzip.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/samples/qtzip.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/samples/write_simple.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/samples/zipfind.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/compressor.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/constants.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/decompressor.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/deflater.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/dos_time.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/inflater.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/ioextras.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/null_compressor.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/null_decompressor.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/null_input_stream.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/pass_thru_compressor.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/pass_thru_decompressor.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/settings.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/tempfile_bugfixed.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_central_directory.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_entry.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_entry_set.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_extra_field.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_file.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_input_stream.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_output_stream.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_streamable_directory.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zip_streamable_stream.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/lib/zip/zipfilesystem.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/README.md
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/NEWS
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/TODO
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rubyzip-0.9.9/Rakefile
Successfully installed rubyzip-0.9.9
1 gem installed
Installing ri documentation for rubyzip-0.9.9...
rdoc --ri --op c:/Ruby193/lib/ruby/gems/1.9.1/doc/rubyzip-0.9.9/ri lib --title rubyzip-0.9.9 Documentation --quiet
Installing RDoc documentation for rubyzip-0.9.9...
rdoc --op c:/Ruby193/lib/ruby/gems/1.9.1/doc/rubyzip-0.9.9/rdoc lib --title rubyzip-0.9.9 Documentation --quiet
インストールを確認
>gem list --local

*** LOCAL GEMS ***

bigdecimal (1.1.0)
io-console (0.3)
json (1.5.4)
minitest (2.5.1)
rake (0.9.2.2)
rdoc (3.9.4)
rubyzip (0.9.9)
ruby_apkインストール
>gem install ruby_apk --platform=mswin32 --verbose
GET http://rubygems.org/latest_specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
200 OK
GET http://rubygems.org/quick/Marshal.4.8/ruby_apk-0.4.1.gemspec.rz
302 Moved Temporarily
GET http://tokyo-m.rubygems.org/quick/Marshal.4.8/ruby_apk-0.4.1.gemspec.rz
200 OK
GET http://rubygems.org/quick/Marshal.4.8/rubyzip-0.9.9.gemspec.rz
302 Moved Temporarily
GET http://tokyo-m.rubygems.org/quick/Marshal.4.8/rubyzip-0.9.9.gemspec.rz
200 OK
Installing gem ruby_apk-0.4.1
Downloading gem ruby_apk-0.4.1.gem
GET http://rubygems.org/gems/ruby_apk-0.4.1.gem
302 Moved Temporarily
GET http://tokyo-m.rubygems.org/gems/ruby_apk-0.4.1.gem
200 OK
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/.rspec
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/Gemfile
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/Gemfile.lock
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/LICENSE.txt
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/README.md
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/Rakefile
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/VERSION
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/apk.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/axml_parser.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/dex.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/dex/access_flag.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/dex/dex_object.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/dex/info.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/dex/utils.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/manifest.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/resource.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/android/utils.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/lib/ruby_apk.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/ruby_apk.gemspec
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/apk_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/axml_parser_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/data/sample.apk
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/data/sample_AndroidManifest.xml
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/data/sample_classes.dex
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/data/sample_resources.arsc
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/data/sample_resources_utf16.arsc
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/dex/access_flag_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/dex/dex_object_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/dex/info_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/dex/utils_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/dex_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/manifest_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/resource_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/ruby_apk_spec.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/spec_helper.rb
c:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby_apk-0.4.1/spec/utils_spec.rb
Successfully installed ruby_apk-0.4.1
1 gem installed
Installing ri documentation for ruby_apk-0.4.1...
rdoc --ri --op c:/Ruby193/lib/ruby/gems/1.9.1/doc/ruby_apk-0.4.1/ri lib LICENSE.txt README.md --title ruby_apk-0.4.1 Documentation --quiet
Installing RDoc documentation for ruby_apk-0.4.1...
rdoc --op c:/Ruby193/lib/ruby/gems/1.9.1/doc/ruby_apk-0.4.1/rdoc lib LICENSE.txt README.md --title ruby_apk-0.4.1 Documentation --quiet
インストールを確認
>gem list --local

*** LOCAL GEMS ***

bigdecimal (1.1.0)
io-console (0.3)
json (1.5.4)
minitest (2.5.1)
rake (0.9.2.2)
rdoc (3.9.4)
ruby_apk (0.4.1)
rubyzip (0.9.9)
よし、準備が整った。

実行

こんなコードを書いて、適当なapkをくわせる。
require 'ruby_apk'

apk = Android::Apk.new(ARGV.first)
m = apk.manifest
puts "package_name: #{m.package_name}"
puts "version_name: #{m.version_name}"
出力結果
package_name: com.blogspot.logroid
version_name: 2.2
SDK無しで情報取れるのは良いんだけど、まだまだ解析がイマイチ。
apktoolでデコードするとこんな感じのAndroidManifest.xmlが取り出される。
※先頭から一部を抜粋
<?xml version="1.0" encoding="utf-8"?>
<manifest android:versionCode="220000" android:versionName="2.2" android:installLocation="internalOnly" package="com.blogspot.logroid"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" />
    <supports-screens android:anyDensity="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:resizeable="true" android:xlargeScreens="true" />
    <application android:label="@string/app_name" android:icon="@drawable/icon" android:name="TestApplication" android:hardwareAccelerated="true">
        <provider android:name=".provider.TestProvider" android:exported="false" android:authorities="com.blogspot.logroid.Test">
            <grant-uri-permission android:pathPrefix="/" />
        </provider>
apk_rubyではこんなxmlが取り出される。(manifest.to_xmlの結果)
<manifest xmlns:android='http://schemas.android.com/apk/res/android' android:versionCode='220000' android:versionName='2.2' android:installLocation='1' package='com.blogspot.logroid'>
    <uses-sdk android:minSdkVersion='7' android:targetSdkVersion='16'/>
    <supports-screens android:anyDensity='true' android:smallScreens='true' android:normalScreens='true' android:largeScreens='true' android:resizeable='true' android:xlargeScreens='true'/>
    <application android:label='@0x7f0b0016' android:icon='@0x7f0200dc' android:name='TestApplication' android:hardwareAccelerated='true'>
        <provider android:name='.provider.TestProvider' android:exported='true' android:authorities='com.blogspot.logroid.Test'>
            <grant-uri-permission android:pathPrefix='/'/>
        </provider>
android:labelが@0x7f0b0016となってしまっている。
これでは、リソースから、実態を参照することが出来ない。
ちなみにリソースも、name属性と値をペアで取る事ができず、取ることが出来るのは値のみでした。
name属性分からないから、実態と照らし合わせることが出来ない。
残念。
今のところ、比較的まともに取得できるのは、AndroidManifest.xmlのみのようです。
今後に期待です。
関連記事