Google Maps Android API v2 인증 실패
내 단계 :
- debug.keystore에서 SHA1 코드를 받았습니다.
- Google API 콘솔에서 앱 만들기
- 활성화 된 Google지도 API v2
- 입력 SHA1; my.package.name
- API 키 얻기
AndroidManifest 파일 생성 :
<permission android:name="my.package.name.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission android:name="my.package.name.permission.MAPS_RECEIVE"/> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:hardwareAccelerated="true"> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MY_API_KEY_HERE" /> <activity android:name="MyActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
생성 된 레이아웃
- libs에 "google-play-services.jar"를 넣어
컴파일 후 충돌이 발생했습니다.
ERROR/AndroidRuntime(10182): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4716)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
at android.app.Activity.setContentView(Activity.java:1881)
at com.example.gm2.MyActivity.onCreate(MyActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
그 후 레이아웃을 다음과 같이 변경했습니다.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
MyActivity를 다음으로 변경했습니다.
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.map, MapFragment.newInstance());
transaction.commit();
그 결과 응용 프로그램이 시작되었지만지도가 보이지 않았습니다.
콘솔 로그 :
ERROR/Google Maps Android API(10369): Authorization failure.
단계 :
- 기기에 Google Play 서비스 APK가 있는지 확인
- Google Play 서비스 버전을 설치합니다. 2 이상
- https://code.google.com/apis/console/ 에서 프로젝트를 만들려면
- "Google Maps Android API v2"를 활성화하려면
- API 콘솔 에서 프로젝트 ( NOW, YOU WRITE SHA1; your.app.package.name )에 SHA1을 등록 하고 API KEY를 얻으려면
- ANDROID_SDK_DIR / extras / google / google_play_services / libproject / google-play-services_lib 디렉토리를 프로젝트의 루트에 복사하려면
- YOUR_PROJECT / project.properties에 다음 줄을 추가하려면
android.library.reference.1=google-play-services_lib
- 다음에 다음 줄을 추가하려면
YOUR_PROJECT/proguard-project.txt
.
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
이제 Android 용 Google Map API V2를 사용하여 나만의 Google지도 앱을 만들 준비가되었습니다.
최소 SDK = 8로 애플리케이션을 생성하는 경우 MapFragment 대신 Android 지원 라이브러리 v4 + SupportMapFragment를 사용하세요.
또한이 게시물을 확인하십시오 : Google Map Android Api V2 샘플 코드가 작동하지 않습니다 . 올바른 단계를 수행했다고 확신하는 경우 두 번째 답변을 따르십시오. 인증이 어딘가에 캐시되고 응용 프로그램을 수동으로 제거하십시오 ( 일반 응용 프로그램) 그런 다음 프로젝트를 다시 "실행"합니다.
API를 작동시키는 데 많은 시간을 낭비했기 때문에 Map API v2에 대한 단계별 유효성 검사를 시도하겠습니다.
1 단계 : API 키 신청
Google API 콘솔에 익숙하지 않은 경우 위의 Rusfearuth에 대한 아주 좋은 답변을 읽으십시오.
2 단계 : SHA Hash를 확인합니다 (이 경우 eclipse의 디버그 키를 사용합니다).
Windows 시스템에서 명령 프롬프트에서 사용자 디렉토리로 이동했습니다.
C:\Users\you>keytool -list -alias androiddebugkey -keystore .android\debug.keyst
ore -storepass android -keypass android
다음과 같은 내용이 표시됩니다.
androiddebugkey, 15.10.2012, PrivateKeyEntry,
Zertifikat-Fingerprint (SHA1): 66:XX:47:XX:1E:XX:FE:XX:DE:XX:EF:XX:98:XX:83:XX:9A:XX:23:A6
그런 다음 맵 활동의 패키지 이름 (예 : com.example.mypackagename)을 확인합니다.
이것을 결합하고 Google API 콘솔의 설정으로 확인하십시오.
66:XX:47:XX:1E:XX:FE:XX:DE:XX:EF:XX:98:XX:83:XX:9A:XX:23:A6;com.example.mypackagename
API 키를 얻는 위치 :
AZzaSyDhkhNotUseFullKey49ylKD2bw1HM
3 단계. 매니페스트 메타 데이터
메타 데이터가 있고 올바른 키를 포함하는지 확인하십시오. 앱을 출시하는 경우 다른 키가 필요합니다.
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AZzaSyDhkhNotUseFullKey49ylKD2bw1HM" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
4 단계. 매니페스트 기능 :
지도 API에는 몇 가지 그래픽 지원이 필요하므로이 항목이 필요합니다.
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
걱정하지 마세요. 기기의 99.7 %가이를 지원합니다.
5 단계. 매니페스트 라이브러리 :
Google 라이브러리를 추가하십시오.
<uses-library
android:name="com.google.android.maps"
android:required="false" /> // This is required if you want your app to start in the emulator. I set it to false also if map is not an essential part of the application.
6 단계. 매니페스트 권한 :
패키지 이름을 두 번 확인하십시오. com.example.yourpackage
<permission
android:name="com.example.yourpackage.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.yourpackage.permission.MAPS_RECEIVE" />
다음 권한을 추가하십시오.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
다음 권한은 선택 사항이며지도 만 표시하는 경우에는 필요하지 않습니다. 그것들을 사용하지 마십시오.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
7 단계. 레이아웃에지도 조각을 포함합니다.
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraTargetLat="47.621120"
map:cameraTargetLng="-122.349594"
map:cameraZoom="15" />
2.x Android 버전으로 릴리스하는 경우 활동에 지원을 추가해야합니다.
import android.support.v4.app.FragmentActivity;
For the map: entries to work include
xmlns:map="http://schemas.android.com/apk/res-auto"
in your activity layout (e.g. LinearLayout).
In my case I have to clean the project each time I change something in the layout. Seems to be a bug.
Step 8: Use Eclipse - Project - Clean.
Enjoy!
You need to use the library project located at: ANDROID-SDK-DIRECTORY/extras/google/google_play_services/libproject
This will fix your first issue.
I'm not sure about your second, but it may be a side effect of the first. I am still trying to get the map working in my own app :)
Today I faced with this problem. I used Android Studio 2.1.3, windows 10. While debugging it works fine, but if I update to release mode it does not work. I cleared all proguard conditions, updated, but this was not solution.
The solution is related with project structure. The google_maps_api.xml file was different between app\src\debug\res and app\src\release\res. I did manual copy paste from debug to release folder.
Now it works.
I followed most, if not all, of Gunnar Bernstein's suggestions mentioned above and it still didn't work. However, it started to work after I followed his suggestions AND the following:
I created a new MapActivity by using Android Studio's right click list of options: New -> Google -> Google Maps Activity
I then opened the google_maps_api.xml file that automatically gets generated and used the stated link to create a new API KEY. I did all the steps and saved my new key under my current project. I then removed my old registered API KEY as it was no longer required.
Under the Manifest file I replaced the old API KEY value with the string shortcut created by this new XML file:
android:value="@string/google_maps_key
", instead of stating the KEY directly.Finally, remove the new MapActivity, but keep the xml file that was created in that process.
Note: By creating the API KEY in this way the Restrictions column, under Credentials, now stated "Android apps". Earlier, when it didn't work the column stated "Android apps, 1 API" or something similar. I do not know if this makes a difference or not.
Note: No, that just means that I do not have a specific API selected for this API key (Console -> API key -> Key restrictions -> API restrictions).
Note: It looks like the meta-data tag under the Manifest file:
android:name="com.google.android.maps.v2.API_KEY
has been replaced by:
android:name="com.google.android.geo.API_KEY"
I guess that both can be used but it's better from the start using the latter.
Note: The value stated, in the build.gradle file, under android -> defaultConfig -> applicationId has to match the Package name text under the Credentials page.
Just Add this into your manifest file:
**<uses-library android:name="com.google.android.maps" />**
For Example...
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".California"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And please update your google play service lib...Go to Window -> Android sdk manager->update google play service...installed it..delete old one and keep this one. Take this from ANDROID-SDK-DIRECTORY/extras/google/google_play_services/
Thanks..Please vote up
I solved this error by checking the package name in manifest and app build.gradle
.
In manifest:
I am using a package name as:
com.app.triapp
In app build.gradle:
defaultConfig {
applicationId "com.app.live"
}
After changed to com.app.triapp
in build.gradle
, solved my issue.
I am migrating from V1 to V2 of Google Maps. I was getting this failure trying to run the app via Eclipse. The root cause for me was using my release certificate keystore rather than the Android debug keystore which is what gets used when you run it via Eclipse. The following command (OSX/Linux) will get you the SHA1 key of the debug keystore:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
If you are using Windows 7 instead, you would use this command:
keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
It is probably best to uninstall your app completely from your device before trying with a new key as Android caches the security credentials.
"java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable"
A had this error too, you need to: File -> import -> Existing Android Code Into Workspace -> Browse -> Android sdks -> extras -> google -> google_play_services -> lib_project -> google_play_services_lib and OK. Check the project and Finish.
The project goes to Package Explorer. Now go to your project (with error) -> properties -> Android and in Library click Add... the google_play_services_lib should be there! add and try again :)
I had same issue but it turned out that it was because I created two different map API keys with same SHA-1 fingerprint with nearly similar package name com.bla.bla
and the other com.bla.bla.something
.
I had the exact same issue and i just needed to set the SDK for the library project of the MapsApiV2 to Android 2.3.3 (API lvl 10)
I had the same issue. After about two hours of googling, retries, regenerating API Key many times, etc. i discovered that i enabled the wrong service in the Google APis Console. I enabled Google Maps API v2 Service, but for Android Apps you have to use Google Maps Android API v2. After enabling the right service all started working.
YOUR ECLIPSE MAYBE CHANGED SHA1 KEY, so you must regen your google key with new SHA1 key in here: https://console.developers.google.com/project/watchful-net-796/apiui/credential After that, copy new key into manifest and reload this google page some times, and your key will be updated, rebuild your project, it will work. P/S: For my error, I deleted .android folder so eclipse regen SHA1.
I followed the same step provided in the Google Doc but i was getting the same error. Later i realized that i was signing my app with my app.keystore and the SHA key that i was using to generate the API key was the debug one.
So i simply removed the signingConfig signingConfig.generic
from by build.gradle
file and my map started to work fine.
Hope this helps someone.
I faced the same issue.
If you issued an api for your release version of the application. Then that api will only work for the release version not for the debug version. So make sure you are using the release version in your phone or emulator .
For me, everything was working both in an emulator and on a physical device.
However, it stopped working for me when I set up a second machine to debug the same app in an emulator with a newer API level.
나는 그 기계 의 지문 이 바뀌 었다는 것을 몰랐 습니다. 기기 로그에서 인증 실패 오류 로그를 확인한 후 Google 개발자 콘솔의 지문과 오류 메시지의 지문을 면밀히 비교했습니다. 그때 제가 그 차이를 보았습니다. 패키지 이름과 함께 개발자 콘솔에 새 지문을 추가 한 후 내 앱이 새 시스템의 에뮬레이터에서 예상대로 작동하기 시작했습니다.
따라서 새 시스템을 설정 한 경우 지문을 다시 확인하십시오!
참고 URL : https://stackoverflow.com/questions/13696620/google-maps-android-api-v2-authorization-failure
'developer tip' 카테고리의 다른 글
handler.postDelayed () 중지 (0) | 2020.09.03 |
---|---|
Maven 2에서 전이 종속성이 발생하는 종속성을 어떻게 알 수 있습니까? (0) | 2020.09.03 |
JavaScript에서 객체를 반복하는 방법은 무엇입니까? (0) | 2020.09.03 |
sed가 \ t를 탭으로 인식하지 않는 이유는 무엇입니까? (0) | 2020.09.03 |
IP 주소에 사용할 MySQL 데이터 유형은 무엇입니까? (0) | 2020.09.03 |