관리 메뉴

웹개발자의 기지개

[안드로이드] E/Google Maps Android API: Authorization failure. 구글맵 연동시 권한 에러가 날때 본문

안드로이드

[안드로이드] E/Google Maps Android API: Authorization failure. 구글맵 연동시 권한 에러가 날때

http://portfolio.wonpaper.net 2021. 3. 25. 02:41

구글맵 연동하여 작업을 할때, 아래와 같이 권한 관련 에러 메세지를 접할 수 있다.

 

1
2
3
4
5
6
E/Google Maps Android API: Authorization failure.  Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.
E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
    Ensure that the "Google Maps Android API v2" is enabled.
    Ensure that the following Android Key exists:
        API Key: AIzaSy000000000000000000000000000
        Android Application (<cert_fingerprint>;<package_name>): 81:D1:E5:D2:E8:79:7C:F0:95:9A:21:2D:9E:1F:1F:1B:18:13:22:AF;won.test.test001
cs

권한이 제대로 적용되지 않아서 나오는 에러메세지이다.

 

[ 점검 사항 ]

 

1. 구글 클라우드 api 콘솔 사이트에서 사용자 인증 권한 확인한다.

console.cloud.google.com/apis

 

Google Cloud Platform

하나의 계정으로 모든 Google 서비스를 Google Cloud Platform을 사용하려면 로그인하세요.

accounts.google.com

 

애플리케이션 제한사항은 없음으로 간단히 하면 아주 간단히 설정을 마칠수 있다.

좀더 보안적으로 강화하고 싶으면 따로 제한사항 설정을 추가해도 된다.

 

 

2. 구글맵 기능을  클릭하여 정상적으로 사용중인지 확인한다.

1번, 2번으로 구글 api 콘솔에서의 설정은 끝났다.

 

3. 구글맵 소스 코드 키값 추가적용한다.

[ AndroidManifest.xml ]

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="won.test.test001">
 
    <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
        .....>
 
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
 
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
 
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
    </application>
 
</manifest>
cs

16라인, 17라인부분이다.

 

[ gradle.properties ] - Project Properties 소스내 추가

1
GOOGLE_MAPS_API_KEY=AIzaSy00000000000000000000
cs

 

[ build.gradle ] - apps 소스내 추가

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"
 
    defaultConfig {
        applicationId "won.test.test001"
        minSdkVersion 24
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
 
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 
        resValue "string", "google_maps_key",
                (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
    }
 
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
 
dependencies {
 
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
}
cs

        resValue "string", "google_maps_key",

                (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")

 

14, 15라인과

 

    implementation 'com.google.android.gms:play-services-maps:17.0.0'

    implementation 'com.google.android.gms:play-services-location:17.0.0'

 

41, 42라인이다.

 

Sync 클릭하고, 컴파일한 다음 실행해 보자. ^^

 

 

Comments