提问者:小点点

如何修复错误:. dex文件中的方法引用数量不能超过64K?[重复]


这一点我都包括进去了,对解决问题没有帮助!

 multiDexEnabled true

build. gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.0'
    defaultConfig {
        applicationId "com.pokemongo.pokemon"
        minSdkVersion 16
        targetSdkVersion 24
    }
    buildTypes {
        release {
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.android.support:multidex:1.0.1'
}

清单:

<manifest package="com.pokemongo.pokemon"
xmlns:android="http://schemas.android.com/apk/res/android">
android:versionCode="1"
android:versionName="1.0">

<uses-sdk
    android:minSdkVersion="18"
    android:targetSdkVersion="22" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/pikachu"
    android:name="android.support.multidex.MultiDexApplication"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light">
    <activity
        android:name=".CameraViewActivity"
        android:label="@string/title_activity_camera_view">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MapActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".CameraViewActivity" />
    </activity>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyD67YQ0A8XXPF5RvvtQIdJnc-gcqem5I9s" />

</application>

日志:

   Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug]
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2411Library
:app:prepareComAndroidSupportAppcompatV72411Library
:app:prepareComAndroidSupportMediarouterV72300Library
:app:prepareComAndroidSupportMultidex101Library
:app:prepareComAndroidSupportSupportV42411Library
:app:prepareComAndroidSupportSupportVectorDrawable2411Library
:app:prepareComGoogleAndroidGmsPlayServices940Library
:app:prepareComGoogleAndroidGmsPlayServicesAds940Library
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite940Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics940Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl940Library
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing940Library
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite940Library
:app:prepareComGoogleAndroidGmsPlayServicesAuth940Library
:app:prepareComGoogleAndroidGmsPlayServicesAuthBase940Library
:app:prepareComGoogleAndroidGmsPlayServicesBase940Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement940Library
:app:prepareComGoogleAndroidGmsPlayServicesCast940Library
:app:prepareComGoogleAndroidGmsPlayServicesCastFramework940Library
:app:prepareComGoogleAndroidGmsPlayServicesClearcut940Library
:app:prepareComGoogleAndroidGmsPlayServicesContextmanager940Library
:app:prepareComGoogleAndroidGmsPlayServicesDrive940Library
:app:prepareComGoogleAndroidGmsPlayServicesFitness940Library
:app:prepareComGoogleAndroidGmsPlayServicesGames940Library
:app:prepareComGoogleAndroidGmsPlayServicesGass940Library
:app:prepareComGoogleAndroidGmsPlayServicesGcm940Library
:app:prepareComGoogleAndroidGmsPlayServicesIdentity940Library
:app:prepareComGoogleAndroidGmsPlayServicesIid940Library
:app:prepareComGoogleAndroidGmsPlayServicesLocation940Library
:app:prepareComGoogleAndroidGmsPlayServicesMaps940Library
:app:prepareComGoogleAndroidGmsPlayServicesNearby940Library
:app:prepareComGoogleAndroidGmsPlayServicesPanorama940Library
:app:prepareComGoogleAndroidGmsPlayServicesPlaces940Library
:app:prepareComGoogleAndroidGmsPlayServicesPlus940Library
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet940Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanager940Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerApi940Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks940Library
:app:prepareComGoogleAndroidGmsPlayServicesVision940Library
:app:prepareComGoogleAndroidGmsPlayServicesWallet940Library
:app:prepareComGoogleAndroidGmsPlayServicesWearable940Library
:app:prepareComGoogleFirebaseFirebaseAnalytics940Library
:app:prepareComGoogleFirebaseFirebaseAnalyticsImpl940Library
:app:prepareComGoogleFirebaseFirebaseAuth940Library
:app:prepareComGoogleFirebaseFirebaseAuthCommon940Library
:app:prepareComGoogleFirebaseFirebaseAuthModule940Library
:app:prepareComGoogleFirebaseFirebaseCommon940Library
:app:prepareComGoogleFirebaseFirebaseConfig940Library
:app:prepareComGoogleFirebaseFirebaseCrash940Library
:app:prepareComGoogleFirebaseFirebaseDatabase940Library
:app:prepareComGoogleFirebaseFirebaseDatabaseConnection940Library
:app:prepareComGoogleFirebaseFirebaseIid940Library
:app:prepareComGoogleFirebaseFirebaseMessaging940Library
:app:prepareComGoogleFirebaseFirebaseStorage940Library
:app:prepareComGoogleFirebaseFirebaseStorageCommon940Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:mergeDebugAndroidTestShaders
:app:compileDebugAndroidTestShaders
:app:generateDebugAndroidTestAssets
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
Note: D:\Android Project\Virtual\POKEMON\Pokemon\app\src\main\java\com\pokemongo\pokemon\CameraViewActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:buildInfoDebugLoader
:app:transformClassesWithExtractJarsForDebug
:app:transformClassesWithInstantRunVerifierForDebug
:app:transformClassesWithJavaResourcesVerifierForDebug
:app:mergeDebugJniLibFolders
:app:transformNative_libsWithMergeJniLibsForDebug
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug
:app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:transformClassesWithInstantRunForDebug
:app:transformClasses_enhancedWithInstant+reloadDexForDebug UP-TO-DATE
:app:incrementalDebugTasks
:app:prePackageMarkerForDebug
:app:fastDeployDebugExtractor
:app:generateDebugInstantRunAppInfo
:app:transformClassesWithDexForDebug
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
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_91\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 1 mins 6.756 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console

共3个答案

匿名用户

试试这个…

  defaultConfig {
    applicationId "com.pokemongo.pokemon"
    minSdkVersion 16
    targetSdkVersion 24

    multiDexEnabled true

    }

dexOptions应该添加…

dexOptions {
   //incremental = true;
preDexLibraries = false
javaMaxHeapSize "4g"
 }

也在你的AndroidManifest. xml中添加这一行android:name

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication"
>

在你的Gradle…

  apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
defaultConfig {
    applicationId "com.pokemongo.pokemon"
    minSdkVersion 16
    targetSdkVersion 24
    multiDexEnabled true
}

   dexOptions {
  //incremental = true;
  preDexLibraries = false
  javaMaxHeapSize "4g"
  }
buildTypes {
    release {

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
 }
productFlavors {
 }
 }

 dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.android.support:multidex:1.0.1'
 }

匿名用户

您在编译调试apk时尝试了发布:

buildTypes {
        release {
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

也尝试将其包含在默认值中:

multiDexEnabled true

匿名用户

请遵循下面列出的所有步骤。

启用multidex启用true并允许作为multidex应用程序支持您的应用程序。要遵循的几个步骤是:

defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 3
        versionName "1.0.1"
        **multiDexEnabled true**
    }

将此依赖项添加到依赖项列表

编译'com.android.support: multidex:1.0.0'

使用MultiDexApplication扩展您的应用程序级别类

在您的应用程序类中编写此方法

protected void attachBaseContext(Context base)
    {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

更新

dexOptions {
        jumboMode = true
        javaMaxHeapSize "4g" //specify the heap size for the dex process
        preDexLibraries = false
    }