2021年6月15日火曜日

jcenter()が非推奨の為、AndroidStudioで新規作成するとエラー

AndroidStudioで新規プロジェクトを作成すると、以下のエラーが出てビルドできなくなったので備忘録
Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
This repository is deprecated and it will be shut down in the future.
See http://developer.android.com/r/tools/jcenter-end-of-service for more information.
Currently detected usages in: root project 'My Application', project ':app'
Affected Modules: app

どうやら「jcenter()が非推奨になって、じきに完全消滅するから、ビルドスクリプトから消してくれ」とのこと

AndroidStudio4.2でKotlinで新規プロジェクト作成するとエラーになる

以前にも紹介したが、また同類のエラーが発生したので備忘録
新規プロジェクトをKotlinで作成すると、以下のエラーが出てビルドできなくなった。
A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10-release-894.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.10-release-894/kotlin-gradle-plugin-1.5.10-release-894.pom
       - https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.10-release-894/kotlin-gradle-plugin-1.5.10-release-894.pom
     Required by:
         project :

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

どうやらkotlinのプラグイン「1.5.10-release-894」が見つからないらしい。。

2021年6月9日水曜日

KotlinでListの参照は[]を使うべきかgetを使うべきか

KotlinでListの参照を行うには以下二種類の方法が存在する
  • []のインデックス演算子で指定する方法
  • get()のメソッドで指定する方法

どちらを使うのが適切なのか調べてみると
言語仕様で[]を使う参照は、getに置き換えてくれてるようだ。

わざわざ[]で参照をできるように言語仕様側で調整していることになる。
ということは
言語開発者の意図として、[]を使ってほしいということ。

以上から、

Kotlin言語では[]で参照することが正しい