0

My project builds and runs on my emulator, but fails when I try to generate an APK for my project. I am receiving the following the error when I attempt to generate the release APK:

Warning:com.google.android.gms.gcm.GcmTaskService: can't find referenced field 'android.os.IBinder zzaHj' in program class com.google.android.gms.gcm.PendingCallback

Warning:there were 1 unresolved references to program class members.

Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.


My proguard-rules.pro

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

# Attempted below to fix issue
#-keep public class com.google.android.gms.* { public *; }
#-dontwarn com.google.android.gms.**

Build.gradle

apply plugin: 'com.android.application'

repositories {
  google()
  // Alternative attempt to resolve
  //    jcenter()
  //    maven {
  //        url "https://maven.google.com"
  //    }
}

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile "com.android.support:support-v4:25.3.1"
    compile "com.android.support:support-v13:25.3.1"
    compile "com.android.support:cardview-v7:25.3.1"
    compile "com.android.support:appcompat-v7:25.3.1"
    compile 'com.google.firebase:firebase-auth:11.0.2'
    compile 'com.google.firebase:firebase-database:11.0.2'
    compile 'com.google.firebase:firebase-crash:11.0.2'
    compile 'com.google.firebase:firebase-config:11.0.2'
    compile 'com.google.firebase:firebase-storage:11.0.2'
    compile 'com.google.firebase:firebase-messaging:11.0.2'
    compile 'com.google.firebase:firebase-core:11.0.2'
    compile 'com.google.android.gms:play-services:11.0.2'
    compile 'com.firebase:firebase-jobdispatcher:0.6.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

List<String> dirs = [
        'main',     // main sample code; look here for the interesting stuff.
        'common',   // components that are reused by multiple samples
        'template'] // boilerplate code that is generated by the sample template process

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.0'

    defaultConfig {
        applicationId "com.company.app"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 12
        versionName "1.11"
        multiDexEnabled true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']

    }


    buildTypes {
        release {
            minifyEnabled true // Enables code shrinking for the release build type.
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    productFlavors {
    }

}
apply plugin: 'com.google.gms.google-services'

Attempts to fix

  1. I have tried adding the following to my proguard-rules.pro (as suggested here):

    -keep public class com.google.android.gms.* { public *; } -dontwarn com.google.android.gms.**

But this just creates the following issue:

Warning:Exception while processing task java.io.IOException: Can't write [/Users/myName/Documents/myProjectFolder/app/build/intermediates/transforms/proguard/release/jars/3/1f/main.jar] (Can't read [/Users/myName/.android/build-cache/a80bb41778b1f73h09e3t326jn804m46e280aw10/output/jars/classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:com/google/android/gms/gcm/PendingCallback.class]))

  1. https://stackoverflow.com/a/46047978/4206520
  2. https://stackoverflow.com/a/33953133/4206520

Does anyone understand why my build fails when generating APK but not building and deploying (and how to prevent it from happening)?

Rbar
  • 3,740
  • 9
  • 39
  • 69
  • You have `"com.android.support:support-v4:25.3.1"` and `"com.android.support:support-v13:25.3.1"`, maybe this could produce problem. I think adding latest support version is the best practice. – Stanojkovic Oct 26 '17 at 21:34

1 Answers1

1

Please remove

compile 'com.google.android.gms:play-services:11.0.2'

from dependencies in build.gradle file

Use individual modules in dependencies as given in below link Set up Google Play Services

Duplicate Entry error means, two same classes are there in your project and there exists conflicts b/w them

Sangeet Suresh
  • 2,527
  • 1
  • 18
  • 19
  • Thanks for the response Sangeet. I believe this may be on the right track, but only doing this (for ex. removing `compile 'com.google.android.gms:play-services:11.0.2'` and adding `compile 'com.google.android.gms:play-services-gcm:11.4.2'`) causes the error `Error:(37, 13) Failed to resolve: com.google.android.gms:play-services-gcm:11.4.2` and then nothing happens when I click the prompt to "Install Repository and sync project" – Rbar Oct 26 '17 at 21:40
  • You could install google play services from Android SDK manager itself – Sangeet Suresh Oct 27 '17 at 03:41