Android Studio開發Groovy,androidgroovy

來源:互聯網
上載者:User

Android Studio開發Groovy,androidgroovy
Context:

主要講下Android Studio如何開發Groovy,搭環境這東西,最噁心。我查了N多的外文。。。。

1.AS(Android Studio)本身是支援Groovy的,Gradle用的文法就是Groovy。也可以在AS中直接建立.groovy尾碼的檔案。

2.Project、Module的build.gradle可以將目錄的展現形式改為Android來識別:

問題:

執行的groovy檔案會提示沒有配置(configure)groovy

解決方案:1.在Project層的build.gradle中加入:

buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.1.0'        classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}

也就是在原有基礎上加

classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'

2.在Module層的build.gradle中加入

apply plugin: 'groovyx.grooid.groovy-android'
dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile 'com.android.support:appcompat-v7:21.+'    compile 'org.codehaus.groovy:groovy:2.4.0:grooid'}
也就是加個plugin和在dependencies加個compile


3.要使用最新的Android Studio1.2Beta3

因為我之前用的是老的,導致無法運行。


4.翻牆:

這個不是必須的,但是在安裝groovy的依賴和AS升級時,可能會影響到。沒辦法天朝技術、管理都不如人。用個VPN就行了,主要百度搜到的第一個的VPN基本都是假冒的,網域名稱都被山寨的搶注了。


源碼:

源碼在我的github上地址是:https://github.com/AlbertSnow/MyGroovyProject.git

檔案是app\src\androidTest\java\com\example\starlight\myapplication\groovyTest.groovy




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.