macOS(64位)
Flutter SDK
下载Flutter SDk
安装包,当前最新稳定版本1.2.1。
下载完成后,解压到本地:
$ cd ~/develop
$ unzip ~/Downloads/flutter_macos_v1.0.0-stable.zip
添加flutter
工具到PATH
环境变量中:
$ export PATH=~/develop/flutter/bin:$PATH
flutter doctor
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.2 18C54, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✗] iOS toolchain - develop for iOS devices
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install with Brew:
brew install ios-deploy
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
For more info, see https://flutter.io/platform-plugins
To install:
brew install cocoapods
pod setup
[✓] Android Studio (version 3.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Community Edition (version 2018.3.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
ANR(Application Not Responding)
就是通常我们在Andrid上遇到的程序无法响应问题。
如果APP的UI线程被长时间阻塞,就会触发ANR错误,如果我们的应用在前台运行,那么系统就会弹出对话框提示用户,允许用户强制结束程序。
如果应用在后台运行,默认不会弹出对话框;当然,我们也可以在系统设置中的开发者选项中,设置允许后台允许的程序也弹出ANR对话框。
Android 中使用PathClassLoader
、DexClassLoader
等来实现类的加载,这两个类都继承自BaseDexClassLoader
,而BaseDexClassLoader
继承自ClassLoader
。
从Android官方文档中可知:PathClassLoader
用来加载系统类及已安装的应用程序的类;DexClassLoader
用来加载jar
、apk
、dex
文件中的类。
ClassLoader
使用了一种称为“双亲委托”的机制:
Java
中打开的某些资源需要我们在使用完成后主动关闭,譬如输入输出流:
final InputStream in = con.getInputStream();
final FileOutputStream os = new FileOutputStream(file);
final byte[] buf = new byte[1024 * 8];
int len;
while (-1 != (len = in.read(buf))) {
os.write(buf, 0, len);
}
os.close();
in.close();
但是我们有时候忘了主动关闭,或者逻辑有疏漏导致无法关闭,譬如以上代码在os.close()
调用时抛出异常,就会导致in.close()
无法执行到。
try-with-resources
语句在Java7
中新增了try-with-resources
语句,提供了资源关闭的新方法。
Android
模拟器使用的是arm
的CPU
架构,首先需要设置环境变量:
$ cd $WORKING_DIRECTORY/kernel/goldfish
$ export ARCH=arm
$ export CROSS_COMPILE=arm-eabi-
将交叉编译工具添加到PATH
环境变量:
$ export PATH=$WORKING_DIRECTORY/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH
AOSP
源码里不包含内核源代码,需要单独下载。不同的内核对应不同的代码仓库,下面我们使用模拟器内核代码来学习。
下载模拟器对应的内核代码:
$ cd $WORKING_DIRECTORY
$ mkdir kernel
$ cd kernel
$ git clone https://android.googlesource.com/kernel/goldfish.git
运行模拟器时,会提示:
SDL init failure, reason is: No available video device
因此需要安装SDL
库:
$ sudo apt-get install ia32-libs
在Ubuntu
中安装JDK
主要有PPA
安装和手动安装两种方式:
PPA
安装PPA
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
在工作目录运行脚本:
$ cd $WORKING_DIRECTORY
$ source build/envsetup.sh
# 或
$ . buuid/envsetup.sh