2017-02-22 141 views
0

我想在我的Android应用程序中使用谷歌地图学习的目的。我生成的API密钥,但我得到这个错误。 执行失败的任务'任务':app:transformClassesWithDexForDebug'的执行失败。在android

: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 

我如何纠正错误?我是新来的Android应用程序开发,所以请大家多多包涵。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.user.googlemap"> 

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 
    <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"> 

     <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
     <meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value="my api key ,i have put it over 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> 

</manifest> 

这里是gradle构建文件的僵尸问。

apply { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.1" 
    defaultConfig { 
     applicationId "com.example.user.googlemap" 
     minSdkVersion 19 
     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' 
     }a 
    } 
} 

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.0.1' 
    compile 'com.google.android.gms:play-services:10.0.1' 
    testCompile 'junit:junit:4.12' 
} 

进行更改后,现在我收到此错误。 *发生了什么问题: 评估项目':app'时发生问题。

对于类型为org.gradle.api.Project的项目':app'上的参数[25]找不到方法compileSdkVersion()。

  • 尝试:
+0

在你的gradle文件中启用multidex – zombie

+0

我应该添加build.gradle文件吗? –

+0

@ zombie我如何在gradle文件中启用multidex? –

回答

0

你的错误... DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

注意:如果方法引用的在您的应用程序数量超过65K的限制,您的应用程序可能无法编译。您可以通过编译你的应用程序时,仅指定特定谷歌Play服务才能缓解这个问题的API应用程序使用,而不是所有的人都

Google Play Services Setup(重点煤矿)

你确实是编译 “所有的人”

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

您似乎只需要地图?

然后只编译-maps

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' 
    }) 
    testCompile 'junit:junit:4.12' 

    compile 'com.android.support:appcompat-v7:25.0.1' 
    compile 'com.google.android.gms:play-services-maps:10.2.0' // See here 
} 

(或者你可以启用Multidex ...但是,这是矫枉过正当前问题)


然后,我不知道你做的摇篮,文件什么,但

apply { // <-- Should be android 
    compileSdkVersion 25 

    ... 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     }a // <--- Remove this random 'a' character 
+0

请解释为在哪个文件我需要改变的东西? –

+0

'/ app/build.gradle'(不是说不要依赖它的那个) –

+0

我已经上传了gradle.build。你可以在那里做改变吗? –

0

我今天得到了类似的问题,我改变的minSdkVersion从15到21, 后添加一行multiDexEnabled真,那么工精细,更多信息请点击这里https://developer.android.com/studio/build/multidex.html,看起来升这个问题是由Multidex支持造成的。

+0

在多行添加“multiDexEnabled true”后,它可以正常工作 –

+0

您可以在我的代码中进行更改吗? –

+0

在gradle文件的defaultconfig部分中确保** multiDexEnabled true **和** minSdkVersion 21 **,因为这个注释编辑器对我来说非常有限,我不知道如何在这里格式化文本,但我认为你应该知道如何改变它 –

相关问题