三歩あるけば物も忘れる

お腹のお肉がメタボックル

ユーザ用ツール

サイト用ツール


InfrastructureConstruction:Google:AndroidStudio01

20.AndroidStudioのプロジェクト作成

AndroidStudioのプロジェクト作成とFirebaseSDK環境の準備になります。

プロジェクトの作成

①「EmptyActivity」を選択し「Next」をクリック

②以下の情報を入力し「Finish」をクリック
・Name:好きな文字列(スマホ上のアプリの名前になります)
・Package Name:こちらで登録したパッケージ名と一致させます。
・Save Location:好きなパス
・Language:kotlin(kotlin or Java)
・Minimum SDK:API19 Android4.4(動作する最低レベルのSDK)

③プロジェクトが開くのでこちらでダウンロードした「google-services.json」をコピーします。

④プロジェクトレベルの「build.gradle」ファイルにbuildscriptの依存関係としてプラグインを追加します。※ハイライト行を追加

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository
    }
    dependencies {
        // Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.13'
    }
}
plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}

④モジュール(アプリレベル)の「build.gradle」ファイルに、google-servicesプラグインと、アプリで使用するFirebaseSDKを追加します。※ハイライト行を追加/編集

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
}

android {
    namespace 'mnztech.work.sns'
    compileSdk 32

    defaultConfig {
        applicationId "mnztech.work.sns"
        minSdk 16
        targetSdk 32
        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'
    }
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:31.1.1')
    implementation 'com.google.firebase:firebase-messaging-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

⑤プラグインと必要なSDKを追加したら、AndroidプロジェクトとGradleファイルを同期します。(「SyncNow」をクリックします。)

InfrastructureConstruction/Google/AndroidStudio01.txt · 最終更新: 2023/01/15 by admin