使用Scala针对Android的2.8干线构建 [英] Targeting Android with Scala 2.8 Trunk builds

查看:140
本文介绍了使用Scala针对Android的2.8干线构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关使用Scala在Android上权威的参考似乎是在这里: HTTP://www.scala -lang.org/node/160

The definitive reference for using Scala on android seems to be here: http://www.scala-lang.org/node/160

不幸的是,在使用Scala与Android所有的引用都根据各地的Scala 2.7,是指一个自定义生成的Andr​​oid library.jar,与一对夫妇神秘引用表明该自定义生成不需要更高版本的Andr​​oid的(我使用的是2.1 / API第7版)

Unfortunately, all the references on using scala with android are based around Scala 2.7 and refer to a custom build android-library.jar, with a couple of cryptic references suggesting that this custom build isn't needed for later versions of android (I'm using 2.1 / API v7)

所以...什么是使用的Scala 2.8的Andr​​oid项目所需的步骤? preferably使用Eclipse和Android的工具,谷歌用品的IDE。

So... What are the steps needed to use Scala 2.8 in an android project? Preferably using eclipse and the Android tools that Google supplies for that IDE.

推荐答案

编辑:

我的新这样做的方法是用我的Eclipse插件: https://github.com/banshee/AndroidProguardScala (自述有用于安装和指针到正常的Ec​​lipse更新站点的说明)。

My new way of doing this is to use my Eclipse plugin: https://github.com/banshee/AndroidProguardScala (the readme has instructions for installing and a pointer to a normal Eclipse update site).

旧的答案仍然有效,但新的方法是只求更好。

The old answer still works, but the new way is just better.

[老办法] 我的方法:

[The old way] My approach:

  • 使用普通的Andr​​oid / Eclipse工具,用于创建一个Java项目。
  • 添加含有斯卡拉code的第二个项目。这样,我可以不断产生的code以供将来参考(我是新的Andr​​oid和斯卡拉)。该项目可以参考的android.jar。
  • 在斯卡拉项目产生了在Java项目中使用的jar文件
  • 使用ProGuard的剥离图书馆。我相信,这避免了需要对斯卡拉-的android.jar这是在2.7
  • 使用

我没有使用过本作什么比你好更加雄心勃勃的,世界的,所以把它作为一个多组提示的。

I haven't used this for anything more ambitious than hello, world though, so take it as more of a set of hints.

在斯卡拉的项目,我想补充一个生成器(生成器>新建),这只是一个shell脚本中包含项目的根目录中称为pguard:

In the scala project, I add a builder (Builder > New) that's just a shell script called pguard in the root directory of the project containing:

#!/bin/sh
cd $1
PROGUARD=$HOME/dev/proguard/lib/proguard.jar
LIBS=
OUTPUT=lib/proguard.jar
rm -f $OUTPUT
AJAR=/Users/jamesmoore/dev/android-sdk-mac_86/platforms/android-7/android.jar
# java -jar $PROGUARD -injars 'bin:lib/scala-library.jar(!META-INF/MANIFEST.MF,!library.properties)' -outjar $OUTPUT -libraryjars  @proguard.txt
java -Xmx1g -jar $PROGUARD -injars 'bin:lib/scala-library.jar(!META-INF/MANIFEST.MF,!library.properties)' -outjar $OUTPUT -libraryjars $AJAR @proguard.txt

建设者已经地点设置为:

The builder has Location set to:

${build_project}/pguard

和两种工作目录,并设置参数

And both working directory and arguments set to

${build_project}

另外,在斯卡拉项目的根,有一个proguard的参数文件@ proguard.txt:

Also in the root of the scala project, there's a proguard arguments file @proguard.txt:

-dontwarn
-dontoptimize
-dontobfuscate
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
                SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keep public class com.banshee.** {
    public protected *;
}

您会想改变-keep参数,以保持当然你自己的code,

You'll want to change the -keep arguments to keep your own code, of course.

在Java项目,我再补充一点年代由斯卡拉项目(我用的lib / proguard.jar在上面的脚本)。

In the java project, I add the jar file that's produced by the scala project (I use lib/proguard.jar in the script above).

Scala的项目不要加在Java项目的构建路径所需的项目,虽然。这将增加斯卡拉类文件,除了jar文件,迷惑DEX(因为它会得到双方的.class文件,并在罐子同样的事情)。据我所知,Eclipse将在工作区中建立的一切,所以当你点击Go按钮,这两个项目获得建设。

Don't add the scala project as a required project in the java project's build path, though. That will add the scala class files in addition to the jar file and confuse dex (since it'll get both the .class files and the same things in the jar). As far as I can tell, Eclipse will build everything in the workspace, so when you hit the go button, both projects get built.

这篇关于使用Scala针对Android的2.8干线构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆