2016-12-14 90 views
0

我将Google地图API集成到我的应用程序中,现在需要更多时间来首次启动(即使我不启动地图),而且我也不能使用地图Build APK。我可以简单地在设备上运行它,但无法在Android Studio中构建它。无法使用谷歌地图创建应用程序

依赖关系:

compile fileTree(dir: 'libs', include: ['*.jar']) 
testCompile 'junit:junit:4.12' 
compile 'com.android.support:appcompat-v7:25.0.1' 
compile 'com.google.android.gms:play-services:9.8.0' 

下面是错误的:

Error:The number of method references in a .dex file cannot exceed 64K. 
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html 
:app:transformClassesWithDexForDebug FAILED 
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.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_101\bin\java.exe'' finished with non-zero exit value 2 

于是,两个问题:如何降低时间首次发射,以及如何构建应用程序?

+1

乘坐看看http://stackoverflow.com/questions/40958192/i-get-errorexecution-failed-for-task-apptransformclasseswithdexfordebug-w/40958284#40958284 – antonio

+0

和在这里 - > http://stackoverflow.com/a/40958251/5188159 –

+0

多个库的问题,您正在使用库文件和gradle链接,请确保您正在使用所需的库。还要在defaultConfig中添加multiDexEnabled true。 – Nithin

回答

1
android { 
       ... 
       defaultConfig { 
        ... 
        multiDexEnabled true 
       } 
      } 

在您的应用程序build.gradle文件中使用它会工作。

+0

还有一件事你只想使用地图服务? –

+0

谢谢!现在是,但我后来不知道。我还需要知道什么? – Tryam

+0

如果您只需要map服务而不是仅使用map的依赖关系,则不要使用完整的play服务依赖项。 compile'c​​om.google.android.gms:play-services-maps:10.0.0' –

0

不要在gradle文件中包含完整的播放服务库,它们会从apk提供的64k方法限制中消耗约34 k个方法。所以有两种解决方案。

  1. 如果你想使用的地图,然后在你的gradle这个添加此添加的播放服务,即只需库

com.google.android.gms:发挥服务,地图:10.0 0.1

  • 启用应用程式multidex支持。要做到这一点执行以下步骤

    android { 
    
    defaultConfig { 
    minSdkVersion 21 
    targetSdkVersion 25 
    multiDexEnabled true// add this line 
    } 
    } 
    

    并添加此作为一个依赖

  • 编译 'com.android.support:multidex:1.0.1'

    相关问题