Android 从1.4.0开始,现在无法访问dex任务

Android 从1.4.0开始,现在无法访问dex任务,android,android-studio,gradle,Android,Android Studio,Gradle,我无法将我的项目升级到gradle 1.5: build.gradle(root)项目刷新失败:从1.4.0开始,现在无法访问dex任务。 错误:1.4.0引入了一个新的转换API,允许操作.class文件 有什么建议吗 root build.gradle: buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.

我无法将我的项目升级到gradle 1.5:

build.gradle(root)项目刷新失败:从1.4.0开始,现在无法访问dex任务。 错误:1.4.0引入了一个新的转换API,允许操作.class文件

有什么建议吗

root build.gradle:

buildscript {
    repositories {
        jcenter()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

subprojects {
    task allDependencies(type: DependencyReportTask) {}
}
buildscript {
repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

dependencies {
    classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.14.7'
    classpath "com.newrelic.agent.android:agent-gradle-plugin:4.244.0"
}
}

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'http://download.crashlytics.com/maven' }
}

task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}

apply plugin: 'com.android.application'

 android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

signingConfigs {
    release
}

testBuildType "debug"

defaultConfig {
    targetSdkVersion 23
    minSdkVersion 14

    multiDexEnabled true

    applicationId "com.freelancer.android.messenger"
    versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
    versionName "${versionMajor}.${versionMinor}.${versionPatch}"
    testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

    renderscriptTargetApi 21
    renderscriptSupportModeEnabled true

}

sourceSets {
    production {
        java.srcDir 'src/common/java'
    }

    develop {
        java.srcDir 'src/common/java'
    }

    staging {
        java.srcDir 'src/common/java'
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
        proguardFile 'proguard.cfg'
        buildConfigField "String", "CONTENT_PROVIDER_AUTHORITY",
                "\"com.freelancer.android.messenger.content_provider\""
    }
    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '.' + versionBuild + '-debug' + gitSha
        buildConfigField "String", "CONTENT_PROVIDER_AUTHORITY",
                "\"com.freelancer.android.messenger.content_provider.\" + BUILD_TYPE.toLowerCase()"
        debuggable true
        testCoverageEnabled = true
    }

    staging {
        applicationIdSuffix '.staging'
        versionNameSuffix '-staging-' + gitSha

        buildConfigField "String", "BASE_URL_API", "\"${rootProject.ext.stagingApiServer}\""
        buildConfigField "String", "BASE_URL_AUTH", "\"${rootProject.ext.stagingAuthServer}\""
        buildConfigField "String", "BASE_URL_WSS", "\"${rootProject.ext.stagingWsServer}\""
        buildConfigField "String", "BASE_URL_GAF", "\"${rootProject.ext.stagingGafUrl}\""
    }
}


productFlavors {
    // Define separate dev and prod product flavors.
    develop {
        // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
        // to pre-dex each module and produce an APK that can be tested on
        // Android Lollipop without time consuming dex merging processes.
        minSdkVersion 21
    }
    production {
        // The actual minSdkVersion for the application.
    }
    mock {

    }

}

// from android 6 apache its been deprecated: refer to ->
// http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
 //    useLibrary 'org.apache.http.legacy'

}


dependencies {

compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'com.android.support:palette-v7:22.2.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:design:22.2.0'

compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.5.0'

compile 'com.google.maps.android:android-maps-utils:0.3.4'
compile 'com.google.code.gson:gson:2.3'

// extension for popular dashclock app
compile 'com.google.android.apps.dashclock:dashclock-api:2.0.0'

compile 'com.jakewharton:butterknife:4.0.1'
compile 'com.squareup:otto:1.3.5'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'

compile ('com.facebook.android:facebook-android-sdk:3.23.0') {
    exclude group: 'com.google.android'
}

compile 'com.newrelic.agent.android:android-agent:4.244.0'
compile "com.mixpanel.android:mixpanel-android:4.5.3"
compile 'com.crashlytics.android:crashlytics:1.1.13'

compile 'com.github.kevinsawicki:http-request:6.0' // TODO deprecate and replace methods with okhttp

compile 'com.koushikdutta.async:androidasync:1.2.9@jar'
compile 'com.koushikdutta.ion:ion:1.2.9@jar'
compile 'com.path:android-priority-jobqueue:1.1.2'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.soundcloud.android:android-crop:0.9.10@aar'

compile project(':libs:stickylistheaders:library')
compile project(':libs:android-core:android-core-library')
compile project(':libs:viewpagerindicator:library')
compile project(':libs:PagerSlidingTabStrip')

compile "org.mockito:mockito-core:1.10.19"
compile 'com.google.dexmaker:dexmaker:1.2'
compile 'com.google.dexmaker:dexmaker-mockito:1.2'

compile 'com.bartoszlipinski.flippablestackview:library:1.2.1'
compile 'com.edmodo:rangebar:1.0.0'
compile 'com.github.clans:fab:1.6.1'

compile fileTree(dir: '../libs', include: '*.jar')

testCompile('org.robolectric:robolectric:3.0') {
    exclude group: 'commons-logging', module: 'commons-logging'
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'recyclerview-v7'
}
testCompile "org.robolectric:shadows-multidex:3.0" // this is needed to avoid multidex

// Dependencies for local unit tests
//    testCompile "org.assertj:assertj-core:$rootProject.ext.assertjCore"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"

// Android Testing Support Library's runner and rules
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"

// Espresso UI Testing dependencies.
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"

// dependencies added after dex split
//    compile 'com.jakewharton.timber:timber:3.1.0'
 }


 configurations.all {
     resolutionStrategy.force "com.android.support:support-   annotations:$rootProject.supportLibraryVersion"
     resolutionStrategy.force "org.hamcrest:hamcrest-core:$rootProject.hamcrestVersion"
     resolutionStrategy.force "com.squareup:javawriter:2.5.0"
}

 configurations.compile.dependencies.each { compileDependency ->
     println "Excluding compile dependency: ${compileDependency.getName()}"
     configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
         configurations.androidTestCompile.exclude module:    "${compileDependency.getName()}"
    }
 }
app build.gradle:

buildscript {
    repositories {
        jcenter()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

subprojects {
    task allDependencies(type: DependencyReportTask) {}
}
buildscript {
repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

dependencies {
    classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.14.7'
    classpath "com.newrelic.agent.android:agent-gradle-plugin:4.244.0"
}
}

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'http://download.crashlytics.com/maven' }
}

task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}

apply plugin: 'com.android.application'

 android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

signingConfigs {
    release
}

testBuildType "debug"

defaultConfig {
    targetSdkVersion 23
    minSdkVersion 14

    multiDexEnabled true

    applicationId "com.freelancer.android.messenger"
    versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
    versionName "${versionMajor}.${versionMinor}.${versionPatch}"
    testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

    renderscriptTargetApi 21
    renderscriptSupportModeEnabled true

}

sourceSets {
    production {
        java.srcDir 'src/common/java'
    }

    develop {
        java.srcDir 'src/common/java'
    }

    staging {
        java.srcDir 'src/common/java'
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
        proguardFile 'proguard.cfg'
        buildConfigField "String", "CONTENT_PROVIDER_AUTHORITY",
                "\"com.freelancer.android.messenger.content_provider\""
    }
    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '.' + versionBuild + '-debug' + gitSha
        buildConfigField "String", "CONTENT_PROVIDER_AUTHORITY",
                "\"com.freelancer.android.messenger.content_provider.\" + BUILD_TYPE.toLowerCase()"
        debuggable true
        testCoverageEnabled = true
    }

    staging {
        applicationIdSuffix '.staging'
        versionNameSuffix '-staging-' + gitSha

        buildConfigField "String", "BASE_URL_API", "\"${rootProject.ext.stagingApiServer}\""
        buildConfigField "String", "BASE_URL_AUTH", "\"${rootProject.ext.stagingAuthServer}\""
        buildConfigField "String", "BASE_URL_WSS", "\"${rootProject.ext.stagingWsServer}\""
        buildConfigField "String", "BASE_URL_GAF", "\"${rootProject.ext.stagingGafUrl}\""
    }
}


productFlavors {
    // Define separate dev and prod product flavors.
    develop {
        // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
        // to pre-dex each module and produce an APK that can be tested on
        // Android Lollipop without time consuming dex merging processes.
        minSdkVersion 21
    }
    production {
        // The actual minSdkVersion for the application.
    }
    mock {

    }

}

// from android 6 apache its been deprecated: refer to ->
// http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
 //    useLibrary 'org.apache.http.legacy'

}


dependencies {

compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'com.android.support:palette-v7:22.2.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:design:22.2.0'

compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.google.android.gms:play-services-analytics:7.5.0'

compile 'com.google.maps.android:android-maps-utils:0.3.4'
compile 'com.google.code.gson:gson:2.3'

// extension for popular dashclock app
compile 'com.google.android.apps.dashclock:dashclock-api:2.0.0'

compile 'com.jakewharton:butterknife:4.0.1'
compile 'com.squareup:otto:1.3.5'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'

compile ('com.facebook.android:facebook-android-sdk:3.23.0') {
    exclude group: 'com.google.android'
}

compile 'com.newrelic.agent.android:android-agent:4.244.0'
compile "com.mixpanel.android:mixpanel-android:4.5.3"
compile 'com.crashlytics.android:crashlytics:1.1.13'

compile 'com.github.kevinsawicki:http-request:6.0' // TODO deprecate and replace methods with okhttp

compile 'com.koushikdutta.async:androidasync:1.2.9@jar'
compile 'com.koushikdutta.ion:ion:1.2.9@jar'
compile 'com.path:android-priority-jobqueue:1.1.2'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.soundcloud.android:android-crop:0.9.10@aar'

compile project(':libs:stickylistheaders:library')
compile project(':libs:android-core:android-core-library')
compile project(':libs:viewpagerindicator:library')
compile project(':libs:PagerSlidingTabStrip')

compile "org.mockito:mockito-core:1.10.19"
compile 'com.google.dexmaker:dexmaker:1.2'
compile 'com.google.dexmaker:dexmaker-mockito:1.2'

compile 'com.bartoszlipinski.flippablestackview:library:1.2.1'
compile 'com.edmodo:rangebar:1.0.0'
compile 'com.github.clans:fab:1.6.1'

compile fileTree(dir: '../libs', include: '*.jar')

testCompile('org.robolectric:robolectric:3.0') {
    exclude group: 'commons-logging', module: 'commons-logging'
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'recyclerview-v7'
}
testCompile "org.robolectric:shadows-multidex:3.0" // this is needed to avoid multidex

// Dependencies for local unit tests
//    testCompile "org.assertj:assertj-core:$rootProject.ext.assertjCore"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"

// Android Testing Support Library's runner and rules
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"

// Espresso UI Testing dependencies.
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"

// dependencies added after dex split
//    compile 'com.jakewharton.timber:timber:3.1.0'
 }


 configurations.all {
     resolutionStrategy.force "com.android.support:support-   annotations:$rootProject.supportLibraryVersion"
     resolutionStrategy.force "org.hamcrest:hamcrest-core:$rootProject.hamcrestVersion"
     resolutionStrategy.force "com.squareup:javawriter:2.5.0"
}

 configurations.compile.dependencies.each { compileDependency ->
     println "Excluding compile dependency: ${compileDependency.getName()}"
     configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
         configurations.androidTestCompile.exclude module:    "${compileDependency.getName()}"
    }
 }

我遵循测试的方法来让测试在我的项目上运行(例如mokito),但它不起作用

这个问题可能与newrelic版本有关。我已尝试安装最新版本的newrelic,并已成功安装

classpath“com.newrelic.agent.android:agent gradle插件:5.5.0”

编译'com.newrelic.agent.android:android-agent:5.5.0'


要解决问题,请执行以下步骤。()

  • 将所有库(来自Google Play服务和支持库以及使用的其他SDK的依赖项)更新为最大可用版本。如果您使用的是NewRelic,请更新至最新版本
  • 将multiDexEnabled true添加到/app/build.gradle中的defaultConfig

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        multiDexEnabled true
    }
    
  • 删除以前为使多重索引工作而编写的所有代码。 比如说,

    • 删除MultiDex的
      afterEvaluate

      afterEvaluate {
          tasks.matching {
              it.name.startsWith('dex')
          }.each { dx ->
              if (dx.additionalParameters == null) {
                  dx.additionalParameters = []
          }
          dx.additionalParameters += '--multi-dex'
      
          // this is optional
          //  dx.additionalParameters += "--main-dex-list=$projectDir/multidex-classes.txt".toString()
          }
      }
      
    • 删除多索引依赖项

      dependencies {
          ...
          compile 'com.android.support:multidex:1.0.1'
      }
      
    • AndroidManifest.xml

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.example.pcsalt.multidex">
          <application
                  ...
              android:name="android.support.multidex.MultiDexApplication">
                  ...
          </application>
      </manifest>
      
  • 在/build.gradle中将生成工具版本更新为
    2.1.2
    (编写本文时可用的最高稳定版本)

    classpath 'com.android.tools.build:gradle:2.1.2'
    
  • 通过单击“立即同步”来同步项目

  • 希望这有帮助


    你解决过这个问题吗?试试5.+(我知道这在道德上是不正确的,但嘿,这是我们正在谈论的分析API集成。如果5.+工作正常,那么试着返回到一个更新的版本。试着始终保持具体)