What is the simplest way to mix Java+Scala in an A

2020-04-10 03:18发布

问题:

What is the simplest way to mix Java+Scala in an Android project using Gradle ?

Is it using https://github.com/saturday06/gradle-android-scala-plugin ?

I am asking this because examples in gradle-android-scala-plugin don't work and I don't know how to get started, maybe there is some other easy way to mix Scala+Java ?

Is there any simpler (less painful, buggy) way than the gradle-android-scala-plugin ?

回答1:

There is no good solution using gradle.

Use sbt-android instead.



回答2:

Use Android studio 3.3.2 and create Android project.

Write this code in build.gradle file

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'com.github.AllBus:gradle-android-scala-plugin:3.3.2'
    }
}

and add app/build.gradle

apply plugin: "com.android.application"
apply plugin: "jp.leafytree.android-scala"

android {
    compileSdkVersion 28
    ...

}

dependencies {
    implementation "org.scala-lang:scala-library:2.11.12"
    ...

}