~~NOCACHE~~ ## 20.AndroidStudioのプロジェクト作成 AndroidStudioのプロジェクト作成とFirebaseSDK環境の準備になります。 ### プロジェクトの作成 ①「EmptyActivity」を選択し「Next」をクリック {{:InfrastructureConstruction:Google:pasted:20230115-013057.png?direct 400x0}} ②以下の情報を入力し「Finish」をクリック ・Name:好きな文字列(スマホ上のアプリの名前になります) ・Package Name:[[InfrastructureConstruction:Google:Firebase01#アプリケーションの作成|こちら]]で登録したパッケージ名と一致させます。 ・Save Location:好きなパス ・Language:kotlin(kotlin or Java) ・Minimum SDK:API19 Android4.4(動作する最低レベルのSDK) {{:InfrastructureConstruction:Google:pasted:20230115-013437.png?direct 400x0}} ③プロジェクトが開くので[[InfrastructureConstruction:Google:Firebase01#アプリケーションの作成|こちら]]でダウンロードした「google-services.json」をコピーします。 {{:InfrastructureConstruction:Google:pasted:20230115-020713.png?direct 400x0}} ④プロジェクトレベルの「build.gradle」ファイルにbuildscriptの依存関係としてプラグインを追加します。※ハイライト行を追加 {{:InfrastructureConstruction:Google:pasted:20230115-022041.png?direct 300x0}} // 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を追加します。※ハイライト行を追加/編集 {{:InfrastructureConstruction:Google:pasted:20230115-022255.png?direct 300x0}} 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:pasted:20230115-023044.png?direct 600x0}} {{tag>AndroidStudio}}