Execution failed for task, java.lang.RuntimeException:Unable to pre-dex

时间:2017-05-16 09:28:56

标签: android android-studio

System:

  • Windows7 x86(32bit)
  • JDK 1.8.0_131
  • AndroidStudio 2.3.2

I'm trying to deploy me APP into my Android device, but kept facing this error:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException:
  java.lang.RuntimeException:
  java.lang.RuntimeException:
    Unable to pre-dex 'C:\Users\me\.android\build-cache\7529f6ca1b923c48febb00ef8a29431fc2b1b32b\output\jars\classes.jar' to
    'D:\Data\MyAPP\code\Android\app\build\intermediates\transforms\dex\debug\folders\1000\10\classes_db0da3bb5cf7139810a8b2f028705f64cb610b31'

After read much thread from Google & Stackoverflow, I tried all the following solution:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'android-apt'
def AAVersion = '4.0.0'
def supportVersion = '23.4.0'

android
{
  compileSdkVersion 23
  buildToolsVersion '25.0.0'
  packagingOptions
  {
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
  }
  defaultConfig
  {
    applicationId "app.myapp.com."
    minSdkVersion 18
    targetSdkVersion 23
    versionCode 1
    versionName "v1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
  }
  buildTypes
  {
    release
    {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  dexOptions
  {
    javaMaxHeapSize "2g" // set it to 4g will bring unable to start JavaVirtualMachine
    preDexLibraries = false
  }
  compileOptions
  {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }
}
dependencies
{
  compile fileTree(include: ['*.jar'], dir: 'libs')
  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
      exclude group: 'com.android.support', module: 'support-annotations'
  })
  apt "org.androidannotations:androidannotations:$AAVersion"
  compile "org.androidannotations:androidannotations-api:$AAVersion"
  apt "org.androidannotations:otto:$AAVersion"
  compile "org.androidannotations:rest-spring-api:$AAVersion"
  apt "org.androidannotations:rest-spring:$AAVersion"
  /** http://projects.spring.io/spring-android/ */
  compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
  compile 'com.android.support:multidex:1.0.1'
  compile "com.android.support:appcompat-v7:$supportVersion"
  compile "com.android.support:design:$supportVersion"
  compile "com.android.support:percent:$supportVersion"
  compile "com.android.support:recyclerview-v7:$supportVersion"
  compile 'com.google.android.gms:play-services-gcm:10.2.4'
  // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
  compile 'com.fasterxml.jackson.core:jackson-core:2.8.1'
  // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations
  compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.1'
  // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
  compile 'com.fasterxml.jackson.core:jackson-databind:2.8.1'
  //Event Bus: https://github.com/square/otto
  compile 'com.squareup:otto:1.3.8'
  compile 'me.dm7.barcodescanner:zbar:1.9'
  testCompile 'junit:junit:4.12'
}

apt
{
  arguments
  {
    androidManifestFile variant.outputs[0]?.processResources?.manifestFile
    // if you have multiple outputs (when using splits), you may want to have other index than 0

    // you should set your package name here if you are using different application IDs
    // resourcePackageName "your.package.name"

    // You can set optional annotation processing options here, like these commented options:
    // logLevel 'INFO'
    // logFile '/var/log/aa.log'
  }
}

Clean and rebuild my project

BUT nothing helps me to solve this problem......can anyone gives more suggestion ?

I'm looking forward for your reply, and thank you~

1 个答案:

答案 0 :(得分:-1)

将您的gradle改为:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '4.0.0'
def supportVersion = '23.4.0'

android
{
  compileSdkVersion 23
  buildToolsVersion '25.0.0'
  packagingOptions
  {
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
  }
  defaultConfig
  {
    applicationId "app.myapp.com."
    minSdkVersion 18
    targetSdkVersion 23
    versionCode 1
    versionName "v1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
  }
  buildTypes
  {
    release
    {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  dexOptions
  {
    javaMaxHeapSize "2g" // set it to 4g will bring unable to start JavaVirtualMachine
    preDexLibraries = false
  }
  compileOptions
  {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }
}
dependencies
{
  compile fileTree(include: ['*.jar'], dir: 'libs')
  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
      exclude group: 'com.android.support', module: 'support-annotations'
  })
  apt "org.androidannotations:androidannotations:$AAVersion"
  compile "org.androidannotations:androidannotations-api:$AAVersion"
  apt "org.androidannotations:otto:$AAVersion"
  compile "org.androidannotations:rest-spring-api:$AAVersion"
  apt "org.androidannotations:rest-spring:$AAVersion"
  /** http://projects.spring.io/spring-android/ */
  compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
  compile 'com.android.support:multidex:1.0.1'
  compile "com.android.support:appcompat-v7:$supportVersion"
  compile "com.android.support:design:$supportVersion"
  compile "com.android.support:percent:$supportVersion"
  compile "com.android.support:recyclerview-v7:$supportVersion"
  compile 'com.google.android.gms:play-services-gcm:10.2.4'
  // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
  compile 'com.fasterxml.jackson.core:jackson-core:2.8.1'
  // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations
  compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.1'
  // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
  compile 'com.fasterxml.jackson.core:jackson-databind:2.8.1'
  //Event Bus: https://github.com/square/otto
  compile 'com.squareup:otto:1.3.8'
  compile 'me.dm7.barcodescanner:zbar:1.9'
  testCompile 'junit:junit:4.12'
}

apt
{
  arguments
  {
    androidManifestFile variant.outputs[0]?.processResources?.manifestFile
    // if you have multiple outputs (when using splits), you may want to have other index than 0

    // you should set your package name here if you are using different application IDs
    // resourcePackageName "your.package.name"

    // You can set optional annotation processing options here, like these commented options:
    // logLevel 'INFO'
    // logFile '/var/log/aa.log'
  }
}

apply plugin: 'com.google.gms.google-services'