{"id":17771106,"url":"https://github.com/saturday06/gradle-android-scala-plugin","last_synced_at":"2025-04-07T10:26:53.585Z","repository":{"id":13850982,"uuid":"16548412","full_name":"saturday06/gradle-android-scala-plugin","owner":"saturday06","description":"gradle-android-scala-plugin adds scala language support to official gradle android plugin","archived":false,"fork":false,"pushed_at":"2017-10-14T04:57:22.000Z","size":3607,"stargazers_count":342,"open_issues_count":38,"forks_count":64,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-03-31T08:12:15.107Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saturday06.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-05T15:22:07.000Z","updated_at":"2023-12-22T07:26:09.000Z","dependencies_parsed_at":"2022-09-13T01:23:03.814Z","dependency_job_id":null,"html_url":"https://github.com/saturday06/gradle-android-scala-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saturday06%2Fgradle-android-scala-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saturday06%2Fgradle-android-scala-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saturday06%2Fgradle-android-scala-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saturday06%2Fgradle-android-scala-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saturday06","download_url":"https://codeload.github.com/saturday06/gradle-android-scala-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634241,"owners_count":20970491,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-26T21:29:07.041Z","updated_at":"2025-04-07T10:26:53.560Z","avatar_url":"https://github.com/saturday06.png","language":"Groovy","funding_links":[],"categories":["Libs","Android"],"sub_categories":["\u003cA NAME=\"Plugin\"\u003e\u003c/A\u003ePlugin"],"readme":"# gradle-android-scala-plugin\n\ngradle-android-scala-plugin adds scala language support to official gradle android plugin.\nSee also sample projects at https://github.com/saturday06/gradle-android-scala-plugin/tree/master/sample\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n- [Supported versions](#supported-versions)\n- [Installation](#installation)\n  - [1. Add buildscript's dependency](#1-add-buildscripts-dependency)\n  - [2. Apply plugin](#2-apply-plugin)\n  - [3. Add scala-library dependency](#3-add-scala-library-dependency)\n  - [4. Put scala source files](#4-put-scala-source-files)\n  - [5. Implement a workaround for DEX 64K Methods Limit](#5-implement-a-workaround-for-dex-64k-methods-limit)\n    - [5.1. Option 1: Use ProGuard](#51-option-1-use-proguard)\n    - [5.2. Option 2: Use MultiDex](#52-option-2-use-multidex)\n      - [5.2.1. Setup application class if you use customized one](#521-setup-application-class-if-you-use-customized-one)\n- [Configuration](#configuration)\n- [Complete example of build.gradle with manually configured MultiDexApplication](#complete-example-of-buildgradle-with-manually-configured-multidexapplication)\n- [Changelog](#changelog)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Supported versions\n\n| Scala  | Gradle | Android Plugin      | compileSdkVersion | buildToolsVersion |\n| ------ | ------ | ------------------- | ----------------- | ----------------- |\n| 2.11.7 | 2.2.1  | 1.1.3, 1.2.3, 1.3.1 | 21, 22, 23        | 21.1.2, 22.0.1    |\n| 2.10.5 | 2.2.1  | 1.1.3, 1.2.3, 1.3.1 | 21, 22, 23        | 21.1.2, 22.0.1    |\n\nIf you want to use older build environment,\nplease try [android-scala-plugin-1.3.2](https://github.com/saturday06/gradle-android-scala-plugin/tree/1.3.2)\n\n## Installation\n\n### 1. Add buildscript's dependency\n\n`build.gradle`\n```groovy\nbuildscript {\n    dependencies {\n        classpath \"com.android.tools.build:gradle:1.3.1\"\n        classpath \"jp.leafytree.gradle:gradle-android-scala-plugin:1.4\"\n    }\n}\n```\n\n### 2. Apply plugin\n\n`build.gradle`\n```groovy\napply plugin: \"com.android.application\"\napply plugin: \"jp.leafytree.android-scala\"\n```\n\n### 3. Add scala-library dependency\n\nThe plugin decides scala language version using scala-library's version.\n\n`build.gradle`\n```groovy\ndependencies {\n    compile \"org.scala-lang:scala-library:2.11.7\"\n}\n```\n\n### 4. Put scala source files\n\nDefault locations are src/main/scala, src/androidTest/scala.\nYou can customize those directories similar to java.\n\n`build.gradle`\n```groovy\nandroid {\n    sourceSets {\n        main {\n            scala {\n                srcDir \"path/to/main/scala\" // default: \"src/main/scala\"\n            }\n        }\n\n        androidTest {\n            scala {\n                srcDir \"path/to/androidTest/scala\" // default: \"src/androidTest/scala\"\n            }\n        }\n    }\n}\n```\n\n### 5. Implement a workaround for DEX 64K Methods Limit\n\nThe Scala Application generally suffers [DEX 64K Methods Limit](https://developer.android.com/tools/building/multidex.html).\nTo avoid it we need to implement one of following workarounds.\n\n#### 5.1. Option 1: Use ProGuard\n\nIf your project doesn't need to run `androidTest`, You can use `proguard` to reduce methods.\n\nSample proguard configuration here:\n\n`proguard-rules.txt`\n```\n-dontoptimize\n-dontobfuscate\n-dontpreverify\n-dontwarn scala.**\n-ignorewarnings\n# temporary workaround; see Scala issue SI-5397\n-keep class scala.collection.SeqLike {\n    public protected *;\n}\n```\nFrom: [hello-scaloid-gradle](https://github.com/pocorall/hello-scaloid-gradle/blob/master/proguard-rules.txt)\n\n#### 5.2. Option 2: Use MultiDex\n\nAndroid comes with built in support for MultiDex. You will need to use\n`MultiDexApplication` from the support library, or modify your `Application`\nsubclass in order to support versions of Android prior to 5.0. You may still\nwish to use ProGuard for your production build.\n\nUsing MultiDex with Scala is no different than with a normal Java application.\nSee the [Android Documentation](https://developer.android.com/tools/building/multidex.html)\nand [MultiDex author's Documentation](https://github.com/casidiablo/multidex) for\ndetails.\n\nIt is recommended that you set your `minSdkVersion` to 21 or later for\ndevelopment, as this enables an incremental multidex algorithm to be used, which\nis *significantly* faster.\n\n`build.gradle`\n```groovy\nrepositories {\n    jcenter()\n}\n\nandroid {\n    defaultConfig {\n        multiDexEnabled true\n    }\n}\n\ndependencies {\n    compile \"org.scala-lang:scala-library:2.11.7\"\n    compile \"com.android.support:multidex:1.0.1\"\n}\n```\n\nChange application class.\n\n`AndroidManifest.xml`\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"jp.leafytree.sample\"\u003e\n    \u003capplication android:name=\"android.support.multidex.MultiDexApplication\"\u003e\n\u003c/manifest\u003e\n```\n\nIf you use customized application class, please read [next section](#521-setup-application-class-if-you-use-customized-one).\n\nTo test MultiDexApplication, custom instrumentation test runner should be used.\nSee also https://github.com/casidiablo/multidex/blob/publishing/instrumentation/src/com/android/test/runner/MultiDexTestRunner.java\n\n`build.gradle`\n```groovy\nandroid {\n    defaultConfig {\n        testInstrumentationRunner \"com.android.test.runner.MultiDexTestRunner\"\n    }\n}\n\ndependencies {\n    compile \"org.scala-lang:scala-library:2.11.7\"\n    compile \"com.android.support:multidex:1.0.1\"\n    androidTestCompile \"com.android.support:multidex-instrumentation:1.0.1\", { exclude module: \"multidex\" }\n}\n```\n\n##### 5.2.1. Setup application class if you use customized one\n\nSince application class is executed **before** multidex configuration,\nWriting custom application class has stll many pitfalls.\n\nThe application class must extend MultiDexApplication or override\n`Application#attachBaseContext` like following.\n\n`MyCustomApplication.scala`\n```scala\npackage my.custom.application\n\nimport android.app.Application\nimport android.content.Context\nimport android.support.multidex.MultiDex\n\nobject MyCustomApplication {\n  var globalVariable: Int = _\n}\n\nclass MyCustomApplication extends Application {\n  override protected def attachBaseContext(base: Context) = {\n    super.attachBaseContext(base)\n    MultiDex.install(this)\n  }\n}\n```\n\n**You need to remember:**\n\nNOTE: 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\n\n- The static fields in your **application class** will be loaded before the `MultiDex#install`be called! So the suggestion is to avoid static fields with types that can be placed out of main classes.dex file.\n- The methods of your **application class** may not have access to other classes that are loaded after your application class. As workaround for this, you can create another class (any class, in the example above, I use Runnable) and execute the method content inside it. Example:\n\n```scala\n  override def onCreate = {\n    super.onCreate\n\n    val context = this\n    new Runnable {\n      override def run = {\n        variable = new ClassNeededToBeListed(context, new ClassNotNeededToBeListed)\n        MyCustomApplication.globalVariable = 100\n      }\n    }.run\n  }\n```\n\nThis section is copyed from\n[README.md for multidex project](https://github.com/casidiablo/multidex/blob/5a6e7f6f7fb43ba41465bb99cc1de1bd9c1a3a3a/README.md#cautions)\n\n## Configuration\n\nYou can configure scala compiler options as follows:\n\n`build.gradle`\n```groovy\ntasks.withType(ScalaCompile) {\n    // If you want to use scala compile daemon\n    scalaCompileOptions.useCompileDaemon = true\n    // Suppress deprecation warnings\n    scalaCompileOptions.deprecation = false\n    // Additional parameters\n    scalaCompileOptions.additionalParameters = [\"-feature\"]\n}\n```\n\nComplete list is described in\nhttp://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.scala.ScalaCompileOptions.html\n\n## Complete example of build.gradle with manually configured MultiDexApplication\n\n`build.gradle`\n```groovy\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n\n    dependencies {\n        classpath \"com.android.tools.build:gradle:1.3.1\"\n        classpath \"jp.leafytree.gradle:gradle-android-scala-plugin:1.4\"\n    }\n}\n\nrepositories {\n    jcenter()\n}\n\napply plugin: \"com.android.application\"\napply plugin: \"jp.leafytree.android-scala\"\n\nandroid {\n    compileSdkVersion \"android-22\"\n    buildToolsVersion \"22.0.1\"\n\n    defaultConfig {\n        targetSdkVersion 22\n        testInstrumentationRunner \"com.android.test.runner.MultiDexTestRunner\"\n        versionCode 1\n        versionName \"1.0\"\n        multiDexEnabled true\n    }\n\n    productFlavors {\n        dev {\n            minSdkVersion 21 // To reduce compilation time\n        }\n\n        prod {\n            minSdkVersion 8\n        }\n    }\n\n    sourceSets {\n        main {\n            scala {\n                srcDir \"path/to/main/scala\" // default: \"src/main/scala\"\n            }\n        }\n\n        androidTest {\n            scala {\n                srcDir \"path/to/androidTest/scala\" // default: \"src/androidTest/scala\"\n            }\n        }\n    }\n}\n\ndependencies {\n    compile \"org.scala-lang:scala-library:2.11.7\"\n    compile \"com.android.support:multidex:1.0.1\"\n    androidTestCompile \"com.android.support:multidex-instrumentation:1.0.1\", { exclude module: \"multidex\" }\n}\n\ntasks.withType(ScalaCompile) {\n    scalaCompileOptions.deprecation = false\n    scalaCompileOptions.additionalParameters = [\"-feature\"]\n}\n```\n\n## Changelog\n- 1.4 Support android plugin 1.1.3. Manual configuration for dex task is now unnecessary (contributed by [sgrif](https://github.com/sgrif))\n- 1.3.2 Fix unexpected annotation processor's warnings\n- 1.3.1 Support android plugin 0.12.2\n- 1.3 Incremental compilation support in scala 2.11\n- 1.2.1 Fix binary compatibility with JDK6\n- 1.2 Incremental compilation support in scala 2.10 / Flavors support\n- 1.1 MultiDexApplication support\n- 1.0 First release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaturday06%2Fgradle-android-scala-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaturday06%2Fgradle-android-scala-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaturday06%2Fgradle-android-scala-plugin/lists"}