メモ代わり。てきとーに。 いや、ですからてきとーですって。 2年前ぐらいにPythonあたりでメールくれた方、ごめんなさい。メール紛失してしまい無視した形になってしまいました。。。

2012年4月3日火曜日

[Android][メモ] java.beans.*

android sdk(rev 16)ではjava.beans.*は実装されてないらしい。

だもんで、もう終わってるApache Harmonyからjava.beans実装をパチって
使えるようにしてみる。

Apache Harmonyのjre/lib/boot/beans.jarを<プロジェクト>/libsへコピー。

でコンパイルしてみると、


[dx]
[dx] trouble processing "java/beans/AppletInitializer.class":
[dx]
[dx] Ill-advised or mistaken usage of a core class (java.* or javax.*)
[dx] when not building a core library.
[dx]
[dx] This is often due to inadvertently including a core library file
[dx] in your application's project, when using an IDE (such as
[dx] Eclipse). If you are sure you're not intentionally defining a
[dx] core class, then this is the most likely explanation of what's
[dx] going on.
[dx]
[dx] However, you might actually be trying to define a class in a core
[dx] namespace, the source of which you may have taken, for example,
[dx] from a non-Android virtual machine project. This will most
[dx] assuredly not work. At a minimum, it jeopardizes the
[dx] compatibility of your app with future versions of the platform.
[dx] It is also often of questionable legality.
[dx]
[dx] If you really intend to build a core library -- which is only
[dx] appropriate as part of creating a full virtual machine
[dx] distribution, as opposed to compiling an application -- then use
[dx] the "--core-library" option to suppress this error message.
[dx]
[dx] If you go ahead and use "--core-library" but are in fact
[dx] building an application, then be forewarned that your application
[dx] will still fail to build or run, at some point. Please be
[dx] prepared for angry customers who find, for example, that your
[dx] application ceases to function once they upgrade their operating
[dx] system. You will be to blame for this problem.
[dx]
[dx] If you are legitimately using some code that happens to be in a
[dx] core package, then the easiest safe alternative you have is to
[dx] repackage that code. That is, move the classes in question into
[dx] your own package namespace. This means that they will never be in
[dx] conflict with core system classes. JarJar is a tool that may help
[dx] you in this endeavor. If you find that you cannot do this, then
[dx] that is an indication that the path you are on will ultimately
[dx] lead to pain, suffering, grief, and lamentation.
[dx]
[dx] 1 error; aborting
 

といわれるので、いわれたとおりに作業する。

1. buid.xmlを修正(カスタマイズする準備)
<プロジェクト>/build.xmlの<import file="${sdk.dir}/tools/ant/build.xml" />
をコメントアウト。

<SDK>/tools/ant/build.xmlの<project />の中身
<プロジェクト>/build.xmlの<import file="${sdk.dir}/tools/ant/build.xml" />
のあったところにコピー。


2. jarjarでrepackageするように修正
(jarjar.jarはここらへん)
jarjar-1.2.jarをダウンロードし、<プロジェクト>/buildtools/以下に保存。

jarjarターゲットをbuid.xmlに追加。内容は以下のとおり。

<!-- Converts this project's .class files into .dex files -->
<target name="-jarjar" depends="-compile">
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"
classpath="buildtools/jarjar-1.2.jar"/>
<jarjar jarfile="${out.absolute.dir}/repackagedclasses.jar">
<zipgroupfileset dir="${extensible.libs.classpath}" includes="*.jar" />
<rule pattern="java.beans.**" result="jp.co.qsdn.android.@1"/>
</jarjar>
</target>
 

At this point you'll need to edit the tag to refer to the javax.* appropriate package prefix, and to the rename target.
とのことなので、jp.co.qsdn.android.とした。
これでjava.beans.*パッケージはjp.co.qsdn.android.java.beans.*へ書き換わる。

そして

<target name="-dex" depends="-compile, -post-compile, -obfuscate">
 



<target name="-dex" depends="-compile, -post-compile, -obfuscate, -jarjar">
 

に書き換え。

dex-helper中の

<path refid="jar.libs.ref" />
 



<fileset file="${out.absolute.dir}/repackagedclasses.jar" />
 

に書き換え。

で、できたはず。


$ ant debug


で、とりあえずコンパイルして*-debug.apkは作成できるようになった。
とりあえずjava.beans.*使ったcommons-beanutilsは動いている模様。

うーむ、、、
.