对于Flutter项目,之前如果创建是不支持AndroidX的,怎么快速适配AndroidX呢?
其实很简单:
1、在/android/gradle.properties文件里面,添加两个配置
android.useAndroidX=true
android.enableJetifier=true
2、然后在将android里面support的包文件用androidx的包文件替代,下面以MainActivity为例:
package com.example.aethersharedcommunication;
import android.os.Bundle;
import org.devio.flutter.splashscreen.SplashScreen;
//导入AndroidX的包文件
import androidx.annotation.NonNull;
//这个是AndroidX之前android用的包文件
//import android.support.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, true);
super.onCreate(savedInstanceState);
}
}
网友评论