生成APK时构建失败但未构建和部署

时间:2017-10-26 19:33:06

标签: android apk build.gradle android-proguard

我的项目在我的模拟器上构建并运行,但在我尝试为我的项目生成APK时失败。当我尝试生成发布APK时,我收到以下错误:

  

警告:com.google.android.gms.gcm.GcmTaskService:找不到   在程序类中引用字段'android.os.IBinder zzaHj'   com.google.android.gms.gcm.PendingCallback

     

警告:有1个   对程序类成员的未解析引用。

     

警告:异常   处理任务时java.io.IOException:请更正以上内容   警告先。

     

错误:任务执行失败   ':应用程序:transformClassesAndResourcesWithProguardForRelease'。

我的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'

尝试修复

  1. 我尝试将以下内容添加到proguard-rules.pro(按建议here):

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

  2. 但这只会产生以下问题:

      

    警告:处理任务java.io.IOException时出现异常:不能   写   [/Users/myName/Documents/myProjectFolder/app/build/intermediates/transforms/proguard/release/jars/3/1f/main.jar]   (看不懂   [/Users/myName/.android/build-cache/a80bb41778b1f73h09e3t326jn804m46e280aw10/output/jars/classes.jar(;;;;;;**.class)]   (重复的zip条目   [classes.jar:COM /谷歌/机器人/克/ GCM / PendingCallback.class]))

    1. https://stackoverflow.com/a/46047978/4206520
    2. https://stackoverflow.com/a/33953133/4206520
    3. 是否有人理解为什么我的构建在生成APK但未构建和部署(以及如何防止它发生)时失败?

1 个答案:

答案 0 :(得分:1)

请删除

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

来自dependencies文件中的build.gradle

在依赖关系中使用单个模块,如下面的链接所示 Set up Google Play Services

重复输入错误意味着,项目中存在两个相同的类,并且存在冲突,而不是