1.AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>>
2.settings.gradle
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}
3.app build.gradle
buildTypes {
debug {
signingConfig signingConfigs.debug
//x86用于模拟器
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a','x86'
}
}
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
}
4.gradle-wrapper.properties
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.5-all.zip
5.MainActivity
import android.os.Bundle;
// 重点1
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
import androidx.annotation.NonNull;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.annotation.SuppressLint;
public class MainActivity extends FlutterActivity {
private String flutterMethodChannelName = "flutterCallbackMethodChannel";
MethodChannel methodChannel_callFlutter;
@SuppressLint("NewApi")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
methodChannel_callFlutter = new
// 重点2
MethodChannel(getFlutterEngine().getDartExecutor().getBinaryMessenger(), flutterMethodChannelName);
}
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
// 重点3
super.configureFlutterEngine(flutterEngine);
GeneratedPluginRegistrant.registerWith(flutterEngine); /// 刚开始怎么运行此处都报错,将其删除再粘贴回去,居然不报错了,奇了个怪了。
}
}
6.如果出现:
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
强制改一下插件kotlin版本