1.兩個demo
最簡單最初始的demo肯定是hello world啦
flutter
import 'package:flutter/material.dart';
void main() {
runApp(
Center(
child: Text(
'Hello, world!',
textDirection: TextDirection.ltr,
),
),
);
}
android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
</LinearLayout>
package com.example.hello_world;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
2.抓取trace
2.1 flutter
主線程:PostFork+ZygoteInit+ActivityThreadMain+setCoreSettings+bindApplication(makeApplication)+activityStart(inflate)+activityResume+Choreographer#doFrame(measure+layout+draw)
RenderThread:
setSurface+DrawFrame(dequeueBuffer+flush commands+eglSwapBuffersWithDamageKHR+queueBuffer+frameComplete 1)
2.2 android
主線程:PostFork+ZygoteInit+ActivityThreadMain+setCoreSettings+bindApplication(makeApplication)+activityStart(inflate)+activityResume+Choreographer#doFrame(measure+layout+draw)
RenderThread:
setSurface+DrawFrame(dequeueBuffer+flush commands+eglSwapBuffersWithDamageKHR+queueBuffer+frameComplete 1)
3.總結
仔細對照了下Android版本的helloworld和flutter版本的hello world從perfetto來看大體流程並沒什麼區別,flutter可以認爲是定製化的Android應用,與Android交互的流程邏輯還是走的Android現有的那套,至少從perfetto trace的視角來看是這樣。