Android、Scala 和 Proguard
在一头扎进了与 Android 命令行工具集的排列一样多的问题之后,我终于成功地将 Scala 和 Java 源代码的混合编译成一个可用的 apk。
正如许多人建议的那样,我使用 proguard
通过 dex
工具压缩 Scala 库。问题是这样的:
BUILD SUCCESSFUL
Total time: 1 minute 29 seconds
一分半钟。我们在这里讨论的是具有 Hello-World 复杂性的应用程序。我想我不可能发展成这样。我需要参加冥想课程。
这是 proguard 配置:
-injars ${out.absolute.dir}/classes:${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)
-outjars ${out.absolute.dir}/classes.min.jar
-libraryjars ${android.jar}
-dontwarn
-dontoptimize
-dontobfuscate
-keep public class * extends android.app.Activity
有没有办法加快 proguard 步骤?
编辑:我在一台相当不错的双核、3GB RAM 机器、64 位 Linux 上运行它。 antcompile
(scalac
/javac
) 的运行需要 3 秒。如上所述,完整的 ant 安装
需要 1 分 30 秒。根据输出,这是“冻结”的“proguard”步骤,很可能是因为 scala/android 运行时库大小。
After running headfirst into as many problems as there are permutations of the set of Android command-line tools, I finally managed to compile a mix of Scala and Java source code into a usable apk.
As many suggest, I used proguard
to squeeze the Scala library through the dex
tool. The problem is this:
BUILD SUCCESSFUL
Total time: 1 minute 29 seconds
One minute and a half. We're talking about an application with Hello-World complexity here. I don't think I can develop like that. I'm gonna need to take meditation classes.
This is the proguard
configuration:
-injars ${out.absolute.dir}/classes:${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)
-outjars ${out.absolute.dir}/classes.min.jar
-libraryjars ${android.jar}
-dontwarn
-dontoptimize
-dontobfuscate
-keep public class * extends android.app.Activity
Is there a way to speed up the proguard step?
Edit: I'm running this in a pretty decent dual-core, 3GB ram machine, on top of 64-bit Linux. A run of ant compile
(scalac
/javac
) takes 3 seconds. A full ant install
takes 1:30, as described above. It's the proguard
step that "freezes", according to the output, most likely because of the scala/android runtime lib sizes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过 android Ant 构建工作可能不是解决此问题的正确方法。
当前的“最佳建议”是将 SBT 与
插件。
Working via android Ant builds is probably not the right way to go about this.
The current "best advice" is to use SBT with the
plugins.
ProGuard 收缩 Scala 2.9.1 库的时间比 Scala 2.8.1 库要长得多(8.5 MB 与 6.2 MB 分别为 54 秒与 13 秒)。要么是库类的结构发生了根本性的变化,要么是一些新的类导致了过多的计算。我必须弄清楚是否可以针对这种情况改进 ProGuard 或其配置。目前,您也许可以使用 Scala 2.8.1。
我假设您的 ProGuard 配置还包含 Android 和 Scala 所需的选项,如 ProGuard 手册中所述。如果您使用常规 Android 构建过程,则已经为您指定了输入(
classes
、libs
)和库(android.jar
)在 Ant 构建文件中,您不需要在 ProGuard 配置文件中再次指定它们。阅读它们两次只会花费时间并生成许多警告(您已完全关闭它们 - 有选择地关闭它们更安全)。ProGuard takes a lot longer to shrink the Scala 2.9.1 library than the Scala 2.8.1 library (54 seconds vs. 13 seconds, for 8.5 MB vs. 6.2 MB). Either the structure of the library classes has changed fundamentally, or some new classes are causing excessive computations. I'll have to figure out if ProGuard or its configuration can be improved for this case. For now, you might be able to work with Scala 2.8.1.
I'm assuming your ProGuard configuration also contains the required options for Android and for Scala, as discussed in the ProGuard manual. If you are using the regular Android build process, the input (
classes
,libs
) and libraries (android.jar
) are already specified for you in the Ant build file, and you don't need to specify them again in the ProGuard configuration file. Reading them twice will just take time and generate many warnings (which you have switched off completely -- it's safer to switch them off selectively).如果您有 root 权限的手机并且只想对此进行测试,您可以直接在手机上安装 scala 库,这样您就不再需要 proguard 步骤:
https://github.com/jrudolph/scala-android-libs
If you have a rooted phone and only want to test on this you can install the scala libs directly on your phone so you don't need the proguard step anymore:
https://github.com/jrudolph/scala-android-libs