应用程序没有在android studio中使用multidexEnabled启动 - 着名的65k参考方法

时间:2015-07-17 11:15:47

标签: android android-studio android-multidex

之前我使用的是Eclipse IDE,因为我使用了很多来自Amazon的库,我开始得到65K方法引用错误。所以我从Eclipse转移到Android studio最新的预览频道版本。我的gradle看起来像:

apply plugin: 'com.android.application'

android {
    packagingOptions {
        exclude 'META-INF/LICENSE'
    }
    signingConfigs {
        xxx {
            keyAlias 'xxx'
            keyPassword 'xxx'
            storeFile file('path')
            storePassword 'xxx'
        }
    }
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.xxx.app"
        versionCode 4
        versionName "0.4"

        // Enabling multidex support.
        multiDexEnabled true
    }
    productFlavors {
        // Define separate dev and prod product flavors.
        dev {
            // 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
        }
        prod {
            // The actual minSdkVersion for the application.
            minSdkVersion 15
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.xxx
        }
        debug {
            signingConfig signingConfigs.xxx
            minifyEnabled false
        }
    }
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.soundcloud.android:android-crop:1.0.0@aar'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'com.android.support:multidex:1.0.0'
    compile files('libs/gcm.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/universal-image-loader-1.9.2-with-sources.jar')
    compile files('libs/aspectjweaver.jar')
    compile files('libs/aws-java-sdk-1.9.39.jar')
    compile files('libs/commons-codec-1.6.jar')
    compile files('libs/commons-logging-1.1.3.jar')
    compile files('libs/freemarker-2.3.18.jar')
    compile files('libs/httpclient-4.3.jar')
    compile files('libs/httpcore-4.3.jar')
    compile files('libs/jackson-annotations-2.3.0.jar')
    compile files('libs/jackson-core-2.3.2.jar')
    compile files('libs/jackson-databind-2.3.2.jar')
    compile files('libs/javax.mail-api-1.4.6.jar')
    compile files('libs/joda-time-2.2.jar')
    compile files('libs/spring-beans-3.0.7.jar')
    compile files('libs/spring-context-3.0.7.jar')
    compile files('libs/spring-core-3.0.7.jar')
    compile 'com.google.android.gms:play-services:7.5.0'
    compile project(':flipcheckbox')
}

我的gradle构建成功,我已将构建变体设置为devDebug但是当我单击Run(绿色图标)时,应用程序未安装在设备上。我等了45分钟,但它只显示我的Gradle任务正在运行。

我有应用程序类,它扩展了MultiDexApplication并添加了attachBaseContext方法。

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

我正在尝试运行该应用程序超过一天,不幸的是没有什么对我有用。我的申请中还有其他什么吗?欢迎提出所有建议。

更新日志: -

Error: duplicate files during packaging of APK E:\Workspace\AndroidStudio\Loneous\app\build\outputs\apk\app-dev-debug-unaligned.apk
    Path in archive: META-INF/LICENSE
    Origin 1: E:\Workspace\AndroidStudio\Loneous\app\libs\jackson-annotations-2.3.0.jar
    Origin 2: E:\Workspace\AndroidStudio\Loneous\app\libs\httpcore-4.3.jar
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'META-INF/LICENSE'
      }
    }

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageDevDebug'.
> Duplicate files copied in APK META-INF/LICENSE
    File 1: E:\Workspace\AndroidStudio\Loneous\app\libs\jackson-annotations-2.3.0.jar
    File 2: E:\Workspace\AndroidStudio\Loneous\app\libs\httpcore-4.3.jar


* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:packageDevDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:310)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.tooling.BuildException: Duplicate files copied in APK META-INF/LICENSE
    File 1: E:\Workspace\AndroidStudio\Loneous\app\libs\jackson-annotations-2.3.0.jar
    File 2: E:\Workspace\AndroidStudio\Loneous\app\libs\httpcore-4.3.jar

    at com.android.build.gradle.tasks.PackageApplication.doFullTaskAction(PackageApplication.groovy:111)
    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.groovy:64)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:243)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:230)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 14 more
Caused by: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
    File 1: E:\Workspace\AndroidStudio\Loneous\app\libs\jackson-annotations-2.3.0.jar
    File 2: E:\Workspace\AndroidStudio\Loneous\app\libs\httpcore-4.3.jar

    at com.android.builder.internal.packaging.Packager$JavaAndNativeResourceFilter.checkEntry(Packager.java:178)
    at com.android.builder.signing.SignedJarBuilder.writeZip(SignedJarBuilder.java:260)
    at com.android.builder.internal.packaging.Packager.addResourcesFromJar(Packager.java:458)
    at com.android.builder.core.AndroidBuilder.packageApk(AndroidBuilder.java:1511)
    at com.android.builder.core.AndroidBuilder$packageApk$11.call(Unknown Source)
    at com.android.build.gradle.tasks.PackageApplication.doFullTaskAction(PackageApplication.groovy:98)
    ... 22 more

1 个答案:

答案 0 :(得分:1)

既然您正在使用Android Studio,请尝试仅包含所需的Play服务模块而不是完整堆栈,这将大大减少总方法数:

https://developers.google.com/android/guides/setup#split

在那之后你可能不需要multidex。

编辑:您还必须删除gcm.jar并使用Play服务版本,否则您的项目中可能会有重复的文件而且无法构建。