Files
Obsidian-Main/03. 專注Study/Android/Android programming.md
Awin Huang 5e4265b783 vault backup: 2022-09-30 21:53:03
Affected files:
.obsidian/workspace
03. 專注Study/Android/ADB 取得 APK 的 icon.md
03. 專注Study/Android/ADB.md
03. 專注Study/Android/AOSP.md
03. 專注Study/Android/Android programming.md
03. 專注Study/Android/AudioTrack.md
03. 專注Study/Android/Ktor.md
03. 專注Study/Android/Service.md
03. 專注Study/Android/Tools.md
03. 專注Study/Android/UI.md
03. 專注Study/C++/C++17.md
03. 專注Study/C++/Class template.md
03. 專注Study/C++/GCC.md
03. 專注Study/C++/Structured binding declaration.md
03. 專注Study/C++/for_each.md
03. 專注Study/C++/lambda.md
03. 專注Study/C++/lvalue.md
03. 專注Study/C++/move operator.md
03. 專注Study/C++/rvalue.md
03. 專注Study/C++/智慧指標.md
03. 專注Study/RxKotlin/20200207 - Study RxKotlin.md
04. Programming/COM/20210726 - COM Interface.md
04. Programming/DB/MySQL.md
04. Programming/DB/sqlite.md
04. Programming/Design Pattern.md
04. Programming/FFMPEG/00. Introduction.md
04. Programming/FFMPEG/01. Setup.md
04. Programming/FFMPEG/FFMpeg.md
04. Programming/Flask.md
04. Programming/Kotlin/class.md
04. Programming/Kotlin/run, let, with, also 和 apply.md
04. Programming/Media Foundation/20210604 - Windows media foundation.md
04. Programming/OpenCV.md
04. Programming/OpenGL.md
04. Programming/Python/argparse.ArgumentParser.md
04. Programming/Python/decorator.md
04. Programming/Python/logging.md
04. Programming/Python/opencv.md
04. Programming/Python/subprocess.md
04. Programming/Python/threading.md
04. Programming/Python/tkinter.md
04. Programming/Python/檢測工具.md
04. Programming/QT/Dropdown button.md
04. Programming/QT/QVariant.md
04. Programming/QT/Qt.md
04. Programming/UML.md
04. Programming/演算法.md
05. 資料收集/99. templates/blogHeader.md
05. 資料收集/99. templates/date.md
05. 資料收集/99. templates/front matter.md
05. 資料收集/99. templates/note.md
05. 資料收集/99. templates/table.md
05. 資料收集/99. templates/thisWeek.md
05. 資料收集/99. templates/日記.md
05. 資料收集/99. templates/讀書筆記.md
05. 資料收集/Linux/CLI/cut.md
05. 資料收集/Linux/CLI/scp.md
05. 資料收集/Linux/CLI/timedatectl.md
05. 資料收集/Linux/Programming.md
05. 資料收集/Linux/Ubuntu.md
05. 資料收集/Tool Setup/Hardware/RaspberryPi.md
05. 資料收集/Tool Setup/Software/Chrome.md
05. 資料收集/Tool Setup/Software/Obisidian.md
05. 資料收集/Tool Setup/Software/SublimeText.md
05. 資料收集/Tool Setup/Software/VirtualBox.md
05. 資料收集/Tool Setup/Software/Visual Studio Code.md
05. 資料收集/Tool Setup/Software/Windows Setup.md
05. 資料收集/Tool Setup/Software/Windows Terminal.md
05. 資料收集/Tool Setup/Software/freefilesync.md
05. 資料收集/Tool Setup/Software/vim.md
05. 資料收集/名言佳句.md
05. 資料收集/架站/Gitea.md
05. 資料收集/架站/HTTP Server/Apache.md
05. 資料收集/架站/HTTP Server/Nginx/Reverse Proxy(Layer4).md
05. 資料收集/架站/Pelican blog.md
05. 資料收集/架站/Proxmox VE.md
05. 資料收集/架站/SWAG Reverse proxy.md
05. 資料收集/架站/Storj.md
05. 資料收集/架站/Trojan.md
05. 資料收集/每週外食.md
05. 資料收集/科技/802.11.md
05. 資料收集/科技/HDR Sensor.md
05. 資料收集/科技/量子電腦.md
05. 資料收集/科技/鋰電池.md
05. 資料收集/興趣嗜好/RC/Traxxas Sledge.md
05. 資料收集/興趣嗜好/RC/好盈電變調整中立點.md
05. 資料收集/興趣嗜好/RC/差速器調教教學.md
05. 資料收集/興趣嗜好/模型/舊化作例.md
05. 資料收集/興趣嗜好/軍武/虎式.md
05. 資料收集/讀書筆記/20201201 - 學習如何學習.md
05. 資料收集/讀書筆記/20201218 - Kotlin權威2.0.md
05. 資料收集/讀書筆記/20201224 - 寫作是最好的自我投資.md
05. 資料收集/讀書筆記/20210119 - 中產悲歌.md
05. 資料收集/讀書筆記/20210220 - 最高學習法.md
05. 資料收集/讀書筆記/20210320 - 最高學以致用法.md
05. 資料收集/讀書筆記/20210406 - 精準購買.md
05. 資料收集/讀書筆記/20210723 - 高手學習.md
05. 資料收集/讀書筆記/20220526 - 深入淺出設計模式.md
05. 資料收集/讀書筆記/20220619 - 精確的力量.md
05. 資料收集/軟體工具/IPFS.md
05. 資料收集/軟體工具/MkDocs.md
05. 資料收集/軟體工具/Obsidian.md
05. 資料收集/軟體工具/docker.md
05. 資料收集/軟體工具/git/apply.md
05. 資料收集/軟體工具/git/submodule.md
05. 資料收集/軟體工具/youtube-dl.md
05. 資料收集/面試準備/技术面试最后反问面试官的话.md
2022-09-30 21:53:04 +08:00

164 lines
6.5 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## Build AOSP
### Build compile environment
1. Install Ubuntu 18.04
2. 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`
- https://source.android.com/setup/build/initializing
3. 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
```
- https://source.android.com/setup/develop#installing-repo
4. Download AOSP source
1. Create folder for AOSP
```
mkdir -p ~/codes/aosp ; cd ~/codes/aosp
```
2. Setup git
```
git config --global user.name AwinHuang ;\
git config --global user.email awinhuang@gmail.com
```
3. 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
5. Build code
```
source build/envsetup.sh ;\
lunch aosp_arm-eng ;\
make clobber ;\
make -j16
```
- `make clobber`用來刪除build資料夾
### Reference
- [GitHub - henrymorgen/android-knowledge-system: Android应用开发最强原创知识体系](https://github.com/henrymorgen/android-knowledge-system)
- [Android AOSP基础AOSP源码和内核源码下载 | BATcoder - 刘望舒](http://liuwangshu.cn/framework/aosp/2-download-aosp.html)
- [Android AOSP基础Android系统源码的整编和单编 | BATcoder - 刘望舒](http://liuwangshu.cn/framework/aosp/3-compiling-aosp.html)
## Build kernel
1. Download the code
```
mkdir -p ~/codes/kernel ;\
cd ~/codes/kernel ;\
repo init -u https://android.googlesource.com/kernel/manifest ;\
repo sync -j16
```
2. Compile
```
build/build.sh
```
- 如果遇到`Command 'java' not found, but can be installed with:`
- 依序安裝
- `sudo apt install default-jre`
- `sudo apt install openjdk-11-jre-headless`
- `sudo apt install openjdk-8-jre-headless`
- 執行 `sudo update-alternatives --config java`
- 選擇 `/usr/lib/jvm/java-11-openjdk-amd64/bin/java`
- 再次compile
- `source build/envsetup.sh`
- `mm idegen`
3. 產生android.iml和android.ipr
在source code跟目錄下執行`development/tools/idegen/idegen.sh`
### Reference
- [Android kernel源码下载与编译](https://blog.csdn.net/u010164190/article/details/106561022)
## 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
- 確認有 `kotlin-kapt` 這個plugin。
![[Pasted image 20210330102148.png]]
- [Android jetpack所有library](https://developer.android.com/jetpack/androidx/explorer)
- [Android jetpack - Lifecycle](https://developer.android.com/jetpack/androidx/releases/lifecycle)
- 從`Declaring dependencies`這區塊複製必要的module
![[Pasted image 20210330110411.png]]
```
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
```kotlin
viewModel = ViewModelProvider(this).get(GuessViewModel::class.java)
```
- Observe a live data in ViewModel
```kotlin
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.
1. 在`app/build.gradle`中加入:
```
plugins {
...
id 'kotlin-parcelize' <-- Add this
}
android {
...
buildFeatures { <-- Add this
viewBinding true
}
...
}
```
2. 在你的activity裡面
1. `import <APP_DOMAIN_NAME>.databinding.<ACTIVITY_NAME>Binding`
假如APP_DOMAIN_NAME是`com.example.testmultisectioncyclerview`ACTIVITY_NAME是`ActivityMain`,那就是:
`import com.example.testmultisectioncyclerview.databinding.ActivityMainBinding`
2. 用`lateinit`宣告一個變數變數名稱是activity的名字加上binding例如`ActivityMain`就是:
`private lateinit var activityBinding: ActivityMainBinding`
3. 在`onCreate()`中,就可以用`activityBinding`來取得view與其他元件了
```
activityBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(activityBinding.root) <-- root就是view
```
## ADB usage
- [如何透過 adb command line 指令啟動 Android App](https://kkboxsqa.wordpress.com/2014/08/20/%E5%A6%82%E4%BD%95%E9%80%8F%E9%81%8E-adb-command-line-%E6%8C%87%E4%BB%A4%E5%95%9F%E5%8B%95-android-app/)
# MISC
## 教學文
- [Android Template 小技巧 及 寫程式常見的問題](https://www.eeaseries.com/2021/01/android-template.html?m=1)
- [Jetpack Compose 基础知识](https://developers.google.com/codelabs/jetpack-compose-basics?hl=zh-cn#0)
- [一文带你了解适配Android 11分区存储](https://zhuanlan.zhihu.com/p/354632087)