在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):saturday06/gradle-android-scala-plugin开源软件地址(OpenSource Url):https://github.com/saturday06/gradle-android-scala-plugin开源编程语言(OpenSource Language):Groovy 45.4%开源软件介绍(OpenSource Introduction):gradle-android-scala-plugingradle-android-scala-plugin adds scala language support to official gradle android plugin. See also sample projects at https://github.com/saturday06/gradle-android-scala-plugin/tree/master/sample Table of Contents generated with DocToc
Supported versions
If you want to use older build environment, please try android-scala-plugin-1.3.2 Installation1. Add buildscript's dependency
buildscript {
dependencies {
classpath "com.android.tools.build:gradle:1.3.1"
classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.4"
}
} 2. Apply plugin
apply plugin: "com.android.application"
apply plugin: "jp.leafytree.android-scala" 3. Add scala-library dependencyThe plugin decides scala language version using scala-library's version.
dependencies {
compile "org.scala-lang:scala-library:2.11.7"
} 4. Put scala source filesDefault locations are src/main/scala, src/androidTest/scala. You can customize those directories similar to java.
android {
sourceSets {
main {
scala {
srcDir "path/to/main/scala" // default: "src/main/scala"
}
}
androidTest {
scala {
srcDir "path/to/androidTest/scala" // default: "src/androidTest/scala"
}
}
}
} 5. Implement a workaround for DEX 64K Methods LimitThe Scala Application generally suffers DEX 64K Methods Limit. To avoid it we need to implement one of following workarounds. 5.1. Option 1: Use ProGuardIf your project doesn't need to run Sample proguard configuration here:
From: hello-scaloid-gradle 5.2. Option 2: Use MultiDexAndroid comes with built in support for MultiDex. You will need to use
Using MultiDex with Scala is no different than with a normal Java application. See the Android Documentation and MultiDex author's Documentation for details. It is recommended that you set your
repositories {
jcenter()
}
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies {
compile "org.scala-lang:scala-library:2.11.7"
compile "com.android.support:multidex:1.0.1"
} Change application class.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="jp.leafytree.sample">
<application android:name="android.support.multidex.MultiDexApplication">
</manifest> If you use customized application class, please read next section. To test MultiDexApplication, custom instrumentation test runner should be used. See also https://github.com/casidiablo/multidex/blob/publishing/instrumentation/src/com/android/test/runner/MultiDexTestRunner.java
android {
defaultConfig {
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
}
dependencies {
compile "org.scala-lang:scala-library:2.11.7"
compile "com.android.support:multidex:1.0.1"
androidTestCompile "com.android.support:multidex-instrumentation:1.0.1", { exclude module: "multidex" }
} 5.2.1. Setup application class if you use customized oneSince application class is executed before multidex configuration, Writing custom application class has stll many pitfalls. The application class must extend MultiDexApplication or override
package my.custom.application
import android.app.Application
import android.content.Context
import android.support.multidex.MultiDex
object MyCustomApplication {
var globalVariable: Int = _
}
class MyCustomApplication extends Application {
override protected def attachBaseContext(base: Context) = {
super.attachBaseContext(base)
MultiDex.install(this)
}
} You need to remember: NOTE: The following cautions must be taken only on your android Application class, you don't need to apply this cautions in all classes of your app
override def onCreate = {
super.onCreate
val context = this
new Runnable {
override def run = {
variable = new ClassNeededToBeListed(context, new ClassNotNeededToBeListed)
MyCustomApplication.globalVariable = 100
}
}.run
} This section is copyed from README.md for multidex project ConfigurationYou can configure scala compiler options as follows:
tasks.withType(ScalaCompile) {
// If you want to use scala compile daemon
scalaCompileOptions.useCompileDaemon = true
// Suppress deprecation warnings
scalaCompileOptions.deprecation = false
// Additional parameters
scalaCompileOptions.additionalParameters = ["-feature"]
} Complete list is described in http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.scala.ScalaCompileOptions.html Complete example of build.gradle with manually configured MultiDexApplication
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:1.3.1"
classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.4"
}
}
repositories {
jcenter()
}
apply plugin: "com.android.application"
apply plugin: "jp.leafytree.android-scala"
android {
compileSdkVersion "android-22"
buildToolsVersion "22.0.1"
defaultConfig {
targetSdkVersion 22
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
versionCode 1
versionName "1.0"
multiDexEnabled true
}
productFlavors {
dev {
minSdkVersion 21 // To reduce compilation time
}
prod {
minSdkVersion 8
}
}
sourceSets {
main {
scala {
srcDir "path/to/main/scala" // default: "src/main/scala"
}
}
androidTest {
scala {
srcDir "path/to/androidTest/scala" // default: "src/androidTest/scala"
}
}
}
}
dependencies {
compile "org.scala-lang:scala-library:2.11.7"
compile "com.android.support:multidex:1.0.1"
androidTestCompile "com.android.support:multidex-instrumentation:1.0.1", { exclude module: "multidex" }
}
tasks.withType(ScalaCompile) {
scalaCompileOptions.deprecation = false
scalaCompileOptions.additionalParameters = ["-feature"]
} Changelog
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论