java - 谷歌地图 API 出现 DexIndexOverflowException

标签 java android dictionary

我想制作一个使用谷歌地图 API 的应用程序,我从一个打开谷歌地图 Activity 的简单应用程序开始。 (我从 SDK 管理器下载 google play 服务)。我认为这是一个非常基本的程序,但是当我尝试运行我的应用程序时出现错误。

这是我程序的代码,也是Android Studio产生的错误。

错误:

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

代码:

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 方法限制。

如果你的 build.gradle 中有这个:

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

将其替换为:

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

有关详细信息,请参阅 the documentation .

关于java - 谷歌地图 API 出现 DexIndexOverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38177434/

相关文章:

java - 图书馆 |如何创建小 map ?

android - 在 mapsforge 的 android 中选择离线 .map 中的对象

python - 在迭代文档时存储 3 个不同的变量(字典或列表)?

python - 如何在python中的字典列表中查找项目的累计总和

java - 项目 lombok 在 jboss 开发人员工作室中工作吗?

java - Android ListView OnClickListener

java - Android - 使用 fragment 扩展另一个类

java - TCP 套接字关闭并重新绑定(bind)

java - 使用正则表达式在一个空格处拆分字符串

java - Android Studio 中的分数计数器错误