Android Weekly Notes #420

Android Weekly Issue #420

Exploring Hilt: Application Level Code Generation

解析Hilt的工作原理. 主要是@HiltAndroidApp.

Component hierarchy: https://dagger.dev/hilt/components

Going deep on Flows & Channels — Part 2

协程Flow的使用.

Never Use Foo, Bar, Baz, etc. in Software Documentation

不要在你的文档里用什么Foo, Bar, 本来看文档看得好好的, 碰上这些词就懵了.

因为这些词没有context, 不带任何附加的信息.

真正的text placeholder是: Lorem Ipsum. 没有人关心它的内容.

请在文档中使用更真实, 更有意义的例子.

Analyze Stack Traces in Android Studio

Debug的时候stack traces是可以点击的. 生产环境的stack traces其实只是纯文本.

我们也可以把这些log导入Android Studio, 官方文档.

步骤如下:

  • In the Android Studio menu bar, navigate to "Analyze > Analyze Stack Trace or Thread Dump"
  • Paste the stack trace in the window
  • Click "Normalize" to format the stack trace - in case it is not already formatted.
  • Click on "OK" to complete this.
    然后你就可以得到一个格式良好的, 带超链接的stack trace.

通常生产环境的log是被混淆的, 会需要你的mapping.txt文件来, 你的reporting工具会帮你做这件事情.

但是有时候你的log可能不是从report工具上拿到的, 就是一个混淆的stack traces怎么办呢, 你需要自己把它和mapping文件处理一下.

会需要安装一个Proguard unscrambler: https://plugins.jetbrains.com/plugin/11971-proguard-unscramble.
这个插件可以添加mapping文件.

另外, SDK还带了命令行工具来做这件事情: https://www.guardsquare.com/en/products/proguard/manual/retrace

用起来是这样:

$ANDROID_HOME/tools/proguard/bin/retrace.sh mapping.txt stacktrace.txt

Generics in Kotlin

Kotlin中的泛型.

一些相关的名字解释:

  • Type vs Class vs Subtype
  • Variance
  • Covariance
If C is a generic type with type parameter T and U is a subtype of T, then C is a subtype of C
  • Contravariance
If C is a generic type with type parameter T and U is a subtype of T, then C is a subtype of C
  • Invariance
If C is a subtype of C, then T = U
  • Type projections: 使用.
  • Star projection: 使用*号.
  • Type erasure and reified type parameters.
Reified types parameters:
Work only with functions (or extension properties that have a get() function)
Work with those functions that are declared to be inline
Advantages of using reified types parameters:
type checks with is
casts without unchecked cast warnings
assign class objects by appending ::class.java to the parameter name. For example: val a = T::class.java

Making The Most of a Rewrite

Snapchat的Android app重写.
还有个talk: https://www.droidcon.com/media-detail?video=348140440

Introducing Hephaestus

一个想改善dagger的kotlin插件.

Github: https://github.com/square/hephaestus/#hilt

通过注解自动merge module.

你可能感兴趣的:(Android Weekly Notes #420)