Affected files: .obsidian/workspace 01. 個人/02. 專注Study/20150803 - Android/Android programming.md 01. 個人/02. 專注Study/20220601 - C++/C++17 1.md 03. 資料收集/01. 架站/01. Nginx Layer4 Reverse Proxy.md 03. 資料收集/Android operating.md 03. 資料收集/DB/MySQL.md 03. 資料收集/DB/sqlite.md 03. 資料收集/NextDNS.md 03. 資料收集/SLAM.md 03. 資料收集/V2Ray.md 03. 資料收集/__templates/blogHeader.md 03. 資料收集/__templates/date.md 03. 資料收集/__templates/front matter.md 03. 資料收集/__templates/note.md 03. 資料收集/__templates/table.md 03. 資料收集/__templates/thisWeek.md 03. 資料收集/__templates/日記.md 03. 資料收集/__templates/讀書筆記.md 03. 資料收集/frp.md 03. 資料收集/youtube-dl.md 03. 資料收集/架站/02. SWAG Reverse proxy.md 03. 資料收集/架站/03. Trojan.md 03. 資料收集/架站/04. Gitea.md 03. 資料收集/架站/Nginx/Reverse Proxy(Layer4).md 03. 資料收集/模型/Traxxas Sledge.md 03. 資料收集/模型/舊化作例.md 03. 資料收集/財經.md 03. 資料收集/軍武/虎式.md 03. 資料收集/面試準備/技术面试最后反问面试官的话.md
6.5 KiB
6.5 KiB
Build AOSP
Build compile environment
- Install Ubuntu 18.04
- Install packages:
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig - Install Repo
mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo ;\ chmod a+x ~/bin/repo ;\ gpg --recv-key 8BB9AD793E8E6153AF0F9A4416530D5E920F5C65 ;\ curl https://storage.googleapis.com/git-repo-downloads/repo.asc | gpg --verify - ~/bin/repo - Download AOSP source
- Create folder for AOSP
mkdir -p ~/codes/aosp ; cd ~/codes/aosp - Setup git
git config --global user.name AwinHuang ;\ git config --global user.email awinhuang@gmail.com - Download source code
repo init -u https://android.googlesource.com/platform/manifest ;\ repo sync -j8- 如果要切換某一個特定版本可以使用
-b,例如:repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r47。 - 要知道版本tag可以查看:https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds
- 如果要切換某一個特定版本可以使用
- Create folder for AOSP
- Build code
source build/envsetup.sh ;\ lunch aosp_arm-eng ;\ make clobber ;\ make -j16make clobber用來刪除build資料夾
Reference
- GitHub - henrymorgen/android-knowledge-system: Android应用开发最强原创知识体系
- Android AOSP基础(二)AOSP源码和内核源码下载 | BATcoder - 刘望舒
- Android AOSP基础(三)Android系统源码的整编和单编 | BATcoder - 刘望舒
Build kernel
-
Download the code
mkdir -p ~/codes/kernel ;\ cd ~/codes/kernel ;\ repo init -u https://android.googlesource.com/kernel/manifest ;\ repo sync -j16 -
Compile
build/build.sh- 如果遇到
Command 'java' not found, but can be installed with:- 依序安裝
sudo apt install default-jresudo apt install openjdk-11-jre-headlesssudo apt install openjdk-8-jre-headless
- 執行
sudo update-alternatives --config java- 選擇
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
- 選擇
- 再次compile
source build/envsetup.shmm idegen
- 依序安裝
- 如果遇到
-
產生android.iml和android.ipr 在source code跟目錄下執行:
development/tools/idegen/idegen.sh
Reference
Android App programming
-
R的全名:
<PACKAGE_NAME> + .R,例如package name是com.awin.testapp,那全名是com.awin.testapp.R。 -
AndroidX = Android eXtension
-
Layout
- layout_margin: 物件與其他物件的距離
- layout_gravity: 物件在容器內的位置(靠左、靠右、置中...)
- textApperance: 字型大小
-
Extensions
- Android 4.1 沒有自動加入的extension
- 打開build.gradle,在
plugins區塊中加入:id 'kotlin-kapt' id 'kotlin-android-extensions'
-
使用ViewModel & LiveData
-
從
Declaring dependencies這區塊複製必要的module !
def lifecycle_version = "2.3.1" // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" // LiveData implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" // Annotation processor kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" -
Create a ViewModel
viewModel = ViewModelProvider(this).get(GuessViewModel::class.java) -
Observe a live data in ViewModel
viewModel.counter.observe(this, Observer { counter.setText(it.toString()) })counter這個變數是包含在ViewModel裡面的live data,我們的資料則是放在counter裡面的「value」。 所以如果要取用我們的data,則是:
viewModel.counter.value。
-
使用LiveData
val counter = MutableLiveData<Int>()
Use ViewBinding
ViewBinding is used to replace Kotlin Synthetics.
- 在
app/build.gradle中加入:plugins { ... id 'kotlin-parcelize' <-- Add this } android { ... buildFeatures { <-- Add this viewBinding true } ... } - 在你的activity裡面
import <APP_DOMAIN_NAME>.databinding.<ACTIVITY_NAME>Binding假如:APP_DOMAIN_NAME是com.example.testmultisectioncyclerview,ACTIVITY_NAME是ActivityMain,那就是:import com.example.testmultisectioncyclerview.databinding.ActivityMainBinding- 用
lateinit宣告一個變數,變數名稱是activity的名字加上binding,例如ActivityMain就是:private lateinit var activityBinding: ActivityMainBinding - 在
onCreate()中,就可以用activityBinding來取得view與其他元件了:activityBinding = ActivityMainBinding.inflate(layoutInflater) setContentView(activityBinding.root) <-- root就是view
