【问题标题】:Google Map API not Found - React Native Visual Studio Code - PC未找到 Google Map API - React Native Visual Studio Code - PC
【发布时间】:2022-12-06 09:17:52
【问题描述】:

我正在使用 React Native Visual Studio Code - PC 的 API 有问题。我知道我已将其设置为计费,因此 API 应该可以用于此目的。任何想法如何解决这个问题?我已尝试按照所有步骤进行设置,但似乎无法解决问题。我查看了文档,我相信我已经完成了所有步骤。

AndroidManifest.xml 文件:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tool_right">
    
        <uses-permission android:name="android.permission.INTERNET" />
    
        <application
          android:name=".MainApplication"
          android:label="@string/app_name"
          android:icon="@mipmap/ic_launcher"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:allowBackup="false"
          android:theme="@style/AppTheme">
          <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
            android:launchMode="singleTask"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
          </activity>
          <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    
            <!-- You will only need to add this meta-data tag, but make sure it's a child of application -->
            <meta-data
                    android:name="com.google.android.geo.API_KEY"
                    android:value="KEY Pasted here"/>
    
            <!-- You will also only need to add this uses-library tag -->
            <uses-library android:name="org.apache.http.legacy" android:required="false"/>
        </application>
    
    </manifest>
    

构建.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile
import org.apache.tools.ant.taskdefs.condition.Os

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        playServicesVersion = "17.0.0"

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.2.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:5.0.1")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

这是我得到的错误

API Error

【问题讨论】:

  • 请注意,我确实已将 API 密钥粘贴到需要的位置,但出于安全原因不想在 Stack overflow 上公开显示

标签: android react-native visual-studio-code


【解决方案1】:

在 AndroidManifest.xml 文件中,您需要指定 API 密钥:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tool_right">
  ...
  <application
    android:name=".MainApplication"
    ...
    >
         ...
         <!-- You will only need to add this meta-data tag, but make sure it's a child of application -->
         <meta-data                    
           android:name="com.google.android.geo.API_KEY"
           android:value="KEY Pasted here"/> // YOU SHOULD SET YOUR KEY HERE!!!
    
          <!-- You will also only need to add this uses-library tag -->
        </application>
    </manifest>

【讨论】:

  • 我确实将我的密钥粘贴到那里我只是不想将它发布到 stackoverflow 我仍然收到该错误@crystal_17
猜你喜欢
  • 2019-02-16
  • 1970-01-01
  • 2016-12-09
  • 1970-01-01
  • 2018-03-26
  • 1970-01-01
  • 2020-07-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多