简体   繁体   中英

Using Proguard With Android Studio problems generating signed apk

build.gradle file

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')
}

I have few library projects such as facebook. Both my project and the library use the same version of support library v13.

While generating a signed apk i am getting these errors

Execution failed for task ':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]))

I have no clue how to solve this and generate a signed apk

Also went through the library projects libs folder and din't find android-support-v4.jar. All i have is android-support-v13.jar

Don't reference the support library by including its jar directly; when you do this, the build system can't disambiguate between multiple versions of it, and you get errors of this type. Include it by referencing its Maven coordinates:

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

where XXX is the proper version number based on what API you're compiling against. If you include this dependency via the UI at Project Structure > (your module) > Dependencies > + Button > Library dependency it will help you choose the right version number.

You may also find it convenient to include other dependencies via Maven coordinates instead of wrangling their jars; that same library dependency UI has a search function to help you find libraries.

I added support-v13 from SDK as mentioned above, direct library dependency not through lib folder.

Apart from the above changes, I did some modification in my proguard-android.txt file.

For third party libraries added:

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

For facebook added:

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

Now, it's working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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