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

问题描述

我有一个使用Android studio 3.2的Java项目,我想添加一些Scala文件.我已经阅读过在Android Studio中将Scala与Java结合使用我对此有一些疑问.

I have a project in Java with Android studio 3.2, and I want to add some Scala files.I have already read this Using Scala with Java in Android Studioand I have some questions about it.

据我了解,当您想要拥有Java和Scala文件时,最好使用gradle scala插件而不是scala插件.但是因为这个话题太老了,所以我想知道它是否仍然是真的,还是我应该使用scala插件.

From what I understand, when you want to have java and scala files, it's better to use the gradle scala plugin instead of the scala plugin.But because the topic is rather old, I was wondering if it's still true, or if I should use the scala plugin.

感谢您的回答和建议!

推荐答案

我创建了这个插件 https://github.com/AllBus/gradle-android-scala-plugin 此版本的插件支持Android 28和Gradle 5.3

I create fork this plugin https://github.com/AllBus/gradle-android-scala-pluginThis version of the plugin supports Android 28 and Gradle 5.3

将此代码写入build.gradle文件

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'
    }
}

并添加app/build.gradle

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"
    ...

}

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

07-23 22:02