Windowsで、Ruboto製アプリ内で使われているRuboto関連ファイルをアップデートしたときのエラー

古いバージョンを使ったRubotoアプリがあるのですが、最新のRubotoへアップデートしたところエラーが出たため、対応した時のメモ。
なお、通常の流れはGithubにあるRubotoのREADME.mdに記載されています。
ruboto/README.md at master · ruboto/ruboto · GitHub

■環境

旧環境
Platform JDK ant Ruby ruboto jruby-jars Device API level
Windows7 x64 1.7.0_25 1.9.1 RubyInstaller 1.9.3-p448 0.14.0 1.7.4 Nexus7 2012 android-17
新環境

gemは「ruboto」「jruby-jars」を、後は最近リリースされたJavaもバージョンを上げておきました。

Platform JDK ant Ruby ruboto jruby-jars Device API level
Windows7 x64 1.7.0_45 1.9.1 RubyInstaller 1.9.3-p448 0.15.0 1.7.6 Nexus7 2012 android-17

■流れ

Java

JDKを落としてきてインストールします。詳しいことは省略します。



gem

必要なgemをアップデートしておきます。gemのうち「jruby-jars」はインストールしていなかったため、改めてインストールしました。

gem install jruby-jars --no-ri --no-rdoc
gem update ruboto
アプリ自体のアップデート

今回は「d:\GitHub」フォルダにある、「RubotoFelicaRead」アプリをアップデートしてみます。


アプリのルートディレクトリへと移動し、アプリ内のJRubyをアップデートします。
とりあえずエラーは発生していないようです。

# 実行
c:\Users\hoge>cd /d d:\GitHub\RubotoFelicaRead
d:\GitHub\RubotoFelicaRead>ruboto update jruby


# 結果
Current jruby version: 1.7.4
New jruby version: 1.7.6.dev
Removing libs/jruby-core-1.7.4.jar...Done.
Removing libs/jruby-stdlib-1.7.4.jar...Done.
Copying C:/Ruby193/lib/ruby/gems/1.9.1/gems/jruby-jars-1.7.6/lib/jruby-core-complete-1.7.6.dev.jar to libs...Done.
Copying C:/Ruby193/lib/ruby/gems/1.9.1/gems/jruby-jars-1.7.6/lib/jruby-stdlib-complete-1.7.6.dev.jar to libs...Done.
Copying dx.jar to libs...Done.
Removing unneeded classes from jruby-core-1.7.6.dev.jar...exclude pattern "**/*Windows*" found no files...exclude pattern "jnr/constants/platform/darwin" found no files...Done.
Reformatting jruby-stdlib-1.7.6.dev.jar...generator...parser...jline-2.11...readline...ripper...Done.
Removing unneeded classes from dx.jar...Done.
JRuby version is now: 1.7.6.dev


続いて、ruboto関連ファイルをアップデートしますが、そのままではエラー(invalid byte sequence in Windows-31J (ArgumentError))が発生します。

# 実行
d:\GitHub\RubotoFelicaRead>ruboto update app

# 結果
Updated local.properties
Updated file d:\GitHub\RubotoFelicaRead\build.xml
Updated file d:\GitHub\RubotoFelicaRead\proguard-project.txt
Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android.bat update' command.
Updated local.properties
Updated file d:\GitHub\RubotoFelicaRead\test\build.xml
Updated file d:\GitHub\RubotoFelicaRead\test\proguard-project.txt

Copying files:
.gitignore...Done.
Rakefile...Done.
assets...Done.
rakelib...Done.
res/layout...Done.
test...Done.
Copying ruboto/version.rb...Done.
Copying additional ruboto script components...Done.
Ruboto java classes...Done.
Ruboto java test classes...Done.
Regenerating Activity FelicaReadActivity
Updated file d:/GitHub/RubotoFelicaRead/src/jp/gr/java_conf/thinkami/felica_read/FelicaReadActivity.java.
F, [2013-10-24T06:27:27.726369 #2840] FATAL -- : invalid byte sequence in Windows-31J (ArgumentError)
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruboto-0.15.0/lib/ruboto/util/update.rb:266:in `block in update_classes'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruboto-0.15.0/lib/ruboto/util/update.rb:264:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruboto-0.15.0/lib/ruboto/util/update.rb:264:in `update_classes'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruboto-0.15.0/lib/ruboto/commands/base.rb:349:in `run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/main-5.2.0/lib/main/program/class_methods.rb:155:in `block in run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/main-5.2.0/lib/main/program/class_methods.rb:144:in `catch'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/main-5.2.0/lib/main/program/class_methods.rb:144:in `run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/main-5.2.0/lib/main/factories.rb:18:in `run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/main-5.2.0/lib/main/factories.rb:25:in `Main'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruboto-0.15.0/lib/ruboto/commands/base.rb:23:in `main'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruboto-0.15.0/bin/ruboto:11:in `'
C:/Ruby193/bin/ruboto:23:in `load'
C:/Ruby193/bin/ruboto:23:in `

'


エラーが出ている付近のソースコードを見てみると、Windows用のパス区切りになっていないことが分かりました。
「C:\Ruby193\lib\ruby\gems\1.9.1\gems\ruboto-0.15.0\lib\ruboto\util\update.rb」*1の264行目あたりです。
ruboto/lib/ruboto/util/update.rb at 0.15.0 · ruboto/ruboto · GitHub

Dir['src/**/*.java'].each do |f|


そのため、「/」を「\\」へと修正します。

# Dir['src/**/*.java'].each do |f|
Dir['src\\**\\*.java'].each do |f|


その後、再実行すると問題なくアップデートができました。

C:\rubototemp\RubotoFelicaRead>ruboto update app
Updated local.properties
Updated file C:\rubototemp\RubotoFelicaRead\build.xml
Updated file C:\rubototemp\RubotoFelicaRead\proguard-project.txt
Error: The project either has no target set or the target is invalid.
Please provide a --target to the 'android.bat update' command.
Updated local.properties
Updated file C:\rubototemp\RubotoFelicaRead\test\build.xml
Updated file C:\rubototemp\RubotoFelicaRead\test\proguard-project.txt

Copying files:
.gitignore...Done.
Rakefile...Done.
assets...Done.
rakelib...Done.
res/layout...Done.
test...Done.
Copying ruboto/version.rb...Done.
Copying additional ruboto script components...Done.
Ruboto java classes...Done.
Ruboto java test classes...Done.
Copying dx.jar to libs...Done.
JRuby is up to date at version 1.7.6.dev. Make sure you 'gem update jruby-jars' if there is a new version.

Adding RubotoActivity, RubotoDialog, RubotoService, and SDK versions to the manifest...Done.
Copying icons...Done.
Loading Android API...Done.
Generating methods for RubotoActivity...Done. Methods created: 60
Generating methods for RubotoService...Done. Methods created: 7
Generating methods for RubotoBroadcastReceiver...Done. Methods created: 1


最後に、以前と同様のWindowsでのビルド時にエラーとなるのを防ぐため、アップデートされた ruboto.rake ファイルの MINIMUM_DX_HEAP_SIZE の値を修正しておきます。(266行目あたり)
d:\GitHub\RubotoFelicaRead\rakelib\ruboto.rake

# MINIMUM_DX_HEAP_SIZE = 2048
MINIMUM_DX_HEAP_SIZE = 768


あとは、再インストールして起動すれば問題なく動作しました。

d:\GitHub\RubotoFelicaRead>rake reinstall start

■その他のエラー

「Unable to find a javac compiler」エラーが発生する場合

上記とはあまり関係なさそうですが、ビルドするときに以下のようなエラーが出ました。

C:\androidsdk\tools\ant\build.xml:734: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\jre7"


そのため、以下を参考にbuild.xmlファイルを修正し、解消しました。
悪文:[ECLIPSE][ANT]Unable to find a javac compilerエラーの解決 - livedoor Blog(ブログ)

- fork="${need.javac.fork}">
+ fork="true">

*1:デフォルトでインストールした場合