Fatal Exception on adding yandex mapkit to project:
Empty Flutter project. Add yandex_mapkit: ^3.1.1 in pubspec.yaml.
Init yandex_mapkit, by pub.dev instuction: https://pub.dev/packages/yandex_mapkit
When run main.dart:
Launching lib\main.dart on AOSP on IA Emulator in debug mode... Running Gradle task 'assembleDebug'... √ Built build\app\outputs\flutter-apk\app-debug.apk. Installing build\app\outputs\flutter-apk\app.apk... E/AndroidRuntime(17681): FATAL EXCEPTION: main E/AndroidRuntime(17681): Process: com.example.test_yandex_map, PID: 17681 E/AndroidRuntime(17681): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test_yandex_map/com.example.test_yandex_map.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.test_yandex_map.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/base.apk"],nativeLibraryDirectories=[/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): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843) E/AndroidRuntime(17681): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) E/AndroidRuntime(17681): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) E/AndroidRuntime(17681): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) E/AndroidRuntime(17681): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) E/AndroidRuntime(17681): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) E/AndroidRuntime(17681): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(17681): at android.os.Looper.loop(Looper.java:193) E/AndroidRuntime(17681): at android.app.ActivityThread.main(ActivityThread.java:6669) E/AndroidRuntime(17681): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(17681): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/AndroidRuntime(17681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) E/AndroidRuntime(17681): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.test_yandex_map.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.test_yandex_map-dpNzlkJVGKi1iBVn_qHZTA==/base.apk"],nativeLibraryDirectories=[/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): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) E/AndroidRuntime(17681): at java.lang.ClassLoader.loadClass(ClassLoader.java:379) E/AndroidRuntime(17681): at java.lang.ClassLoader.loadClass(ClassLoader.java:312) E/AndroidRuntime(17681): at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69) E/AndroidRuntime(17681): at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45) E/AndroidRuntime(17681): at android.app.Instrumentation.newActivity(Instrumentation.java:1215) E/AndroidRuntime(17681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831) E/AndroidRuntime(17681): ... 11 more
Flutter doctor:
[√] 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
• No issues found!
Files modified, due yandex maps initialization:
...src/build.gradle
SDK < 21 throws exception, so I set it to 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
...kotlin/.../MainActivity
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)
}
}
I just accedently remove this: kotlin/.../MainActivity.kt
package com.example.my_app_name