简体   繁体   English

使用支持库失败构建的Android build.gradle

[英]Android build.gradle using Support Library Failing Build

I have been successfully building a debug release of my app during development albeit accompanied by the following warning: 尽管出现以下警告,但我在开发过程中已成功构建了我的应用程序的调试版本:

"W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable.

When I do a fullRelease build I encounter the following error: 当我执行fullRelease构建时,遇到以下错误:

Error:Execution failed for task   ':app:transformClassesAndResourcesWithProguardForFullRelease'.
> java.io.IOException: Can't write  [/PATH_TO_APP/app/build/intermediates/transforms/proguard/full/release/jar s/3/1f/main.jar] (Can't read  [/PATH_TO_APP/app/build/intermediates/exploded- aar/com.android.support/support- fragment/24.2.1/jars/classes.jar(;;;;;;**.class)] (Duplicate zip entry  [android/support/v4/app/r.class ==  classes.jar:android/support/v4/app/Fragment$1.class]))

I am incorporating the Support Libraries for the purpose of using the AppCompat Permissions in Android 6.0+. 我并入了支持库,目的是在Android 6.0+中使用AppCompat权限。 The following is my build.gradle file. 以下是我的build.gradle文件。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.3'
    useLibrary 'org.apache.http.legacy'
ext {
    supportLibVersion = '24.2.1'
}

lintOptions {
    abortOnError false
}

defaultConfig {
    applicationId "com.whatever.appname"
    testApplicationId 'com.whatever.appname'
    versionCode 8
    minSdkVersion 9
    targetSdkVersion 24
}

buildTypes {
    debug {
        debuggable true
        minifyEnabled false
        signingConfig signingConfigs.debug
    }
    release {
        debuggable false
        minifyEnabled true
        shrinkResources true
        proguardFile 'PATH_TO_PROGUARD/proguard-project.txt'
    }
}

signingConfigs {
    release {
        keyPassword 'PASSWORD'
        storePassword 'PASSWORD'
        keyAlias 'ALIAS'
        storeFile file('PATH_TO_KEYSTORE/keystore_file')
    }
    debug {
        keyAlias 'KEY_ALIAS'
        keyPassword 'PASSWORD'
        storePassword 'PASSWORD'
        storeFile file('PATH_TO_DEBUG_KEYSTORE/debug.keystore')
    }
}
productFlavors {
    full {
        versionName '10.6.0'
        applicationId 'com.whatever.appname'
        testApplicationId 'APP_TEST_ID'
        versionCode 8
        proguardFile '/PATH_TO_PROGUARD/proguard-project.txt'
        signingConfig signingConfigs.release
        targetSdkVersion 24
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}
dependencies {
    compile 'ch.acra:acra:4.7.0'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:support-compat:24.2.1'
    compile 'com.android.support:support-core-utils:24.2.1'
    compile 'com.android.support:support-core-ui:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-annotations:24.2.1'
    compile fileTree(include: ['*.jar'], dir: 'libs')
}

In my proguard-project.txt file, due to the use of some deprecated classes, some of the relevant and specific entries for my app are: 在我的proguard-project.txt文件中,由于使用了一些不赞成使用的类,因此与我的应用有关的一些特定条目是:

-keep class org.apache.http.** { *; }
-dontwarn org.apache.commons.**
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn com.google.android.gms.**
-dontwarn com.android.volley.toolbox.**
-ignorewarnings

For those that are curious, when I completely remove the proguard process from the build and do an application clean, followed by a fullRelease build, the errors that I encounter are different: 对于那些好奇的人,当我从构建中完全删除proguard进程并清理应用程序,然后执行fullRelease构建时,遇到的错误是不同的:

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define     Landroid/support/graphics/drawable/AnimatedVectorDrawableCompat$1;

and: 和:

Error:Execution failed for task  ':app:transformClassesWithDexForFullRelease'.
> com.android.build.api.transform.TransformException:   com.android.ide.common.process.ProcessException:    java.util.concurrent.ExecutionException:    java.lang.UnsupportedOperationException

Can anybody shed some light on the errors that I am encountering, and possibly suggest a work around? 有人能阐明我遇到的错误,并可能建议解决方法吗? Naturally, I would ideally prefer to incorporate the proguard process into build process. 自然,理想情况下,我更喜欢将proguard流程纳入构建流程。

UPDATE: Additionally, when running any gradle tasks from the command line I encountered the error: 更新:此外,从命令行运行任何gradle任务时,我遇到了错误:

problem occurred evaluating project ':app'.
> java.lang.UnsupportedClassVersionError:   com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0

which lead me to believe that somewhere in either the AppCompat or Support libraries Java 8 language features were being used, and I was compiling against Java 7. 这使我相信AppCompat或支持库中的某处正在使用Java 8语言功能,并且我正在针对Java 7进行编译。

not sure mate, but if i were you i try to look ad this 不确定队友,但是如果我是你,我会尝试广告

compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-compat:24.2.1'

maybe appcompact and support compact doesn't go well altogether. 也许appcompact和紧凑的支持不能很好地结合在一起。 try removing appcompact and use support (or viceversa) 尝试删除appcompact并使用支持(反之亦然)

hope it helps 希望能帮助到你

The solution to my problem was a configuration solution which enables the Java 8 language features as described in the document, Use Java 8 Language Features . 解决我的问题的方法是配置解决方案,该解决方案启用了Java 8语言功能,如文档Use Java 8 Language Features中所述

The exact steps I took to solve the issue were to: add the following to the build.gradle defaultConfig section. 我解决该问题的确切步骤是:将以下内容添加到build.gradle defaultConfig部分。

jackOptions {
    enabled true
}

Add the following to the build.gradle buildTypes, debug & release, respectively: 将以下内容分别添加到build.gradle buildTypes,debug&release:

debug{
    shrinkResources false
}
release {
    shrinkResources false
}

Changed the build.gradle sourceCompatability and targetCompatability Java versions from VERSION_1_7 to the following 将build.gradle sourceCompatability和targetCompatability Java版本从VERSION_1_7更改为以下版本

sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8

After carrying out these changes, I carried out a clean and Build and was able to successfully build the application. 进行了这些更改之后,我进行了清理和构建,并能够成功构建该应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM