【Android Studio】Google vs JetBrains - build 時 に利用する JDK の選択

外野から、さらっと見ていると、


- IDEA Intellij は JetBraains 製。
- Android Studio は Google 製。
- Android Studio は IDEA Intellij を利用してできている。

と認識しています。

それぞれ公式で以下の内容。


ん?

一般的、標準的な Android アプリ開発の IDE といえば Android Studio だと思うのですが、開発したソースコードの build に利用する JDK は、「Android Studio にバンドルされている JDK」でいいんですよね?

Android Studio 設定画面からは、どちらでも選択はできます。

今現在、私のパソコンにインストールされてる JDK は、Android Studio バンドル版を含めて OpenJDK 11.0.15 と 11.0.18 と 19.0.1 の3つ。

Android Studio 設定画面もそれは認識しています。

【Android Studio】Google vs JetBrains - build 時 に利用する JDK の選択
19 系はないとして、やはり embedded JDK 11.0.15 が妥当ですよね。

少し、混乱してました。

特に理由がなければこれで良し、とな。

👉 Android Studio Electric Eel | 2022.1.1 の JDK11 設定 hatena-bookmark
👉 【macOS】Android Studio 埋め込み JDK の Home のパスを取得する hatena-bookmark
👉 AndroidStudio 利用する Java (JDK) の選択・設定の方法 hatena-bookmark
👉 macOS (Intel) + Homebrew の JDK の現状を確認する hatena-bookmark
👉 【Android Studio】Settings - Build Tools - Gradle JDK の選択肢がゴミだらけで意味不明の場合 hatena-bookmark


Android Studio Electric Eel おすすめの Gradle Plugin と Gradle のバージョン

2023-01-20 現在。

 

■ Android Studio


Electric Eel | 2022.1.1
AI-221.6008.13.2211.9477386

 

■ Android Gradle Plugin


7.4.0


com.android.tools.build.gradle:7.4.0
↓
com.android.application:7.4.0
com.android.library:7.4.0

👉 【Plugin DSL】「com.android.tools.build:gradle」の記述は不要? hatena-bookmark

 

■ Gradle


7.6

 

■ 参考

👉 Android Studio Dolphin おすすめの Gradle Plugin と Gradle のバージョン hatena-bookmark



【Python】2022年 = 令和4年 = 平成34年 = 昭和97年 というような 西暦 - 元号 対照表

役所関連の書類とか整理していると、

平成とか昭和の書類がでてきて、

何年前の書類なのか、

時系列が全くわからん。

いちいちネットで調べるのだるいので。

Python の訓練です。

 

■ 確認

変換の基準を確認する。


昭和 S01.12.25 (1926-12-25) - S64.01.07 (1989-01-07)
平成 H01.01.08 (1989-01-08) - H31.04.30 (2019-04-30)
令和 R01.05.01 (2019-05-01) -

👉 元号 - Wikipedia hatena-bookmark

 

■ コード

対照表がほしい。


#!/usr/bin/env python

import datetime
from tabulate import tabulate

d = []

for a in range(1989, datetime.date.today().year + 1)[::-1]:

  r = a - 2018
  h = a - 1988
  s = a - 1925

  d.append([a, r if r > 0 else '', f'({h})' if r > 1 else h, f'({s})' if h > 1 else s])

print(tabulate(d, headers=('ad', 'reiwa', 'heisei', 'showa'), stralign='right'))

「元」とかは無視。

 

■ まとめ

中国、朝鮮、台湾、日本、ベトナムくらいですか。

微妙です。

👉 日本は役所や企業での元号の使用をやめるべきだと思いますか? - Quora hatena-bookmark


Gradle Version Catalog 見づらい TOML インラインテーブル を別フォーマットで表示してみる

すべてインラインテーブルで記述したもののなんか見づらい。

なんかいい方法はないかな、と模索。

Python 3.11 で同梱された tomllib を使って別フォーマットで整形して表示してみます。

👉 How to Use Python 3.11's New TOML Parser, tomllib - The Invent with Python Blog hatena-bookmark

記事にするには大きすぎるので [plugins] だけで。


import tomllib
import pprint
import json
import yaml
import pandas
import tabulate

file = "/path/to/libs.versions.toml"

with open(file, "rb") as fp:
  data = tomllib.load(fp)["plugins"] # only plugins

# raw (dic)
print(data)

# pretty print
pprint.pprint(data)

# json
print(json.dumps(data, indent=2))

# yaml
print(yaml.dump(data))

# pandas + tabulate
df = pandas.DataFrame.from_dict(data, orient='index')
print(tabulate.tabulate(df, headers='keys'))

以下、出力結果。

 

■ raw (dic)


{'android-application': {'id': 'com.android.application', 'version': {'ref': 'agp'}}, 'kotlin-android': {'id': 'org.jetbrains.kotlin.android', 'version': {'ref': 'kotlin'}}, 'kotlin-kapt': {'id': 'org.jetbrains.kotlin.kapt', 'version': {'ref': 'kotlin'}}, 'kotlin-plugin-serialization': {'id': 'org.jetbrains.kotlin.plugin.serialization', 'version': {'ref': 'kotlin'}}, 'hilt': {'id': 'com.google.dagger.hilt.android', 'version': {'ref': 'hilt'}}, 'sqldelight': {'id': 'app.cash.sqldelight', 'version': {'ref': 'sqldelight'}}, 'google-services': {'id': 'com.google.gms.google-services', 'version': {'ref': 'google-services'}}, 'firebase-crashlytics': {'id': 'com.google.firebase.crashlytics', 'version': {'ref': 'firebase-crashlytics'}}, 'ben-manes-versions': {'id': 'com.github.ben-manes.versions', 'version': '0.44.0'}}

 

■ pretty print


{'android-application': {'id': 'com.android.application',
                         'version': {'ref': 'agp'}},
 'ben-manes-versions': {'id': 'com.github.ben-manes.versions',
                        'version': '0.44.0'},
 'firebase-crashlytics': {'id': 'com.google.firebase.crashlytics',
                          'version': {'ref': 'firebase-crashlytics'}},
 'google-services': {'id': 'com.google.gms.google-services',
                     'version': {'ref': 'google-services'}},
 'hilt': {'id': 'com.google.dagger.hilt.android', 'version': {'ref': 'hilt'}},
 'kotlin-android': {'id': 'org.jetbrains.kotlin.android',
                    'version': {'ref': 'kotlin'}},
 'kotlin-kapt': {'id': 'org.jetbrains.kotlin.kapt',
                 'version': {'ref': 'kotlin'}},
 'kotlin-plugin-serialization': {'id': 'org.jetbrains.kotlin.plugin.serialization',
                                 'version': {'ref': 'kotlin'}},
 'sqldelight': {'id': 'app.cash.sqldelight', 'version': {'ref': 'sqldelight'}}}

 

■ json


{
  "android-application": {
    "id": "com.android.application",
    "version": {
      "ref": "agp"
    }
  },
  "kotlin-android": {
    "id": "org.jetbrains.kotlin.android",
    "version": {
      "ref": "kotlin"
    }
  },
  "kotlin-kapt": {
    "id": "org.jetbrains.kotlin.kapt",
    "version": {
      "ref": "kotlin"
    }
  },
  "kotlin-plugin-serialization": {
    "id": "org.jetbrains.kotlin.plugin.serialization",
    "version": {
      "ref": "kotlin"
    }
  },
  "hilt": {
    "id": "com.google.dagger.hilt.android",
    "version": {
      "ref": "hilt"
    }
  },
  "sqldelight": {
    "id": "app.cash.sqldelight",
    "version": {
      "ref": "sqldelight"
    }
  },
  "google-services": {
    "id": "com.google.gms.google-services",
    "version": {
      "ref": "google-services"
    }
  },
  "firebase-crashlytics": {
    "id": "com.google.firebase.crashlytics",
    "version": {
      "ref": "firebase-crashlytics"
    }
  },
  "ben-manes-versions": {
    "id": "com.github.ben-manes.versions",
    "version": "0.44.0"
  }
}

 

■ yaml


android-application:
  id: com.android.application
  version:
    ref: agp
ben-manes-versions:
  id: com.github.ben-manes.versions
  version: 0.44.0
firebase-crashlytics:
  id: com.google.firebase.crashlytics
  version:
    ref: firebase-crashlytics
google-services:
  id: com.google.gms.google-services
  version:
    ref: google-services
hilt:
  id: com.google.dagger.hilt.android
  version:
    ref: hilt
kotlin-android:
  id: org.jetbrains.kotlin.android
  version:
    ref: kotlin
kotlin-kapt:
  id: org.jetbrains.kotlin.kapt
  version:
    ref: kotlin
kotlin-plugin-serialization:
  id: org.jetbrains.kotlin.plugin.serialization
  version:
    ref: kotlin
sqldelight:
  id: app.cash.sqldelight
  version:
    ref: sqldelight

 

■ pandas + tabulate


                             id                                         version
---------------------------  -----------------------------------------  -------------------------------
android-application          com.android.application                    {'ref': 'agp'}
kotlin-android               org.jetbrains.kotlin.android               {'ref': 'kotlin'}
kotlin-kapt                  org.jetbrains.kotlin.kapt                  {'ref': 'kotlin'}
kotlin-plugin-serialization  org.jetbrains.kotlin.plugin.serialization  {'ref': 'kotlin'}
hilt                         com.google.dagger.hilt.android             {'ref': 'hilt'}
sqldelight                   app.cash.sqldelight                        {'ref': 'sqldelight'}
google-services              com.google.gms.google-services             {'ref': 'google-services'}
firebase-crashlytics         com.google.firebase.crashlytics            {'ref': 'firebase-crashlytics'}
ben-manes-versions           com.github.ben-manes.versions              0.44.0

 

■ まとめ

Python って、簡単にいろんなことできるんですね!


【Android Studio】Gradle Version Catalog「Live Template」を使って インライン・テーブル に瞬時に書き換える

だるいですよね、インラインテーブル記述。


name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }
animal = { type.name = "pug" }

👉 TOML: 日本語 v0.5.0 hatena-bookmark

Android Studio でも

Graadle Version Catalog で、最初は、こんな記述でも


[plugins]
android-material = "com.google.android.material:material:1.8.0-alpha02"

やがて、


[plugins]
android-material = { module = "com.google.android.material:material", version = "1.8.0-alpha02" }

となり


[versions]
android-material = "1.8.0-alpha02"

[plugins]
android-material = { module = "com.google.android.material:material", version.ref = "android-material" }

というふうに変わっていきます。

大量にやってるのも地味にだるい。

Live Templete を使って書き換えます。


Preferences

  ↓

Live Templates

から作っていきます。

ここマクロたちは、思ったより使いづらいものが多い。

live template macro

👉 intellij-community/platform/lang-impl/src/com/intellij/codeInsight/template/macro at master · JetBrains/intellij-community hatena-bookmark

割と使える Groovy のマクロ。

groovyScript(, [arg, ...])

Executes the Groovy script passed as a string.

The first argument is a string with either the text of the script or the path to the file that contains the script. The function passes other optional arguments to the script as values for _1, _2, _3, ..., _n variables. Also, you can access the current editor from inside the script using the _editor variable.

The following example shows a groovyScript() function that splits the selected text into words and displays them as a numbered list:


groovyScript("def result = ''; _1.split().eachWithIndex { item, index -> result = result + index.next() + '. ' + item + System.lineSeparator() }; return result;", SELECTION);

👉 Edit Template Variables dialog | IntelliJ IDEA hatena-bookmark

以下の感じで設定して4つのテンプレートを記述しました。

どれも似たような記述なので、一つだけ貼っておきます。

使い回せます。

使い方は、該当文字列をコピーしてから、Abbreviation を入力で、テンプレートを吐き出しながらキーなどを編集してください。

結果。

toml live template

キーの編集に連携されて関連記述が編集されるのがいいところでしょうか。

けどまあ、Android Studio 本体の機能更新が待たれるところですが。

 

🙆 追記

複数行一括のほうがいいので以下の方法を実際は使っています。