使用Android Studio签名APK时出现Proguard错误

时间:2018-09-09 22:53:27

标签: android android-gradle build.gradle proguard android-proguard

我正在尝试使用Proguard调试错误。我的项目在调试时工作正常,但在Proguard中却无法正常工作。任何帮助将不胜感激。

  1. 我在Proguard中尝试了ignore warning。但是,应用程序因生成的APK而崩溃。
  2. 当前Proguard设置不起作用。我已上传到Gist
  3. 的消息控制台
  4. Build.gradle在下面给出
  5. gist中的Prodguard-project.txt

    buildscript {
      repositories {
        jcenter()
      }
    
      dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
      }
    }
    

build.gradle

    apply plugin: 'com.android.application'
    apply from: rootProject.file('gradle/codequality.gradle')
    android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
      versionCode 49
      versionName "1.8.8"

      minSdkVersion 14
      targetSdkVersion 22

      buildConfigField 'String', 'BUILD_TAG', '"' + getBuildTag() + '"'
      buildConfigField 'String', 'OWM_API_KEY', '"' + getOpenWeatherMapApiKey() + '"'
      buildConfigField 'boolean', 'ENABLE_WEATHER', 'true'

      def buildSuffix = getBuildSuffix(versionName, versionCode)
      applicationVariants.all { variant ->
        def file = variant.outputs[0].outputFile
        variant.outputs[0].outputFile = new File(file.parent, file.name.replace(".apk", "-" + buildSuffix + ".apk"))
      }
    }

    if (project.hasProperty('signingKeyStoreFile')) {
      signingConfigs {
        release {
            storeFile     file(signingKeyStoreFile)
            storePassword signingKeyStorePassword
            keyAlias      signingKeyAlias
            keyPassword   signingKeyPassword
        }
      }
    }

    buildTypes {
      release {
         minifyEnabled true
         proguardFile 'proguard-project.txt'
         if (project.hasProperty('signingKeyStoreFile')) {
            signingConfig signingConfigs.release
         }
       }
    }

    lintOptions {
        abortOnError false
        checkReleaseBuilds false
        disable 'MissingTranslation'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
  }

  def getBuildSuffix(versionName, versionCode) {
    def suffix = versionName + '-' + versionCode
    if (System.getenv()['BUILD_NUMBER'] != null) {
        suffix += '-b' + System.getenv()['BUILD_NUMBER']
    }
    return suffix
  }

  def getBuildTag() {
    def tag = ''
    if (System.getenv()['BUILD_NUMBER'] != null) {
        tag += 'b' + System.getenv()['BUILD_NUMBER']
    } else {
        tag += 'l'
    }
    tag += '@' + new Date().format('yyyyMMdd')
    return tag
  }

  def getOpenWeatherMapApiKey() {
    if (project.hasProperty('owmApiKey')) {
        return owmApiKey
    } else {
        def apiKeyFile = file('default_owm_api_key');
        if (apiKeyFile.isFile()) {
          return apiKeyFile.text.trim()
        }
    }
    return 'NOKEY'
  }

  ///////////////////////////////////////////////////
  // Dependencies

  repositories {
    mavenCentral()
  }

  dependencies {

    //compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    //compile 'com.android.support:support-v4:19.1.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'net.danlew:android.joda:2.9.4.1'
    compile 'com.google.android.gms:play-services-ads:9.8.0'
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
  }
  configurations {
    all*.exclude group: 'com.google.firebase', module: 'firebase-core'
    all*.exclude group: 'com.google.firebase', module: 'firebase-iid'
  }

  ///////////////////////////////////////////////////
  // Checkstyle

  task checkstyleDebug(type: Checkstyle, dependsOn: 'compileDebugSources') {
    source = fileTree('src/main/java/')
    classpath = files('build/intermediates/classes/debug')
  }
check.dependsOn checkstyleDebug

  ///////////////////////////////////////////////////
  // Findbugs

  task findbugsDebug(type: FindBugs, dependsOn: 'compileDebugSources') {
    source = fileTree('src/main/java/')
    classes = fileTree('build/intermediates/classes/debug')
    classpath = files() // empty classpath!
    effort = 'max'
    excludeFilter = rootProject.file('config/findbugs/androidExcludeFilter.xml')
  }
  check.dependsOn findbugsDebug

  ///////////////////////////////////////////////////
  // PMD

  task pmd(type: Pmd) {
    source = fileTree('src/main/java/')
    ruleSets = ['java-basic', 'java-braces', 'java-android']
  }
  check.dependsOn 'pmd'

1 个答案:

答案 0 :(得分:0)

尝试将getDefaultProguardFile('proguard-android.txt')添加到proguardFile 'proguard-project.txt',以获得下一行:

proguardFile getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' 或开始从您的proguard-project.txt中搜索问题,例如:

  1. 添加规则-keepattributes SourceFile,LineNumberTable,InnerClasses,Signature,Exceptions

  2. 添加规则-dontwarn com.google.** 依此类推,由您的proguard记录失败