Flutter 01 - 安装

系统需求

  • 操作系统:macOS(64位)
  • 磁盘空间:安装完成IDE/工具等,仍需要至少700M空间
  • 工具:
    • bash
    • curl
    • git(2.x)
    • mkdir
    • rm
    • unzip
    • which

下载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.
Show More

Flutter 学习

Flutter 学习

  1. Flutter 01 - 安装
  2. Flutter 02
  3. Flutter 03
Show More

Android ANR

什么是ANR

ANR(Application Not Responding)就是通常我们在Andrid上遇到的程序无法响应问题。

如果APP的UI线程被长时间阻塞,就会触发ANR错误,如果我们的应用在前台运行,那么系统就会弹出对话框提示用户,允许用户强制结束程序。

如果应用在后台运行,默认不会弹出对话框;当然,我们也可以在系统设置中的开发者选项中,设置允许后台允许的程序也弹出ANR对话框。

ANR的触发

Show More

Android类加载机制

ClassLoader

Android 中使用PathClassLoaderDexClassLoader等来实现类的加载,这两个类都继承自BaseDexClassLoader,而BaseDexClassLoader继承自ClassLoader

从Android官方文档中可知:PathClassLoader用来加载系统类及已安装的应用程序的类;DexClassLoader用来加载jarapkdex文件中的类。

ClassLoader使用了一种称为“双亲委托”的机制:

Show More

Java 之 try-with-resources

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语句,提供了资源关闭的新方法。

Show More

Android2.3源码学习06 -- 编译linux内核源代码

Android模拟器使用的是armCPU架构,首先需要设置环境变量:

$ 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
Show More

Android2.3源码学习05 -- 下载内核源码

AOSP源码里不包含内核源代码,需要单独下载。不同的内核对应不同的代码仓库,下面我们使用模拟器内核代码来学习。

下载模拟器对应的内核代码:

$ cd $WORKING_DIRECTORY
$ mkdir kernel
$ cd kernel
$ git clone https://android.googlesource.com/kernel/goldfish.git
Show More

Android2.3源码学习04 -- 运行模拟器

安装 SDL 库

运行模拟器时,会提示:

SDL init failure, reason is: No available video device

因此需要安装SDL库:

$ sudo apt-get install ia32-libs
Show More

Ubuntu中安装JDK

Ubuntu中安装JDK主要有PPA安装和手动安装两种方式:

PPA安装

添加PPA

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
Show More

Android2.3源码学习03 -- 编译源码

设置环境

在工作目录运行脚本:

$ cd $WORKING_DIRECTORY
$ source build/envsetup.sh
# 或
$ . buuid/envsetup.sh
Show More

—  我的个人空间 |   —