Gradle Version Catalog への書き換えツールを作る【python】

素晴らしいツールを公開されています。

👉 takahirom/gradle-version-catalog-converter: Convert `implementation 'androidx.core:core-ktx:1.7.0'` into `androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidxCore" }` hatena-bookmark

結果は以下。

gradle-version-catalog-converter


implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
implementation 'com.google.accompanist:accompanist-swiperefresh:0.26.5-rc'


[versions]
comGoogleAccompanist = "0.17.0"

[libraries]
com-google-accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "comGoogleAccompanist" }
com-google-accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "comGoogleAccompanist" }

build.gradle
implementation libs.com.google.accompanist.systemuicontroller
implementation libs.com.google.accompanist.swiperefresh

build.gradle.kts
implementation(libs.com.google.accompanist.systemuicontroller)
implementation(libs.com.google.accompanist.swiperefresh)

高機能で便利です。

作った動機はだれもが同感できるでしょう。

ということで、

私も python の勉強がてら雑魚ツールを作ります。

クリップボードにコピーした


implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
implementation 'com.google.accompanist:accompanist-swiperefresh:0.26.5-rc'

を python スクリプト実行後すると


* source
  implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
  implementation 'com.google.accompanist:accompanist-swiperefresh:0.26.5-rc'

* gradle/libs.versions.toml
[libraries]
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version = "0.17.0"" }
accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version = "0.26.5-rc" }

* build.gradle
implementation libs.accompanist.systemuicontroller
implementation libs.accompanist.swiperefresh

と表示します。

まずは、ただそれだけです。

[versions] を設定するのもだるい implementation 単独バージョンのライブラリ用。

幼稚なスクリプトなので拡張や変更、削除しやすいです。

重複に注意です。

このへんの変換処理は、

きっと、Android Studio プラグインが登場して、

そのあと、Android Studio に取り込まれいく

のだろうと妄想しています。

それまでのつなぎで。

※ このページは gist を更新しながら更新していきます。

※ 追記: こんなのあったんですね!


👉 「⚠ This project uses Gradle Version Catalogs: this tool may not behave as expected.」→ 今現在、Gradle Version Catalog には gradle-versions-plugin が必須では? hatena-bookmark

👉 【Gradle Version Catalog】libs.versions.toml キー名の形式 camelCase vs kebab-case hatena-bookmark


【KMM】KDoctor って生きてるの?

公式にこんなの書いてるけど。

kdoctor

👉 Set up an environment | Kotlin hatena-bookmark


❯ kdoctor                       
[v] System                                           
    OS: macOS (12.6)
    CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
[v] Java
    Java (openjdk version "11.0.13" 2021-10-19)
    Location: /Users/maochanz/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app/Contents/jre/Contents/Home/bin/java
    
    JAVA_HOME=/Users/maochanz/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app/Contents/jre/Contents/Home
    
    * Note that, by default, Xcode uses Java environment returned by /usr/libexec/java_home:
      /usr/local/Cellar/openjdk@11/11.0.16.1_1/libexec/openjdk.jdk/Contents/Home
      It does not match current JAVA_HOME environment variable:
      /Users/maochanz/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app/Contents/jre/Contents/Home
          Set JAVA_HOME in XCode -> Preferences -> Locations -> Custom Paths to
          /Users/maochanz/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app/Contents/jre/Contents/Home
    
    * Note that, by default, Android Studio uses bundled JDK for Gradle tasks execution.
          Gradle JDK can be configured in Android Studio Preferences under Build, Execution, Deployment -> Build Tools -> Gradle section
    
[x] Android Studio
    * Android Studio (2021.3)
      Location: /Users/maochanz/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app
      Bundled Java: openjdk 11.0.13 2021-10-19
      Kotlin Plugin: 213-1.7.10-release-for-android-studio-AS6777.52
      Kotlin Multiplatform Mobile Plugin: not installed
          Install Kotlin Multiplatform Mobile plugin - https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile
    
[v] Xcode
    Xcode (14.0.1)
    Location: /Applications/Xcode.app
    
[x] Cocoapods
    ruby (ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-darwin21])
    
    ruby gems (3.3.11)
    
    cocoapods (1.11.3)
    
    * cocoapods-generate plugin not found
          Get cocoapods-generate from https://github.com/square/cocoapods-generate#installation
    
Failures: 2
KDoctor has diagnosed one or more problems while checking your environment.
Please check the output for problem description and possible solutions.

Failures: 2 ですけど!!

👉 Kotlin/kdoctor: Environment analysis tool hatena-bookmark

 

■ JAVA_HOME

Homebrew で OpenJDK11 最新を入れておく。

👉 Mac に Homebrew で OpenJDK11 を インストール する hatena-bookmark


export JAVA_HOME=$(/usr/libexec/java_home -v11)
export PATH="$JAVA_HOME/bin:$PATH"


❯ java -version
openjdk version "11.0.16.1" 2022-08-12
OpenJDK Runtime Environment Homebrew (build 11.0.16.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.16.1+0, mixed mode)

❯ javac -version
javac 11.0.16.1

❯ which java
/usr/local/Cellar/openjdk@11/11.0.16.1_1/libexec/openjdk.jdk/Contents/Home/bin/java

❯ which javac
/usr/local/Cellar/openjdk@11/11.0.16.1_1/libexec/openjdk.jdk/Contents/Home/bin/javac

❯ ./gradlew --version

------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------

Build time:   2022-08-05 21:17:56 UTC
Revision:     d1daa0cbf1a0103000b71484e1dbfe096e095918

Kotlin:       1.6.21
Groovy:       3.0.10
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.16.1 (Homebrew 11.0.16.1+0)
OS:           Mac OS X 12.6 x86_64

AndroidStudio 内の設定で選択肢から指定するだけでいい。

JAVA_HOME

👉 AndroidStudio 利用する Java (JDK) の選択・設定の方法 hatena-bookmark

 

■ Kotlin Multiplatform Mobile Plugin

KMM プラグインをインストールしても、ずっと


Kotlin Multiplatform Mobile Plugin: not installed

のままです。

どうやら、JetBrains ToolBox で Android Studio を使ってる場合の現象のようです。

KDoctor が KMM プラグインを見つけられないようです。

Android Studio: Cannot detect installed Kotlin Multiplatform Mobile Plugin
👉 Android Studio: Cannot detect installed Kotlin Multiplatform Mobile Plugin · Issue #25 · Kotlin/kdoctor hatena-bookmark

 

■ cocoapods-generate


~/AndroidStudioProjects/KMM main
❯ gem 'cocoapods-generate'
ERROR:  While executing gem ... (Gem::UnknownCommandError)
    Unknown command cocoapods-generate

~/AndroidStudioProjects/KMM main
❯ gem install cocoapods-generate
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ dir_s_mkdir - /usr/local/lib/ruby/gems/2.7.0/gems/cocoapods-disable-podfile-validations-0.1.1

❯ pod env --verbose
  CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update

### Stack

```
   CocoaPods : 1.11.3
        Ruby : ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-darwin21]
    RubyGems : 3.3.11
        Host : macOS 12.6 (21G115)
       Xcode : 14.0.1 (14A400)
         Git : git version 2.33.0
Ruby lib dir : /usr/local/Cellar/ruby@2.7/2.7.6_1/lib
Repositories : trunk - CDN - https://cdn.cocoapods.org/
```

### Installation Source

```
Executable Path: /usr/local/bin/pod
```

### Plugins

```
cocoapods-deintegrate : 1.0.5
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.1
cocoapods-trunk       : 1.6.0
cocoapods-try         : 1.2.0

```

Kotlin 1.7.0 以降は、


sudo gem install cocoapods

だけでいいんじゃね?

Set up an environment to work with CocoaPods

👉 CocoaPods overview and setup | Kotlin hatena-bookmark

 

■ まとめ

GitHub リポジトリを見てる限り、

KDoctor is a command-line tool that helps to set up the environment for Kotlin Multiplatform Mobile app development.
最終更新日時、

古すぎん?

生きてないのかな、KDoctor。

 

■ バージョン 0.0.5 公開 : 2022-12-04 追記

0.0.5 が公開されています。

正常に診断できるようになってます!!

--verbose で実行すると状態の詳細が分かりやすいです。


❯ kdoctor -h       
Usage: kdoctor options_list
Options: 
    --version -> print KDoctor version 
    --verbose, -v -> print extended information 
    --debug -> debug mode 
    --help, -h -> Usage info


👉 Kotlin/kdoctor: Environment analysis tool hatena-bookmark
👉 CocoaPods/CocoaPods: The Cocoa Dependency Manager. hatena-bookmark
👉 square/cocoapods-generate: A CocoaPods plugin that allows you to easily generate a workspace from a podspec. hatena-bookmark

👉 テキストアニメーションで Progress Indicator hatena-bookmark


Android OS version Market Share

👉 Android OS バージョン確認方法 (platform versions) hatena-bookmark

👉 🚀 iOS Version Market Share hatena-bookmark