【问题标题】:Runtime issue when creating map创建地图时的运行时问题
【发布时间】:2017-01-27 04:30:15
【问题描述】:

我正在使用 Google 地图,但遇到了问题。我还在清单中添加了权限和密钥,详情请参见下文:

问题:

错误:任务 ':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'
}

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    在你的 gradle 中试试这个

    android {
    
        compileSdkVersion ..
        buildToolsVersion '...'
    
        defaultConfig {
           ...
           targetSdkVersion ..
           multiDexEnabled true //multidex set true
       }
    }
    

    也可以查看thread

    【讨论】:

    • 你可以投票并接受答案,如果它有效@Anjali :)
    【解决方案2】:

    避免在 gradle 中启用 multidex。

    在你的 gradle 中使用所需的库而不是所有的播放服务。

    例如如果您使用的是地图,请编译 'com.google.android.gms:play-services-maps:10.0.1'

    【讨论】:

      【解决方案3】:
        defaultConfig {
         ...
         targetSdkVersion ..
         multiDexEnabled true 
          }
      

      在 gradle 应用程序中并使用此依赖项
      编译'com.android.support:multidex:1.0.1'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-24
        • 1970-01-01
        • 2018-09-14
        • 2022-01-16
        • 2021-07-17
        • 1970-01-01
        • 1970-01-01
        • 2019-05-13
        相关资源
        最近更新 更多