yandex_mapkit icon indicating copy to clipboard operation
yandex_mapkit copied to clipboard

java.lang.AssertionError: setApiKey() should be called before initialize() на grade версии больше 4.0.2 (уточнение к #206)

Open pamir72 opened this issue 2 years ago • 6 comments

Уточнение к закрытому топику #206: Если приложение собрано с debug на grade версии больше 4.0.2, то возникает ошибка при каждом четном запуске приложения: "java.lang.AssertionError: setApiKey() should be called before initialize()" судя по всему из-за какого-то незавершенного процесса в предыдущем запуске. Если приложение собрано как release, данной проблемы не возникает. Прошу помощи у уважаемого сообщества, может кто-то сталкивался с подобным ? Опробавно на com.android.tools.build:gradle:7.1.3 и ниже

pamir72 avatar Sep 13 '22 09:09 pamir72

блииииииин... на релизе всё норм?)

jjazzme avatar Sep 28 '22 12:09 jjazzme

У меня такая же проблема.

jjazzme avatar Sep 28 '22 12:09 jjazzme

блииииииин... на релизе всё норм?)

Да, на релизе все ок. Это и спасает.

pamir72 avatar Sep 30 '22 06:09 pamir72

спасибо за инфо, а то я уже голову сломал

jjazzme avatar Sep 30 '22 08:09 jjazzme

У нас, похоже, та же проблема. После перехода на flutter 3.0.0+ (пришлось и градл повысить) пошли жалобы на то, что карта зависает, вылетает или не отображается (на андроидах). Откатиться уже сейчас проблематично (( Сам по себе градл, вроде как, влиять не должен? Минимальная версия котлина? Или с чем еще может быть связано?

dumptyhumpty2014gmail avatar Oct 07 '22 11:10 dumptyhumpty2014gmail

У нас проблема только с ошибкой java.lang.AssertionError: setApiKey() should be called before initialize() и крэше приложения при каждом четном запуске. Если же приложение запустилось, то никаких проблем и зависаний с картами нет.

pamir72 avatar Oct 10 '22 04:10 pamir72

Добрый день!

На данный момент все равно не удается воспроизвести ошибку, возможно она зависит от специфики реального устройства.

DCrow avatar Oct 31 '22 09:10 DCrow

I had the same issue. My solution was creating MyApp class on the android side.

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        MapKitFactory.setApiKey("API_KEY")
    }
}

and it must be running as a primary application. It can be defined in AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.my_app">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

   <application
        android:label="auto"
        android:name=".MyApp"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Don't use MapKitFactory.setApiKey() in the MainActivity I think it should work.

Bahrom2101 avatar Jan 20 '23 15:01 Bahrom2101