Get started with AtlasX Android
ติดตั้ง Android Studio สำหรับเขียน Kotlin
ดาวน์โหลดและติดตั้ง Android Studio https://developer.android.com/studio
ติดตั้ง Library
เมื่อทำการสร้าง Project ใหม่เรียบร้อยแล้ว การ import Library จะทำที่ Gradle Scripts ทั้งหมด ให้ไปที่ไฟล์ build.gradle ของ Project จะเห็น Code ภายใน File เป็นดังนี้
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}ในส่วนของ scope allproject จะมี repositories ที่เป็นแหล่งรวบรวม repository ที่ไว้ import Library ต่างๆเข้ามาใช้ภายใน Project นี้ ให้ทำการเพิ่ม repo maven ที่เป็นของ AtlasX เข้าไปภายใน scope ของ repositories เพื่อสามารถ import dependency ของ AtlasX Android มาใช้ได้ โดยเพิ่ม Code ดังต่อไปนี้
maven {
credentials {
username 'atlasx'
password 'at1asxu5e12'
}
url "http://157.179.28.106:8081/repository/maven-releases/"
}โดย username , password และ url ถ้ามีการเปลี่ยนแปลงในอนาคตจากทีม AtlasX ให้เรามาสามารถเปลี่ยนที่นี่ได้ทันที
ในส่วนต่อมา ให้ไปที่ File build.gradle ของ Module:app จะเห็น Code ภายใน File เป็นดังนี้
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.test.myapplication"
minSdkVersion 27
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'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}ให้ดูส่วนสุดท้ายใน scope ของ dependencies ซึ่งเป็นส่วนของการ import Library ต่างๆทั้งหมดที่เราเพิ่มเติมเข้ามาอยู่ที่นี่ทั้งหมด ดังนั้น ให้เราเพิ่ม Code dependency ด้านล่างเข้าไปใน scope ของ dependencies เพื่อเป็นการ import AtlasX Android เข้ามาใช้งานภายใน Project นี้
implementation 'com.atlasx:atlasx-android:1.0.4'เมื่อทำการเพิ่มเข้าไปแล้ว จะมีแถบสีเหลืองเล็กๆด้านบนมีปุ่มให้เรา sync now ให้ทำการกด เพื่อเป็นการ download gradle ใหม่เนื่องจากมีการเพิ่ม Code ของ build.gradle เมื่อมีการ download เสร็จสิ้น ก็ถือว่าเป็นอันเสร็จสิ้น
โดยเลข 1.0.4 เป็นเลข version ของ AtlasX Android Library (version ปัจจุบัน 1.0.4) เมื่อมีการ update version จะสามารถเปลี่ยนแปลงเลข version และ sync dependency ใหม่ได้ทันที