簡體   English   中英

使用Android Studio簽名APK時出現Proguard錯誤

[英]Proguard error while signing APK with Android Studio

我正在嘗試使用Proguard調試錯誤。 我的項目在調試時工作正常,但在Proguard中卻無法正常工作。 任何幫助將不勝感激。

  1. 我曾嘗試在Proguard中ignore warning 但是,應用程序因生成的APK而崩潰。
  2. 當前的Proguard設置不起作用。 我已上傳到Gist的消息控制台
  3. Build.gradle在下面給出
  4. 要點中的 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'

嘗試將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記錄失敗

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM