【问题标题】:GoogleMap Android API sample doesn't workGoogleMap Android API 示例不起作用
【发布时间】:2017-07-13 18:02:54
【问题描述】:
我尝试从本教程中学习 Google Map API (https://github.com/googlemaps/android-samples)。
但是,当我运行应用程序时收到错误消息。
这个问题可以证明是简单的问题,但我是使用 android studio 和 Google Map API 的初学者。所以我有任何想法来解决这个问题......
请给我一些建议。
错误信息
'任务执行失败':app:transformClassesWithDexForDebug'
com.android.build.api.transform.TransformException:
java.util.concurrent.ExecutionException:com.android.dex.DeIndexOverFlowException:
方法 ID 不在 [0,0xffff]:65536
这就是我所做的。
1) 下载 zip 文件。 (https://github.com/googlemaps/android-samples)
2) 打开 AndroidStudio 并导入项目
从使用“导入项目(Eclipse ADT、Gradle 等)”
3) 将 Google MAP API 密钥放入“gradle.properties”文件中。
4) 运行
【问题讨论】:
标签:
android
google-maps-api-2
【解决方案1】:
你的方法太多了。 dex只能有65536个方法。
你需要包含multi-dex
在 build gradle 中添加这些行
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
同样在您的 Manifest 中将 MultiDexApplication 类从 multidex 支持库添加到应用程序元素
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
【解决方案2】:
我假设您指的是 googlemaps/android-samples 下的 ApiDemos 和教程
- ApiDemos 使用
compile 'com.google.android.gms:play-services-maps'
- 教程使用
compile 'com.google.android.gms:play-services'
第二个将处理所有播放服务 api 而不是特定的。所以你面临着 65K 的限制问题。
尝试对 googlemaps/android-samples 下的所有示例使用单独的 api(如 com.google.android.gms:play-services-maps)