[Modern Android] Jetpack Compose その1


モダーン アンドロイド
Jetpack Composeを試してみたい

その過程をメモします。

まず、メモしている時点では、開発者PreviewなのでStableチャンネルでは
利用できない。

設置する。

ZipFileでダウンロードして、圧縮されたデータを元に戻もどす。

Nextを押します。

Nextを押します。

Nextを押します。
どっちを選んでも問題ないです。

Finishを押します。

終わるまで待ちます。

Finishを押します。

始めよう

Create New Projectを選択する。

Empty Compose Activityを選択する。

Finishを押します。

Buildが終わるまで待ちます。

AVD

私はAPI30のデバイスを使います。
多分基本設置される。

Gradle


android {
    defaultConfig {
        ...
        minSdkVersion 21
    }

    buildFeatures {
        // Enables Jetpack Compose for this module
        compose true
    }
    ...

    // Set both the Java and Kotlin compilers to target Java 8.

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    composeOptions {
        kotlinCompilerExtensionVersion "0.1.0-dev09"
    }
}

全てのApp Build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 29
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.dreamwalker.jetpack_compose_101"
        minSdkVersion 29
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion "${compose_version}"
        kotlinCompilerVersion '1.3.70-dev-withExperimentalGoogleExtensions-20200424'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation "androidx.ui:ui-layout:$compose_version"
    implementation "androidx.ui:ui-material:$compose_version"
    implementation "androidx.ui:ui-tooling:$compose_version"
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}