任务':app:transformClassesWithDexForDebug'执行失败。在android中

时间:2017-02-22 21:00:27

标签: android

我正在尝试在我的Android应用中使用谷歌地图进行学习。我生成了api密钥,但是我收到了这个错误。 任务'

的执行失败
: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>

这是zombie提出的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'
}

进行更改后,现在我收到此错误。 * 什么地方出了错: 评估项目&#39;:app&#39;。

时出现问题
  

无法在项目&#39;:app&#39;上找到参数[25]的方法compileSdkVersion()类型为org.gradle.api.Project。

  • 尝试:

2 个答案:

答案 0 :(得分:0)

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

  

注意:如果您的应用中方法引用的数量超过65K限制,您的应用可能无法编译。您可以通过仅指定应用使用的特定Google 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 ...但这对当前问题来说太过分了)

然后,我不知道你对Gradle做了什么,文件,但是

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

    ... 

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

答案 1 :(得分:0)

我将minSdkVersion从15改为21,今天我遇到了类似的问题, 并添加行multiDexEnabled true然后工作正常,更多信息请在这里查看https://developer.android.com/studio/build/multidex.html,看起来这个问题是由Multidex支持引起的。