Невозможно загрузить map_view в полноэкранном режиме на Flutter - PullRequest
0 голосов
/ 30 сентября 2018

У меня проблема при попытке загрузить карту Google в полноэкранном режиме.Я проследил все документы в pub.dartland.org для map_view:

в моем AndroidManifest.xml У меня было:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

Также добавлено:

 <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your_api_key"/>
 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

Конечно, с измененным apiKey, а также:

<activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>

Я также добавляю зависимости kotlin в build.graddle.Так что теперь я могу видеть карту staticUri на устройстве, отлично, но когда я нажимаю на эту карту, чтобы получить ее в полноэкранном режиме, приложение вылетает с этой ошибкой:

D/AndroidRuntime( 4373): Shutting down VM
E/AndroidRuntime( 4373): FATAL EXCEPTION: main
E/AndroidRuntime( 4373): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apptreesoftware.mapview.MapActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment

E/AndroidRuntime( 4373): Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime( 4373): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime( 4373): Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml

Я попытался добавить:

<meta-data android:name="com.google.android.geo.API_KEY" android:value="xxxxxxxxxxxxxxx"/>

Но та же проблема, может быть, у кого-то есть идея?

РЕДАКТИРОВАТЬ: Вот мой AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="my-app"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXXXXXXXXXXXXX"/>
            <!-- <meta-data android:name="com.google.android.geo.API_KEY" android:value="XXXXXXXXXXXXXXXX"/> -->
            <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>       
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>

    </application>
</manifest>

1 Ответ

0 голосов
/ 01 октября 2018

Хорошо, вам нужно переместить метаданные карт Google за пределы тега activity, например:

        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.example.myapp">

            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
            <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

            <application
                android:name="io.flutter.app.FlutterApplication"
                android:label="my-app"
                android:icon="@mipmap/ic_launcher">


                    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXXXXXXXXXXXXX"/>
                    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> 

                <activity
                    android:name=".MainActivity"
                    android:launchMode="singleTop"
                    android:theme="@style/LaunchTheme"
                    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
                    android:hardwareAccelerated="true"
                    android:windowSoftInputMode="adjustResize">

                    <meta-data
                        android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                        android:value="true" />
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                </activity>
                <activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>

            </application>
        </manifest>

Более подробную информацию можно найти здесь:

https://developer.android.com/guide/topics/manifest/meta-data-element

Таким образом, метаданные относятся к родительскому компоненту, поэтому в этом случае вам нужны эти метаданные для всего приложения, а не только для одного действия:).

...