Scala库为Android [英] Scala library for Android

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

问题描述

我看了题目 IntelliJ IDEA的12个Android +斯卡拉时下这似乎是pretty多少我需要什么。不过,我需要的东西稍有不同:我想刚刚在Scala中创建一个库,并在Android项目中使用它。那Android项目可以使用Java或斯卡拉也没关系。我不想创建一个斯卡拉整个Android项目。

I read a topic IntelliJ Idea 12 + Android + Scala nowadays which seemed to be pretty much what I need. However, I need something slightly different: I want just to create a library in Scala and use it in android project. That android project can use Java or Scala also, it doesn't matter. I don't want to create a whole android project in Scala.

那么,如何建立这样一个库?

So how do I create such a library?

我是否需要创建的Andr​​oid项目利用这里的教程 HTTP ://fxthomas.github.io/android-plugin/ ?或正常Scala库不知道在所有的(事实上,它会在Android项目中使用)的Andr​​oid,然后当我把它添加到Android项目我得添加斯卡拉支持莫名其妙?

Do I need to create an android project using the tutorials from here http://fxthomas.github.io/android-plugin/ ? Or a normal scala library which doesn't know about android at all (the fact that it will be used in an android project), and then when I add it to an android project I'll have to add scala support somehow?

P.S。我用的IntelliJ IDEA 12和SBT。

P.S. I use IntelliJ Idea 12 and sbt.

推荐答案

为了告诉,如果你需要一个Android(库 - )项目,或者你需要清楚地了解您的使用案例的共同斯卡拉应用。其实你要问自己,当你正在建设一个Android库Java的方式非常相同的问题。

In order to tell if you need an Android (library-) project or a common Scala application you need to be clear about your use case. In fact you have to ask yourself the very same question when you are building an Android library the Java way.

当您的库提供任何种类的资源(图片,XML的意见,......),那么你需要创建一个库项目,因为当您包装项目成 *。JAR 文件,这些资源将无法访问了。当你创建一个库项目,那么你也提供库的源$ C ​​$ C给用户。

When your library provides any kind of resources (graphics, xml-views, ...) then you'll need to create a library project because when you wrap the project into a *.jar file these resources will not be accessible any more. When you create a library project, then you're also providing the library's source code to your users.

如果不是这种情况,并在你想建立结束。*你可以用一个共同的斯卡拉项目先走类文件。然后将得到的 *。JAR 文件可以作为图书馆。即使在这样的斯卡拉项目如果您添加的android.jar 你的项目依赖你可能会引用Android的API。

If this is not the case and all you want to build ends up in *.class files you can go ahead with a common Scala project. The resulting *.jar file can then be used as library. And even in such a Scala project you may reference the Android API if you add the android.jar to your project dependencies.

libraryDependencies += "com.google.android" % "android" % "4.1.1.4" % "provided"

这篇关于Scala库为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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