2017-02-14 18:14 4673人阅读 评论(0) 收藏 举报
 分类:
kotlin

转载地址:http://www.tuicool.com/articles/faqyMzE

gitbook 墙内访问速度很糟糕 现在有了 墙内地址 啦 :)

国内服务器由 掘金 赞助

稀土掘金:挖掘最优质的互联网技术 / 联合编辑每日精选内容 / 移动端优质阅读体验

本书源码在github

pd下载 ePub下载

记得要点 star star star

发现有翻译的不好的或者错误欢迎到 github 提issue

号外 号外 Kotlin 1.0 正式发布

Android 世界的 Swift 终于发布1.0版本

Kotlin 是一个实用性很强的语言,专注于互通,安全,简洁,工具健全...

无缝支持 Java+Kotlin 项目,可以更少的使用样版代码,确保类型安全。

Kotlin 1.0 更新日志

还换了logo :)

Kotlin LOC (软件规模代码行) 如下图

近期我会重新读一遍 Kotlin 官方文档 并对现在的这份文档进行更新(又立 flag 了) -- 2016.2.16

如何在Android studio中使用KotLin
 
在根目录build.gradle里边添加相应的依赖就好
看示例:

  1. // Top-level build file where you can add configuration options common to all sub-projects/modules.
  2. buildscript {
  3. ext.kotlin_version = '1.0.6'
  4. repositories {
  5. jcenter()
  6. }
  7. dependencies {
  8. classpath 'com.android.tools.build:gradle:2.0.0'
  9. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  10. classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
  11. }
  12. }
  13. allprojects {
  14. repositories {
  15. jcenter()
  16. }

添加了版本号以及要使用的俩个依赖,如果需要还可以导入其他的依赖。

在app的目录(也就是你android代码目录)的build.gradle文件中添加简单的设置就好
看示例:

  1. buildscript {
  2. repositories {
  3. jcenter()
  4. }
  5. dependencies {
  6. classpath 'com.android.tools.build:gradle:2.0.0'
  7. }
  8. }
  9. def getDate() {
  10. return Calendar.getInstance().getTimeInMillis();
  11. }
  12. allprojects {
  13. repositories {
  14. jcenter()
  15. }
  16. }
  17. apply plugin:  'com.android.application'
  18. apply plugin: 'kotlin-android'
  19. dependencies {
  20. compile 'com.android.support:support-v4:23.1.1'
  21. compile 'com.android.support:appcompat-v7:23.1.1'
  22. compile 'com.android.support:design:23.1.1'
  23. compile 'com.android.support:preference-v7:23.1.1'
  24. compile 'org.apache.commons:commons-compress:1.10'
  25. compile 'commons-net:commons-net:3.3'
  26. compile 'com.github.zafarkhaja:java-semver:0.9.0'
  27. compile 'org.unbescape:unbescape:1.1.1.RELEASE'
  28. compile 'org.msgpack:msgpack:0.6.12'
  29. compile 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
  30. compile 'org.tukaani:xz:1.5'
  31. compile 'ch.acra:acra:4.6.2'
  32. testCompile 'junit:junit:4.12'
  33. compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  34. }
  35. android {
  36. compileSdkVersion 23
  37. buildToolsVersion '23.0.2'
  38. compileOptions {
  39. sourceCompatibility JavaVersion.VERSION_1_7
  40. targetCompatibility JavaVersion.VERSION_1_7
  41. }
  42. packagingOptions {
  43. exclude 'META-INF/LICENSE.txt'
  44. exclude 'META-INF/NOTICE.txt'
  45. }
  46. defaultConfig {
  47. minSdkVersion 9
  48. targetSdkVersion 22
  49. versionCode 4
  50. versionName "1.7.0-unstable"
  51. if(System.getenv("NIGHTLY_BUILD")) {
  52. versionName += "+" + System.getenv("NIGHTLY_BUILD_COMMIT").substring(0, 7)
  53. }
  54. }
  55. lintOptions {
  56. if (System.getenv("NIGHTLY_BUILD")) {
  57. checkReleaseBuilds false
  58. }
  59. abortOnError false
  60. }
  61. signingConfigs {
  62. release {
  63. if (System.getenv("KEYSTORE_FILE") != null) {
  64. storeFile = file(System.getenv("KEYSTORE_FILE"))
  65. storePassword = System.getenv("KEYSTORE_PWD")
  66. keyAlias = System.getenv("KEYSTORE_ALIAS")
  67. keyPassword = System.getenv("KEYSTORE_ALIAS_PWD")
  68. }
  69. return true
  70. }
  71. }
  72. buildTypes {
  73. debug {
  74. buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + getDate() + "L)"
  75. buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\"";
  76. minifyEnabled false
  77. shrinkResources false
  78. debuggable true
  79. jniDebuggable true
  80. zipAlignEnabled true
  81. multiDexEnabled true
  82. }
  83. release {
  84. buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + getDate() + "L)"
  85. buildConfigField "String", "BUILD_NAME", "\"" + System.getenv("USER") + "\"";
  86. if (System.getenv("KEYSTORE_FILE") != null) {
  87. signingConfig signingConfigs.release
  88. }
  89. multiDexEnabled true
  90. return true
  91. }
  92. }
  93. sourceSets {
  94. main.java.srcDirs += 'src/main/kotlin'
  95. }
  96. }
  97. repositories {
  98. mavenCentral()
  99. }

主要添加了有3个地方:
1、

  1. <span style="white-space:pre">  </span>apply plugin: 'kotlin-android'

2、

  1. <span style="white-space:pre">  </span>compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

3、

  1. android{
  2. ......
  3. sourceSets {
  4. main.java.srcDirs += 'src/main/kotlin'
  5. }
  6. }

这样就可以正常使用了。

如果出现
Execution failed for task ':app:clean'.
> Unable to delete file: C:\Users\User\KotlinGameEngine\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\jars\classes.jar
类似这样的问题,那么只要在app目录下的build.gradle文件中添加task:

  1. task clean(type: Exec) {
  2. ext.lockhunter = '\"C:\\LockHunter.exe\"'
  3. def buildDir = file(new File("build"))
  4. commandLine 'cmd', "$lockhunter", '/delete', '/silent', buildDir
  5. }

如果出现Unresolved reference: kotlinx这样的问题,那么需要在app目录下的build.gradle文件中添加:
apply plugin: 'kotlin-android-extensions'
以及要确保classpath配置了classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

 
1
1
 
  相关文章推荐
 
 
查看评论
  暂无评论

 
 
您还没有登录,请[登录][注册]
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
 
 
 
 
    个人资料

Kotlin 中文文档的更多相关文章

  1. Reactor3 中文文档(用户手册)

    文章很长,建议收藏起来,慢慢读! 疯狂创客圈为小伙伴奉上以下珍贵的学习资源: 疯狂创客圈 经典图书 : <Netty Zookeeper Redis 高并发实战> 面试必备 + 大厂必备 ...

  2. Phoenix综述(史上最全Phoenix中文文档)

    个人主页:http://www.linbingdong.com 简书地址:http://www.jianshu.com/users/6cb45a00b49c/latest_articles 网上关于P ...

  3. Chart.js中文文档-雷达图

    雷达图或蛛网图(Radar chart) 简介 A radar chart is a way of showing multiple data points and the variation bet ...

  4. Knockout中文开发指南(完整版API中文文档) 目录索引

    a, .tree li > span { padding: 4pt; border-radius: 4px; } .tree li a { color:#46cfb0; text-decorat ...

  5. ReactNative官方中文文档0.21

    整理了一份ReactNative0.21中文文档,提供给需要的reactnative爱好者.ReactNative0.21中文文档.chm  百度盘下载:ReactNative0.21中文文档 来源: ...

  6. java中文文档官方下载

    一直在寻找它,今天无意之间终于发现它了! http://download.oracle.com/technetwork/java/javase/6/docs/zh/api/overview-summa ...

  7. Spring中文文档

    前一段时间翻译了Jetty的一部分文档,感觉对阅读英文没有大的提高(*^-^*),毕竟Jetty的受众面还是比较小的,而且翻译过程中发现Jetty的文档写的不是很好,所以呢翻译的兴趣慢慢就不大了,只能 ...

  8. jQuery 3.1 API中文文档

    jQuery 3.1 API中文文档 一.核心 1.1 核心函数 jQuery([selector,[context]]) 接收一个包含 CSS 选择器的字符串,然后用这个字符串去匹配一组元素. jQ ...

  9. jQuery EasyUI API 中文文档 - ComboGrid 组合表格

    jQuery EasyUI API 中文文档 - ComboGrid 组合表格,需要的朋友可以参考下. 扩展自 $.fn.combo.defaults 和 $.fn.datagrid.defaults ...

随机推荐

  1. BZOJ 3667 Pollard-rho &Miller-Rabin

    论O(1)快速乘和O(logn)快速乘的差距-. //By SiriusRen #include <cstdio> #include <algorithm> using nam ...

  2. Request.QueryString["id"] 、Request.Params["id"] 的强大

    <form> <input type="text" name="id" value="值"> </form&g ...

  3. CSS3 过渡、动画、多列、用户界面

    CSS3 过渡.动画.多列.用户界面 transition过渡 transition: transition-property transition-duration transition-timin ...

  4. PopupWindow实现点击外部不消失

    View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.alert_ip, null); final Po ...

  5. 粘包_Server

    from socket import *# import subprocessip_port = ('127.0.0.1',8080)back_log = 5buffer_size = 1024tcp ...

  6. css——样式的继承

    css的样式继承 在上面这段代码中,p{}为父类,b{}为子类.b{}将继承p{}. 因为<b>在<p>里面,p{}为父类,b{}为子类. 继承方式: 如果子类没有,父类有,则 ...

  7. logstash配置如何理解?

    elasticsearch {   action => "index" #The operation on ES   hosts => "localhost: ...

  8. JS一个经典闭包问题

    这里是记录一些本人在学习过程中觉得重要的知识点,记录下来以供日后查看,如有不对欢迎指正,望在前端的路上共勉! <!DOCTYPE html> <html lang="en& ...

  9. React 中的 refs的应用

    React Refs React 支持一种非常特殊的属性 Ref ,你可以用来绑定到 render() 输出的任何组件上. 这个特殊的属性允许你引用 render() 返回的相应的支撑实例( back ...

  10. FastDFS 工具类实现文件上传_02

    一.jar 包 jar包下载:https://pan.baidu.com/s/1nwkAHU5 密码:tlv6 或者 下载工程,安装到 maven 本地仓库 工程下载:https://pan.baid ...