DEV Community

kaede
kaede

Posted on • Edited on

Android 基礎 -- Part 00 Android Studio のインストールと Hello World

why

Kotlin のスキルを腐らせないため。


Android Studio のインストール

Kotlin Web で開発するときの IntelliJ だと解釈している。

https://bsblog.casareal.co.jp/archives/5263

(IntelliJ でも使えるが、アプリ用ではないので使いにくそう)

最新版を Mac にインストールする

Image description

Apple Chip の Android Studio Dolphin
2021.3.1 Patch 1 を DL

Applications フォルダーに移動

Image description

  • Android の Software Dev Kit
  • Java の Dev Kit ( Runtime Env を含む )
  • その他付属品

これらを起動時にインストールする。

Image description

いろいろ依存関係を入れて

Image description

プロジェクトを作れる状態になった


Hello World のプロジェクトを作成

https://akira-watson.com/android/helloworld.html

この記事を参考にする。公式は動画だったので。

New Project -> Empty Activity を選択して

Image description

プロジェクト名を HelloAndroid
SDK を Android 12.0

で作成する


内部の MainActivity.kt のコードを見る

Image description

UI は IntelliJ と同じに見える。
しかし、コードを見ると Springboot と違い、起点となる main が見つからない。

Main として最初に動きそうな MainActivity.kt を見てみると

package com.example.helloandroid

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}
Enter fullscreen mode Exit fullscreen mode

activitiy_main を使っているようだ。
activitiy_main.xml は res/layout にあり

Image description

ファイルを開くと UI で表示されてしまう

Image description

右下の Common Attributes のところで中身を
Hello Android! に変更できた


ビルドしてエミュレーターを起動する。

Image description

お馴染みのトンカチボタンを押して、三角ボタンでスタートさせる。
するとなんと Android の電源が入り、選択していたアプリが自動で起動する。

Image description

これで変更した文言で、アプリを起動することができた。


vim の有効化

https://ikenox.info/blog/ideavim-introduction/

Settings (旧 Preferences ) / Plugins /
ここからインストールできる。

Image description

https://dev.to/kaede_io/intellij-chu-qi-she-ding-tocao-zuo-3003

.vimrc は IntelliJ の記事と同じく、~/userName/.idealVimrc
に書けば適用される。


今後

XML での UI 表示が酷く書きづらいので、
React っぽく宣言的に書ける Jetpack Compose というフレームワークを導入してみる。

https://dev.to/vtsen/simple-rest-api-android-app-in-kotlin-various-http-client-library-implementations-11i2

この記事のように REST API を叩きたい

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay