How Can I Integrate Scala Library In Android Project
I'm trying to integrate a Scala library in an android project. All the articles and previous answers seem to be outdated now. Any help will be really appreciated. Thanks
Solution 1:
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Scala provides language inter-operability with Java, so that libraries written in both languages may be referenced directly in Scala or Java code.
So a Scala library
is just a jar
(zip
of compiled *.class byte-code
files), and you must already know how to load a jar
file.
Add scala-library
dependency to Android Studio using Gradle
Add the Scala plugin
buildscript
dependency to your build.gradle
:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.github.xingda920813:gradle-android-scala-plugin:android-gradle-2.3.0'
}
}
//Apply plugin
apply plugin: "com.android.application"
apply plugin: "jp.leafytree.android-scala"
The plugin
decides scala language version
using scala-library's version
.
In your build.gradle:
dependencies {
compile"org.scala-lang:scala-library:2.11.8"
//**put your library here**
compile"<yourlibrary>:<yourlibrary version>"
//OR you can:
//compile project(":lib1")//your library directory
}
Post a Comment for "How Can I Integrate Scala Library In Android Project"