【问题标题】:Using Proguard With Android Studio problems generating signed apk使用带有 Android Studio 的 Proguard 生成签名 apk 的问题
【发布时间】:2014-12-17 11:10:27
【问题描述】:

build.gradle 文件

apply plugin: 'com.android.application'



android {
    signingConfigs {
        config {
            keyAlias 'abc'
            keyPassword 'feet'
            storeFile file('C:/Users/Nabasree/Desktop/mylocation')
            storePassword 'feet'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false

    }
    compileSdkVersion 19
    buildToolsVersion "21.1.1"
    defaultConfig {
        applicationId "in.myapp"
        minSdkVersion 14
        targetSdkVersion 19
    }
    buildTypes {

        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }
        debug {
            debuggable true
            signingConfig signingConfigs.config

        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    productFlavors {
    }
}

dependencies {
    compile project(':facebookSDK')
    compile project(':glowPadView')
    compile project(':pullToRefreshListView')
    compile project(':librari')
    // compile ('com.github.flavienlaurent.datetimepicker:library:VERSION');
    compile project(':viewPagerIndicatorLib')
    compile files('libs/android-saripaar-1.0.2.jar')
    compile files('libs/android-support-v13.jar')
    compile files('libs/com.haarman.listviewanimations-2.6.0.jar')
    compile files('libs/crashlytics.jar')
    compile files('libs/eventbus-2.2.1.jar')
    compile files('libs/image-chooser-library-1.3.0.jar')
    compile files('libs/Parse-1.7.1.jar')
    compile files('libs/picasso-2.3.2.jar')
    compile files('libs/sugar-1.2.jar')
}

我很少有图书馆项目,例如 facebook。我的项目和库都使用相同版本的支持库 v13。

生成签名的 apk 时出现这些错误

任务“:myapp:proguardRelease”执行失败。

 java.io.IOException: Can't write [..\build\intermediates\classes-proguard\release\classes.jar] (Can't read [..\build\intermediates\exploded-aar\F-Up\facebookSDK\unspecified\libs\android-support-v13.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [android/support/v4/c/b.class == android-support-v13.jar:android/support/v4/util/ArrayMap$1.class]))

我不知道如何解决这个问题并生成一个签名的 apk

还浏览了库项目的 libs 文件夹,但没有找到 android-support-v4.jar。我只有android-support-v13.jar

【问题讨论】:

  • 嗨 Nabasree,您找到解决问题的方法了吗?我现在看到完全相同的错误,我相信我像你一样拉扯我的头发:[

标签: android android-studio android-gradle-plugin build.gradle


【解决方案1】:

不要通过直接包含其 jar 来引用支持库;当你这样做时,构建系统无法在它的多个版本之间消除歧义,并且你会得到这种类型的错误。通过引用它的 Maven 坐标来包含它:

dependencies {
    compile 'com.android.support:support-v13:X.X.X'
}

其中X.X.X 是基于您正在编译的API 的正确版本号。如果您通过 UI 在 Project Structure > (your module) > Dependencies > + Button > Library dependency 中包含此依赖项,它将帮助您选择正确的版本号。

您可能还会发现通过 Maven 坐标包含其他依赖项而不是争吵它们的 jar 包很方便;同一个库依赖 UI 有一个搜索功能来帮助你找到库。

【讨论】:

  • 要添加此库,请务必从 libs 或其中存在的任何其他文件夹中删除此库
【解决方案2】:

如上所述,我从 SDK 添加了 support-v13,直接依赖库而不是通过 lib 文件夹。

除了以上改动之外,我还对我的proguard-android.txt文件做了一些修改。

对于添加的第三方库:

-dontwarn android.support.**,com.example.**,com.example1.**

为脸书添加:

-keep class com.facebook.** {
*;
}

现在,一切正常。

【讨论】:

    猜你喜欢
    • 2018-09-23
    • 2020-02-27
    • 2013-12-14
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多