1

早些时候我使用的是 Eclipse IDE,由于我使用了很多来自 Amazon 的库,我开始收到 65K 方法引用错误。所以我从 Eclipse 转移到了 Android studio 最新的预览频道版本。我的毕业典礼看起来像:

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,但是当我单击运行(绿色图标)时,该应用程序未安装在设备上。我等了 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
4

1 回答 1

1

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

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

也许在那之后你就不需要 multidex 了。

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

于 2015-07-17T11:40:28.087 回答