<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
manifest
태그를 통해 이 문서가 manifest에 관련된 문서라는 것을 시스템이 알 수 있음
‘xmlns:android’는 android라는 네임스페이스를 선언
‘package’의 경우 해당 어플리케이션이 속한 패키지 이름을 지정
application
애플리케이션의 정보 정의
android:allowBack
android:icon
android:label
android:roundIcon
android:supportsRtl
android:theme
activity 태그
android:name
android:exported
intent-filter 태그
package com.ex1
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)
}
}
AppCompatActivity를 상속 받아 사용
onCreate( )
액티비티가 실행될 때 시스템이 호출하는 함수
setContentView( ) 함수를 통해 화면을 출력
R.layout.activity_main을 매개변수로 지정하였으므로 res/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_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
ConstraintLayout
루트 요소인 ConstraintLayout은 자식 요소들의 위치를 상대적으로 배치
여기서는 자식인 TextView의 배치를 담당
추후 Layout에서 상세히 설명
TextView
문구를 화면에 표시하는 view
View 객체를 상속 받음
여기서는 Hello world!를 출력
안드로이드 빌드 자동화 시스템
bulid.gralde 파일을 통해 여러가지 환경 설정
프로젝트를 위한 build.gradle과 모듈을 위한 build.gradle 존재
안드로이드 스튜디오 plugin과 Gradle은 항상 버전을 맞춰줘야 함
gradle-wrapper.properties에서 Gradle 버전 확인
project structure에서 plugin 정보 확인
안드로이드 공식 홈페이지에 plugin과 gradle 버전 매칭 정보 확인
프로젝트 수준의 Gradle
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
모든 모듈을 위한 최상위 설정을 목적
plugins
모듈 수준의 Gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.ex1'
compileSdk 33
defaultConfig {
applicationId "com.ex1"
minSdk 24
targetSdk 33
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 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.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'
}
모듈에 대한 특성 정의
파일을 수정하면 Sync Now를 이용해 프로젝트에 반영해야 함