2017-05-09 7 views
0

開発中のアプリでAndroidのGoogleマップAPIを使いたいと思っており、実装に問題がありました。私はGoogle Developers(https://developers.google.com/maps/documentation/android-api/map-with-marker)が提供するチュートリアルに従いました。アプリケーションを実行すると、このビルドエラーが発生しました:Build Error私はこれを回避する方法を探しましたが、解決策を見つけることができませんでした。AndroidのGoogleマップV2 APIでビルドエラーが発生する

activity_maps.xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
 
      xmlns:tools="http://schemas.android.com/tools" 
 
      android:id="@+id/map" 
 
      android:name="com.google.android.gms.maps.SupportMapFragment" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      tools:context="com.example.mapwithmarker.MapsMarkerActivity" />

MapsWithMarkerActivity

package com.example.mapwithmarker; 

    import android.os.Bundle; 
    import android.support.v7.app.AppCompatActivity; 

    import com.google.android.gms.maps.CameraUpdateFactory; 
    import com.google.android.gms.maps.GoogleMap; 
    import com.google.android.gms.maps.OnMapReadyCallback; 
    import com.google.android.gms.maps.SupportMapFragment; 
    import com.google.android.gms.maps.model.LatLng; 
    import com.google.android.gms.maps.model.MarkerOptions; 

    /** 
    * An activity that displays a Google map with a marker (pin) to indicate a particular location. 
    */ 
    public class MapsMarkerActivity extends AppCompatActivity 
    implements OnMapReadyCallback { 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      // Retrieve the content view that renders the map. 
      setContentView(R.layout.activity_maps); 
      // Get the SupportMapFragment and request notification 
      // when the map is ready to be used. 
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
      mapFragment.getMapAsync(this); 
     } 

     @Override 
     public void onMapReady(GoogleMap googleMap) { 
      // Add a marker in Sydney, Australia, 
      // and move the map's camera to the same location. 
      LatLng sydney = new LatLng(-33.852, 151.211); 
      googleMap.addMarker(new MarkerOptions().position(sydney) 
      .title("Marker in Sydney")); 
      googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
     } 
} 

build.gradle(モジュールAPP)

apply plugin: 'com.android.application' 

     android { 
      compileSdkVersion 24 
      buildToolsVersion "23.0.3" 
      defaultConfig { 
      applicationId "com.example.mapwithmarker" 
      minSdkVersion 15 
      targetSdkVersion 24 
      versionCode 1 
      versionName "1.0" 
      testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner" 
      resValue "string", "google_maps_key", 
    (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "") 
     } 
     buildTypes { 
      release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 

}

dependencies { 
     compile fileTree(dir: 'libs', include: ['*.jar']) 
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
      exclude group: 'com.android.support', module: 'support-annotations' 
     }) 
     compile 'com.android.support:appcompat-v7:24.2.1' 
     compile 'com.google.android.gms:play-services:9.8.0' 
     testCompile 'junit:junit:4.12' 
    } 

のAndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.example.mapwithmarker"> 

     <application 
      android:allowBackup="true" 
      android:icon="@mipmap/ic_launcher" 
      android:label="@string/app_name" 
      android:supportsRtl="true" 
      android:theme="@style/AppTheme"> 

      <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=".MapsMarkerActivity" 
       android:label="@string/title_activity_maps"> 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 
      </activity> 
     </application> 

    </manifest> 

私はこれを実行するにはネクサス5XのAPI 23(アンドロイド6.0、API 23)エミュレータを使用しています。 事前に感謝します

答えて

0

これを取り除く方法の1つは、必要な依存関係を追加することです。あなたの場合;

compile 'com.google.android.gms:play-services:9.8.0'

正常にビルドすることをアプリになったので、そのためにあなたに感謝しているこんにちは、

compile 'com.google.android.gms:play-services-maps:9.8.0'

+0

に交換してください。私はサーバー上で認証が失敗する新しいエラーに遭遇しました。これに別のAPIキーを使用する必要がありますか? – mjonjones

+0

'サーバー上で認証が失敗する新しいエラーが発生しました。これはGoogleマップに関連しない別の問題です。 apiキーを取得せず、ビルドgradleでこの 'GOOGLE_MAPS_API_KEY'値を取得しなかったとしても、マップの代わりに空白の領域が表示されます。 – Blackkara

関連する問題