DexIndexOverflowException使用Google Maps API [英] DexIndexOverflowException With Google Maps API

查看:175
本文介绍了DexIndexOverflowException使用Google Maps API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个使用Google Maps API的应用程序,我开始使用一个打开Goog​​le地图活动的简单应用程序。 (我从SDK Manager下载谷歌播放服务)。我认为这是一个非常基本的程序,但是当我尝试运行我的应用程序时会出现错误。

I want to make an application that uses the Google Maps API, I started with a simple application that opens a google map activity. (I download google play services from the SDK Manager). I think that it's a very basic program but there is an error when I try to run my application.

这是程序的代码,还有Android生成的错误工作室。

Here's the code of my program, and also the error generated by Android Studio.

错误:


错误:执行失败的任务
':应用程序: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

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

代码: p>

The code:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {     
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);
}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@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));
}
}





<resources>

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">My API key is here ;) </string>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.amine.bea_mapapp">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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.geo.API_KEY"
        android:value="My API key is here ;)" />

    <activity
        android:name=".MapsActivity"
        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>

推荐答案

当您导入所有Google Play服务时,这是一个常见的错误,如果您这样做,很容易达到65k方法限制。

This is a common error when you import all of Google Play Services, if you do, it's easy to hit the 65k method limit.

如果您有在你的build.gradle中:

If you have this in your build.gradle:

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

将其替换为:

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

有关详细信息,请参阅文档

For more info see the documentation.

这篇关于DexIndexOverflowException使用Google Maps API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆