簡體   English   中英

將Proguard與Android Studio一起使用時會生成簽名的APK問題

[英]Using Proguard With Android Studio problems generating signed apk

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

不要通過直接包含其jar來引用支持庫; 當您執行此操作時,構建系統無法在多個版本之間進行歧義化,並且會出現此類錯誤。 通過引用其Maven坐標將其包括在內:

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

其中XXX是根據您使用的API正確的版本號。 如果您通過UI在項目結構>(您的模塊)>依賴關系> +按鈕>庫依賴關系中包含此依賴關系 ,它將幫助您選擇正確的版本號。

您可能還會發現通過Maven坐標包含其他依賴項而不是對它們的jar進行爭用很方便。 該庫依賴項UI具有搜索功能以幫助您找到庫。

如上所述,我從SDK添加了support-v13,而不是通過lib文件夾直接依賴庫。

除了上述更改之外,我還在proguard-android.txt文件中做了一些修改。

對於添加的第三方庫:

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

對於facebook添加:

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

現在,它工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM