创建地图时的运行时问题

时间:2017-01-27 04:30:15

标签: android google-maps

我正在使用谷歌地图,但遇到了问题。我还在清单中添加了权限和密钥,请参阅下面的详细信息:

问题:

  

错误:任务':app:transformClassesWithDexForDebug'执行失败。   com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中: 65536

主要活动代码:

     private GoogleMap mMap;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_maps);
  // Obtain the SupportMapFragment and get notified 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) {
  mMap = googleMap;

  // Add a marker in Sydney and move the camera
  LatLng sydney = new LatLng(-34, 151);
  mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
  mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
  }

XML文件代码:

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:map="http://schemas.android.com/apk/res-auto"
  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.admin.maptest.MapsActivity" />

build.gradle文件代码:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 25
  buildToolsVersion "25.0.2"
  defaultConfig {
  applicationId "com.admin.maptest"
  minSdkVersion 15
  targetSdkVersion 25
  versionCode 1
  versionName "1.0"
  testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }
  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:25.1.0'
  compile 'com.google.android.gms:play-services:10.0.1'
  testCompile 'junit:junit:4.12'
}

3 个答案:

答案 0 :(得分:2)

在你的gradle中尝试这个

{id: 1, name: "name1", age: 21}

同时检查此thread

答案 1 :(得分:1)

避免在gradle中启用multidex。

在您的gradle中使用所需的库,而不是所有的游戏服务。

e.g。如果你正在使用地图,那么编译'com.google.android.gms:play-services-maps:10.0.1'

答案 2 :(得分:0)

  defaultConfig {
   ...
   targetSdkVersion ..
   multiDexEnabled true 
    }

在gradle app中使用此依赖关系
 编译&#39; com.android.support:multidex:1.0.1&#39;