当前位置:   article > 正文

关于高版本Android Studio使用KTS(koltin)作为脚本代替Gradle构建的细节_e: d:\news2\app\build.gradle.kts:50:17: unexpected

e: d:\news2\app\build.gradle.kts:50:17: unexpected tokens (use ';' to separa

前两天刚刚才写了安卓构建下载太慢的博客,今天新建项目又用到kotlin作为脚本构建项目时出新问题。一开始我是直接从自己的文章复制粘贴到新项目的gradle当中,结果上来就报好几个红,给我人干懵了。
Unexpected tokens (use ';' to separate expressions on the same line)

pluginManagement {
    repositories {
        maven{ url 'https://maven.aliyun.com/repository/public'}
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "M3Test"
include(":app")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

后知后觉发现自己使用了kotlin作为构建脚本。
百度之后改成了:

pluginManagement {
    repositories {
        maven { url = uri('https://maven.aliyun.com/repository/public') }
        maven { url = uri('https://maven.aliyun.com/repository/google' }
        maven { url = uri('https://maven.aliyun.com/repository/jcenter') }
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "M3Test"
include(":app")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

构建时依然报错:
Too many characters in a character literal 'https://maven.aliyun.com/repository/public'

我又一脸蒙蔽,阅读完报错之后,尝试将单引号改为双引号:

pluginManagement {
    repositories {
        maven { url = uri("https://maven.aliyun.com/repository/public") }
        maven { url = uri("https://maven.aliyun.com/repository/google") }
        maven { url = uri("https://maven.aliyun.com/repository/jcenter") }
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "M3Test"
include(":app")
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

构建成功。

@see also : https://blog.csdn.net/weixin_71703379/article/details/130960999

kotlin有成熟的lambda语法,相对于java的语法更为高级。kotlin运用于前后端与脚本。这里的问题就是kotlin对lambda表达式当中dsl的最好示例。

@see also: https://zhuanlan.zhihu.com/p/24800713

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/538132
推荐阅读
相关标签
  

闽ICP备14008679号