无法生成可执行的签名发布版本dexgaurd

时间:2018-03-14 10:15:41

标签: android gradle android-gradle dexguard

我将项目更新为 gradle version to 4.0 ,并将android支持版本库更新为最新版(即27.0.0),目标api为 Android O(26),签名发布版本。

现在我打开应用程序时遇到了这个崩溃:

java.lang.IllegalAccessError: Method 'boolean android.view.ViewGroup.checkLayoutParams(android.view.ViewGroup$LayoutParams)' is inaccessible to class 'android.support.v7.widget.ActionMenuPresenter' (declaration of 'android.support.v7.widget.ActionMenuPresenter' appears in /data/app/com.myairtelapp-iuW7irEMrfWuoyVjp6OGKA==/base.apk)
  at android.support.v7.widget.ActionMenuPresenter.getItemView(:202)
  at android.support.v7.widget.ActionMenuPresenter.flagActionItems(:476)
  at android.support.v7.view.menu.MenuBuilder.flagActionItems(:1164)
  at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(:95)
  at android.support.v7.widget.ActionMenuPresenter.updateMenuView(:229)
  at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(:291)
  at android.support.v7.view.menu.MenuBuilder.onItemsChanged(:1051)
  at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(:1078)
  at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(:460)
  at android.support.v7.app.ToolbarActionBar$1.run(:55)
  at android.os.Handler.handleCallback(Handler.java:789)
  at android.os.Handler.dispatchMessage(Handler.java:98)
  at android.os.Looper.loop(Looper.java:164)
  at android.app.ActivityThread.main(ActivityThread.java:6809)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)'

我的build.gradle是:

    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'

    apply plugin: 'net.researchgate.release'
    apply plugin: 'dexguard'

    android {
        compileSdkVersion project.ext.compile_sdk_version
        buildToolsVersion project.ext.build_tools_version

        lintOptions {
            quiet false
            abortOnError false
            ignoreWarnings false
            disable "ResourceType"
        }
        dexOptions {
            javaMaxHeapSize "4g"
        }

        signingConfigs {
            release {

            }
        }

        flavorDimensions 'channel'
        productFlavors {
            playstore {
                dimension 'channel'
                manifestPlaceholders = [channelName: "playstore"]
            }
        }
        configurations {
            all {
                exclude group: 'org.json', module: 'json'
                exclude module: 'httpclient'
                exclude module: 'commons-logging'
                resolutionStrategy {
                    force "com.android.support:gridlayout-v7:${support_version}"
                    force "com.android.support:support-v4:${support_version}"
                    force "com.android.support:appcompat-v7:${support_version}"
                    force "com.android.support:cardview-v7:${support_version}"
                    force "com.android.support:recyclerview-v7:${support_version}"
                    force "com.android.support:design:${support_version}"
                }
            }
        }
        defaultConfig {
            applicationId "com.myairtelapp"
            minSdkVersion project.ext.min_sdk_version
            targetSdkVersion project.ext.target_sdk_version
            vectorDrawables.useSupportLibrary = true
            versionCode manifestVersionCode
            versionName manifestVersionName
            buildConfigField BOOLEAN, LOAD_DUMMY_JSON, FALSE
            // Config for enbling dummy mode
            buildConfigField BOOLEAN, SET_SPOOF_REQUEST, FALSE
            // Config for spoofing request
            buildConfigField BOOLEAN, REPORT_CRASHES, TRUE
            // Flag for reporting crashlytics


            multiDexEnabled true
        }

        buildTypes {
            release {
                buildConfigField BOOLEAN, LOG_LEVEL_DEBUG, FALSE
                signingConfig signingConfigs.release
                buildConfigField STRING, S3_URL, BASE_URL_S3_PROD
                //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                proguardFile getDefaultDexGuardFile('dexguard-release.pro')
                proguardFile 'dexguard-project.pro'
                proguardFile 'proguard-rules.pro'
            }
            debug {
                debuggable true

                buildConfigField BOOLEAN, REPORT_CRASHES, FALSE
                buildConfigField BOOLEAN, LOG_LEVEL_DEBUG, TRUE
                proguardFile getDefaultDexGuardFile('dexguard-debug.pro')
                proguardFile 'dexguard-project.pro'
                proguardFile 'proguard-rules.pro'
                applicationIdSuffix ".debug"

            }

        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }

    def gitBranchName() {
        return 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
    }

    /** generate main build tasks
     *  generated tasks : [airtelOneDebugAssemble, airtelOneReleaseAssemble, airtelOneStagingAssemble
     *                     airtelOneQaAssemble,airtelOneDummyAssemble]
     **/
    android.buildTypes.all { buildType ->
        android.productFlavors.each { flavor ->
            task("airtelOne${flavor.name.capitalize()}${buildType.name.capitalize()}Assemble") {
                if (buildType.name == android.buildTypes.release.name) {
                    dependsOn "release"
                } else {
                    dependsOn "assemble${flavor.name.capitalize()}${buildType.name.capitalize()}"
                }
            }

        }
    }
    /**
     * rename the generated apk.
     * use SNAPSHOT for intermediate builds
     */

    tasks.whenTaskAdded { task ->
        if (task.name == 'generateReleaseBuildConfig') {
            task.dependsOn 'updateVersionProperties'
        }

    }
    /*
    Override release plugin task and update version properties file.
     */
    task('updateVersionProperties') << {
        def incVersion = manifestVersionCode + 1
        props.setProperty(PropertyVersionCode, incVersion.toString())
        def appVersion = manifestVersionName.split("\\.")
        def majorVersion = appVersion[0]
        def minorVersion = appVersion[1]
        def patchVersion = appVersion[2]
        def updatePatchVersion = patchVersion.toInteger() + 1
        def newVersionName = "${majorVersion}.${minorVersion}.${updatePatchVersion}"
        props.setProperty(PropertyVersionName, newVersionName)
        def writer = new FileWriter(file(PropertiesFile))
        try {
            props.store(writer, 'Manifest Version Properties')
            writer.flush()
        } finally {
            writer.close()
        }
    }

    def getDate() {
        def date = new Date()
        def formattedDate = date.format("dd-MM'T'HH-mm")
        return formattedDate
    }

    repositories {
        mavenCentral()
        maven { url 'http://dl.bintray.com/amulyakhare/maven' }
        maven { url 'https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/' }
        maven { url 'https://maven.fabric.io/public' }
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

    dependencies {
        compile(name: 'GoogleConversionTrackingSdk-2.2.4', ext: 'jar')
        compile(name: 'leap_sdk', ext: 'aar')
        compile(name: 'SecureComponent-PROD-V1.5', ext: 'aar')
        implementation project(':qrcodereaderview')
        implementation project(':applib')
        compile 'com.android.support:multidex:1.0.3'
        compile 'com.mcxiaoke.volley:library:1.0.19'
        compile 'com.squareup:otto:1.3.8'
        compile 'com.jakewharton:butterknife:8.8.1'
        annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
        compile 'com.squareup.okhttp:okhttp:2.7.5'
        //compile 'com.facebook.android:facebook-android-sdk:4.7.0'
        compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'
        compile 'commons-codec:commons-codec:20041127.091804'
        compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.0'
        compile 'com.birbit:android-priority-jobqueue:1.3'
        compile 'com.squareup.wire:wire-runtime:1.6.1'
        compile 'com.squareup:tape:1.2.3'
        compile('com.crashlytics.sdk.android:crashlytics:2.6.3@aar') {
            transitive = true;
        }
        compile('com.github.ozodrukh:CircularReveal:1.1.1@aar') {
            transitive = true;
        }
        compile('com.moengage:moe-android-sdk:7.7.15') {
            exclude group: 'com.moengage', module: 'moe-location-lib'
        }
        compile ('com.moengage:addon-messaging:1.1.02')
                {
                    exclude group: 'com.android.support'
                }

        compile 'com.github.bumptech.glide:glide:3.7.0'
        compile ('in.juspay:godel:0.6.24.1423')
                {
                    exclude group: 'com.android.support'
                }
       /* compile ('fr.baloomba:viewpagerindicator:2.4.2')
                {
                    exclude group: 'com.android.support'
                }*/
        compile 'com.madgag.spongycastle:core:1.54.0.0'
        compile 'com.madgag.spongycastle:prov:1.54.0.0'
        compile files('libs/secure-component-sdk.jar')
        compile 'com.github.PhilJay:MPAndroidChart:v3.0.0'
        //Charts lib
        compile 'com.github.evgenyneu:js-evaluator-for-android:v2.0.0'
        compile "com.android.support:customtabs:${support_version}"
        //SafetyNet dependency
        compile ("com.google.android.gms:play-services-safetynet:${google_play_services_version}")
                {
                    exclude group: 'com.android.support'
                    exclude module: 'support-v4'
                }
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.appsflyer:af-android-sdk:4.8.8'
        compile 'com.android.installreferrer:installreferrer:1.0'
        compile ('com.firebase:firebase-jobdispatcher:0.8.5')
            {
                exclude group: 'com.android.support'
            }
    }

我检查了重复的依赖项,并删除了几乎所有重复的依赖项 我没有找到任何更好的问题

1 个答案:

答案 0 :(得分:3)

这是由于以下优化:方法/概括/类。

我尝试使用 dexguard配置中的以下规则进行发布构建:

-optimizations !method/generalization/class

它对我来说很好