2015-11-19 58 views
1

我的错误信息是:错误在建的apk

//Error Code: 
    2 
Output: 
    UNEXPECTED TOP-LEVEL EXCEPTION: 
    com.android.dex.DexException: Multiple dex files define Lcom/google/common/annotations/Beta; 
     at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) 
     at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) 
     at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) 
     at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) 
     at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) 
     at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) 
     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) 
     at com.android.dx.command.dexer.Main.run(Main.java:230) 
     at com.android.dx.command.dexer.Main.main(Main.java:199) 
     at com.android.dx.command.Main.main(Main.java:103)// 

请帮我解决这个 我的build.gradle

//dependencies { 
compile project(':appRater') 
compile project(':circularImageView') 
compile project(':facebookSDK') 
compile project(':paperSlidingTab') 
compile project(':library') 
compile project(':urlImageViewHelper') 
compile project(':pullToRefreshLi') 
compile project(':libraries:SlidingMenu:library') 
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar') 
compile files('libs/httpmime-4.2.5.jar') 
compile files('libs/json-org.jar') 
compile files('libs/universal-image-loader-1.9.1-with-sources.jar') 
compile files('libs/WebSocket.jar') 
compile files('libs/gcm.jar') 
compile files('libs/applause-sdk-library-2.0.0.jar') 
compile 'org.droidparts:droidparts:1.+' 
compile 'joda-time:joda-time:2.3' 
compile 'com.google.api-client:google-api-client:1.+' 
compile 'com.google.api-client:google-api-client-android2:1.+' 
compile 'com.google.http-client:google-http-client:1.+' 
compile 'com.google.http-client:google-http-client-android2:1.+' 
compile 'com.google.oauth-client:google-oauth-client:1.+' 
compile 'com.google.code.gson:gson:2.+' 
compile 'com.google.guava:guava:11.+' 
compile 'com.google.http-client:google-http-client-jackson2:1.+' 
compile 'com.google.protobuf:protobuf-java:2.+' 
compile 'com.google.android.gms:play-services:3.+' 
} 

android { 
compileSdkVersion 19 
buildToolsVersion "19.1.0" 

defaultConfig { 
    minSdkVersion 9 
    targetSdkVersion 17 
} 

signingConfigs { 
    release { 
     if (System.getenv("GRADLE_KEYSTORE")) { 
      storeFile = file(System.getenv("GRADLE_KEYSTORE")) 
      storePassword = System.getenv("GRADLE_KEYSTORE_PASSWORD") 
      keyAlias = System.getenv("GRADLE_KEY_ALIAS") 
      keyPassword = System.getenv("GRADLE_KEY_PASSWORD") 
     } 
    } 
} 

buildTypes.debug { 
    ext.enableCrashlytics = false 
} 

buildTypes.release { 
    debuggable false 
    zipAlignEnabled true 
    minifyEnabled false 
    signingConfig signingConfigs.release 
} 

packagingOptions { 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/license.txt' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/NOTICE.txt' 
    exclude 'META-INF/notice.txt' 
    exclude 'META-INF/ASL2.0' 
} 

lintOptions { 
    checkReleaseBuilds false 
    // Or, if you prefer, you can continue to check for errors in release builds, 
    // but continue the build even when errors are found: 
    abortOnError false 
} 
} 
+0

在你的依赖使用的是不同版本的同一班。首先检查你的罐子。 –

回答

0
defaultConfig { 
    minSdkVersion 14 //lower than 14 doesn't support multidex 
    targetSdkVersion 22 

    // Enabling multidex support. 
    multiDexEnabled true 
} 

,或者你可以通过做使应用程序类

public class MyApplication extends MultiDexApplication { .. } 

override 
attachBaseContext method and call MultiDex.install(). 
protected void attachBaseContext(Context base) { 
super.attachBaseContext(base); 
MultiDex.install(this); 
} 

否则(如果您的应用程序没有自定义应用程序实现),在AndroidManifest.xml中声明MultiDexApplication作为应用程序实现。

<application 
android:name="android.support.multidex.MultiDexApplication" 
.. > 
.. 
</application> 
+0

好的,thx家伙...让我试试添加该代码..我非常坚持它.. – dany

+0

所有答案无法正常工作..所有人请帮助我解决这个错误 – dany

+0

@dany我提供了另一种方式,也可以帮助您。尝试一次,让我知道 – curiousMind

1

当我们在一个项目中使用具有2个或更多版本的相同库时,会出现这种情况。所以要尽量找到图书馆在你的应用程序版本特别支持-V4库

android { 
     compileSdkVersion 19 
    buildToolsVersion "19.1.0" 

     defaultConfig { 
      ... 
      minSdkVersion 14 
      targetSdkVersion 19 
      ... 

      // Enabling multidex support. 
      multiDexEnabled true 
     } 
     ... 
    } 

    dependencies { 
     compile 'com.android.support:multidex:1.0.0' 
    } 

您可以使用下面的代码也是如此,这项工作在我的情况下

dexOptions { 
     incremental true 
     javaMaxHeapSize "4g" 
    } 
+0

我尝试第一个答案不工作,错误变得很多..我尝试第二个答案 – dany