2016-08-20 46 views
-6

我已经包含了这一点,它并没有帮助解决问题!如何修复错误:.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> 

错误: enter image description here

日志:

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 
+0

使用'minifyEnabled'并将此真做'Proguard'实现涅槃你的代码都在调试和发布版本。这可能会增加你的构建时间。 –

+0

你真的使用所有的谷歌播放服务? –

回答

1

试试这个..

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

    multiDexEnabled true 

    } 

dexOptions要补充..

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

而且在您的AndroidManifest.xml添加此行的android :名称

<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' 
} 
0

你已经尝试了释放,同时要编译调试APK:

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

尝试将其包含在默认的太:

multiDexEnabled true 
+0

我认为你应该阅读你写的,你没有在默认情况下包含multiDex行或者没有调试,如果你了解gradle构建的风格,你应该选择它,因为包含在发行版中并不会将其添加到默认调试中。检查错误图像,并从中发现您正在运行调试。 – sumandas

0

请按照下面列出的所有步骤。

启用multidex启用真实,让你的应用程序作为multidex application.Few步骤支持应遵循如下:

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

添加这种依赖于依赖列表

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

与MultiDexApplication扩展应用程序级类

写这个方法在你的申请ication类

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 
    } 
相关问题