androidgradleshareactionprovider

ShareActionProvider is missing share icon in release build


I have an android app that uses the appcompat.v7 ShareActionProvider. When I run the app frm Android Studio on the device, I see a share icon and I can share my content.

As soon as I run the "Generate Singned APK" from the menu and install the apk on my device, I don't see the share-icon but the text I set. And when I click on the text, the share intent is not starting.

This is my build.gradle...

android {
compileSdkVersion 22
buildToolsVersion "23.0.0"

defaultConfig {
    applicationId "xxx.xxx.xx"
    minSdkVersion 14

    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt')
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0+'
    compile 'com.google.android.gms:play-services:7.0.0'
    compile 'net.hockeyapp.android:HockeySDK:3.5.0'
}

It doesn't matter if I disable minify or shrink resources. The functionality doesn't work. The gradle build is fine, no errors there and the rest of the app is running well. I'm using v7.Toolbar for example...

Any idea why the ShareActionProvider is not working?

Best regards, Jan


Solution

  • This question is pretty old, but since I just had this problem and couldn't find an immediate solution, I'll go ahead and share the answer I eventually uncovered. The solution comes from Tanis.7x in an answer to this separate but related question here: Android Proguard: Release build Force Close

    To quote Tanis.7x

    The problem is that ShareActionProvider is being stripped/obfuscated, but the support library needs it to remain as-is.

    Add this line to your proguard configuration, and you should be set:

    -keep class android.support.v7.widget.ShareActionProvider { *; }

    I dropped that line of code into the proguard-rules.pro file, and ShareActionProvider was back to normal operation.

    Hope that helps!