Try out Android-L Samples with Android studio

1. 导入

image1

image2

2. 更新文件

samples/android-L/ui/views/FloatingActionButton/FloatingActionButtonBasic/build.gradle

此文件为空, 添加内容


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

3. 更新文件内容

samples/android-L/ui/views/FloatingActionButton/FloatingActionButtonBasic/FloatingActionButtonBasicSample/build.gradle

原始内容



buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

apply plugin: 'android'


dependencies {

    compile "com.android.support:support-v4:20.+"
    compile "com.android.support:support-v13:20.+"

}

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
    'main',     // main sample code; look here for the interesting stuff.
    'common',   // components that are reused by multiple samples
    'template'] // boilerplate code that is generated by the sample template process

android {
    compileSdkVersion "android-L"

    buildToolsVersion "20.0.0"

    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']

    }

}

更新为:

apply plugin: 'com.android.application'



dependencies {

    compile "com.android.support:support-v4:20.+"
    compile "com.android.support:support-v13:20.+"

}

android {
    compileSdkVersion "android-L"

    buildToolsVersion "20.0.0"

    lintOptions {
        abortOnError false
    }
}

错误

错误Unable to locate a Java Runtime to invoke.

可能是gradlew daemon 进程死掉了。 https://code.google.com/p/android/issues/detail?id=60913

解决方案: 手动杀掉gradle daemon 进程

➜  ClippingBasic  ps aux|grep gradle
lucas           14659   0.0  0.0  2432784    612 s006  S+    4:13PM   0:00.00 grep gradle
lucas           14529   0.0  4.3  3966132 359556   ??  S     4:07PM   0:22.98 /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home/bin/java -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8 -cp /Users/lucas/.gradle/wrapper/dists/gradle-1.12-bin/64p5p2nte80b6rt6bb068pabi6/gradle-1.12/lib/gradle-launcher-1.12.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 1.12 /Users/lucas/.gradle/daemon 10800000 04d22f9b-874b-469b-8011-f7f2819ec409 -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8
➜  ClippingBasic  kill 14529
➜  ClippingBasic  

Could not create plugin of type 'AppPlugin'.

Gradle 版本和gradle android plugin 版本不对 修改gradle 版本

./gradlew --version

 vim ./gradle/wrapper/gradle-wrapper.properties
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

修改 distributionUrl 的值 gradle-1.*-all.zip.

关于Gradle 版本和gradle android plugin 版本的对应关系,见 gradle plugin version compatibility 页面映射表: http://tools.android.com/tech-docs/new-build-system/version-compatibility