平凡エンジニアからの出発

一に努力、二に理想、三に積小為大。

【Android講座】第0回 趣旨説明、AndroidStudioの導入とアプリ作成



本講座の背景・目的・目標

◆背景

開発初心者がAndroidを体系的に学べる教材がなかったので、なんとかしたい。

◆目的

  • Androidアプリ開発に必要な知識を体系的に身につける
  • Step by Step実装で最初の一鍬を楽にする
  • コーディングの習慣化、そして、プログラミングを楽しむ!

◆目標

  • Androidアプリを一人で作れるようになる

※注意点
本講座で使う開発言語は、現時点でjavaになります。
今後、Androidの体系化が進んでいく中で、kotlinFlutterへの展開も行いたいと考えています。

Android Studioのインストール

◆公式
developer.android.com

アプリの作成

  1. Android Studioを起動
  2. Create New Projectを押下
  3. プロジェクトの情報を入力して、Finishを押下
    Name:AndroidLesson
    PackegeName : com.examle
    Save location : 任意
    Language : java
    Minuimum SDK : API 26 f:id:atuyan39:20210417170333p:plain:w600
  4. Empty Activityを選択して、Finishを押下

Emulatorの導入

※例)Pixel 4

  1. Toolsタブ > AVD Mangerを選択
  2. + Create Virtual Device...を押下
  3. Phone > Pixel 4を選択して、Nextを押下
  4. System Image(AndroidのVer)を選択、Downloadして、Nextを押下
  5. 名前を決めて、Finishを押下
  6. 作成したEmulatorの三角ボタンを押下して、起動

Androidの3大ファイルについて

※EmptyActivityのファイルの中身を確認

AndroidManifes

AndroidManifes.xmlを見る

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AndroidLesson">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

javaファイル

MainActivity.javaを見る

package com.example;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

resファイル

drawable

画像を管理するフォルダ

layout

画面のレイアウトを管理するフォルダ

activity_main.xmlを見る

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

values

画面の文字や色やテーマを管理するフォルダ

strings.xmlを見る

<resources>
    <string name="app_name">AndroidLesson</string>
</resources>

アプリの実行

Empty Activityを作成するとHello Worldと画面に表示するアプリが最初から作られています。

  1. Emulatorを指定して、緑三角のボタンを押下
    →アプリのインストールを行ってくれます

f:id:atuyan39:20210417164610p:plain

まとめ

  • AndroidStudioのインストールをしました。
  • 今後Androidを勉強していくアプリを作成しました。
  • Emulatorの作成とアプリが実行できるようにしました。