使用proguard生成签名APK时出错 - 使用GMS进行项目

时间:2017-03-21 23:08:03

标签: android proguard android-proguard

尝试使用proguard生成指定的APK时,我遇到错误。回复消息:

  Warning: com.google.gms.googleservices.GoogleServicesPlugin: can't find superclass or interface org.gradle.api.Plugin
  Warning: com.google.gms.googleservices.GoogleServicesPlugin: can't find superclass or interface groovy.lang.GroovyObject
  ...
  Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
  > java.io.IOException: Please correct the above warnings first.

将Firebase Cloud Messaging添加到项目后,问题就出现了。 Bellow my build.gradle文件。

  apply plugin: 'com.android.application'

  android {
  compileSdkVersion 25
  buildToolsVersion "25.0.2"
  defaultConfig {
  applicationId 'com...'
  minSdkVersion 15
  targetSdkVersion 25
  versionCode 29
  versionName "2.1"
  testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  multiDexEnabled true
  resConfigs "en", "pt", "fr", "es", "it", "de", "ru"
  }
  buildTypes {
  release {
  shrinkResources true
  minifyEnabled true
  proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  }
  }
  productFlavors {
  }
  packagingOptions {
  exclude 'META-INF/LICENSE'
  exclude 'META-INF/LICENSE-FIREBASE.txt'
  exclude 'META-INF/NOTICE'
  }
  }

  dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  exclude group: 'com.android.support', module: 'support-annotations'
  })
  compile 'com.android.support:appcompat-v7:25.2.0'
  compile 'com.android.support:design:25.2.0'
  compile 'com.android.support:cardview-v7:25.2.0'
  compile 'com.google.android.gms:play-services:10.2.0'
  compile 'com.google.firebase:firebase-ads:10.2.0'
  compile 'com.android.support:multidex:1.0.1'
  compile 'com.google.gms:google-services:3.0.0'
  compile 'com.google.code.findbugs:jsr305:2.0.1'
  compile 'com.google.firebase:firebase-core:10.2.0'
  compile 'com.google.firebase:firebase-messaging:10.2.0'
  testCompile 'junit:junit:4.12'
  compile project(path: ':backend', configuration: 'android-endpoints')
  }

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

现在我的proguard-rules.pro文件。

  -keep class org.gradle.api.** { *; }
  -keep interface org.gradle.api.** { *; }

  -keep class groovy.lang.** { *; }
  -keep interface groovy.lang.** { *; }

  -keep class sun.misc.** { *; }
  -keep interface sun.misc.** { *; }

  -keep class org.codehaus.groovy.runtime.** { *; }
  -keep interface org.codehaus.groovy.runtime.** { *; }

  -keep class org.codehaus.groovy.reflection.** { *; }
  -keep interface org.codehaus.groovy.reflection.** { *; }

  -keep class com.google.gson.** { *; }
  -keep interface com.google.gson.** { *; }

我已经尝试了所有有互联网的东西。

2 个答案:

答案 0 :(得分:1)

您有以下依赖关系:

compile 'com.google.gms:google-services:3.0.0'

这是您的Android应用应包含的依赖关系,但是可以包含在classpath部分中的一行。

删除该依赖项。

答案 1 :(得分:0)

我通过从我的项目中导入其源代码的模块的com.github.dcendents:android-maven-gradle-plugin:2.0中删除build.gradle个模块来解决此问题。