将yandex mapkit添加到项目时出现致命异常:
清空Flutter项目。在pubspec.yaml.中添加yandex_mapkit:^3.1.1
初始化yandex_mapkit,通过pub.dev指令:https://pub.dev/packages/yandex_mapkit
运行main.dart:时
在调试模式下在IA Emulator上的AOSP上启动lib\main.art。。。正在运行Gradle任务"assemblyDebug"…√已建成build\app\outputs\flutter apk\app-debug.apk.安装build\app\outputs\flutter apk\app.apk…E/AndroidRuntime(17681(:致命异常:主E/AndroidRuntime(17681(:进程:com.example.test_yandex_map,PID:17681 E/AndroidRuntime(17681(:java.lang.RuntimeException:无法实例化活动组件信息{com.example.test_yandex_map/com.example.ttest_yandex.map.MainActivity}:java.lang.ClassNotFoundException:找不到类"com.example.test_yandex_map.MainActivity"在路径上:DexPathList[[zip文件"data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/base.apk"],nativeLibrary目录=[/data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/lib/x86,/data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/base.apk/lib/x86,/system/lib]]E/AndroidRuntime(17681(:在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843(E/AndroidRuntime(17681(:位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048(E/AndroidRuntime(17681(:位于android.app.servertransaction.LaunchActivityItem.exexecute(LaunchActivityItem.java:78(E/AndroidRuntime(17681(:位于android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108(E/AndroidRuntime(17681(:位于android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68(E/AndroidRuntime(17681(:位于android.app.ActivityThread$H.handleMessage(ActivityThreads.java:1808(E/AndroidRuntime(17681(:位于android.os.Handler.dispatchMessage(Handler.java:106(E/AndroidRuntime(17681(:在android.os.Looper.loop(Looper.java:193(E/AndroidRuntime(17681(:位于android.app.ActivityThread.main(ActivityThreads.java:6669(E/AndroidRuntime(17681(:位于java.lang.reflect.Method.ioke(Native方法(E/AndroidRuntime(17681(:在com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493(E/AndroidRuntime(17681(:位于com.android.internal.os.ZygoteInit.main(ZygoteNit.java:858(E/AndroidRuntime(17681(:由java.lang.ClassNotFoundException引起:找不到班级"com.example.test_yandex_map.MainActivity"在路径上:DexPathList[[zip文件"data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/base.apk"],nativeLibrary目录=[/data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/lib/x86,/data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/base.apk/lib/x86,/system/lib]]E/AndroidRuntime(17681(:在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134(E/AndroidRuntime(17681(:位于java.lang.ClassLoader.loadClass(ClassLoader.java:379(E/AndroidRuntime(17681(:位于java.lang.ClassLoader.loadClass(ClassLoader.java:312(E/AndroidRuntime(17681(:位于android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69(E/AndroidRuntime(17681(:位于androidx.core.app.CoreComponentFactory.instantiateActivity(核心组件工厂.java:45(E/AndroidRuntime(17681(:位于android.app.Instrumentation.newActivity(Instrumentation.java:1215(E/AndroidRuntime(17681(:位于android.app.ActivityThread.performLaunchActivity(ActivityThreads.java:2831(E/AndroidRuntime(17681(:。。。11个
Flutter医生:
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.18363.1556], locale ru-RU)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.7)
[√] Android Studio (version 2021.2)
[√] Connected device (4 available)
[√] HTTP Host Availability
•未发现任何问题!
文件已修改,由于yandex映射初始化:
src/build.gradle
SDK<21抛出异常,所以我将其设置为21。
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.test_yandex_map"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.yandex.android:maps.mobile:4.2.0-full'
}
main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test_yandex_map">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
科特林//主要活动
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
import com.yandex.mapkit.MapKitFactory
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
MapKitFactory.setLocale("YOUR_LOCALE") // Your preferred language. Not required, defaults to system language
MapKitFactory.setApiKey("YOUR_API_KEY") // Your generated API key
super.configureFlutterEngine(flutterEngine)
}
}
我只是偶然地删除了这个:科特林//主要活动.kt
package com.example.my_app_name