Android Studio cannot resolve getDefaultProguardFi

2019-07-22 08:21发布

When I run my program i get no problems. When I try to generate signed apk, I am told that getDefaultProguardFile cannot be resolved. How can I fix this. Here is the code.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.dose.apps.brainnoodles"
        minSdkVersion 8
        targetSdkVersion 21
        versionCode 13
        versionName "2.13"
    }
    buildTypes {
        release {
            //apply plugin: 'idea'
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile files('libs/InMobi-4.5.3.jar')
}

Here's the stacktrace that was asked

Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'void setTraversalAfter(android.view.View,int)' in library class android.view.accessibility.AccessibilityNodeInfo
Warning:android.support.v4.media.session.MediaSessionCompatApi22: can't find referenced method 'void setRatingType(int)' in library class android.media.session.MediaSession
Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'android.view.accessibility.AccessibilityNodeInfo getTraversalBefore()' in library class android.view.accessibility.AccessibilityNodeInfo
Warning:com.inmobi.commons.internal.ActivityRecognitionManager: can't find referenced class com.google.android.gms.common.GooglePlayServicesUtil
Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'void setTraversalAfter(android.view.View)' in library class android.view.accessibility.AccessibilityNodeInfo
Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'android.view.accessibility.AccessibilityNodeInfo getTraversalAfter()' in library class android.view.accessibility.AccessibilityNodeInfo
Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'void setTraversalBefore(android.view.View)' in library class android.view.accessibility.AccessibilityNodeInfo
Warning:android.support.v4.view.accessibility.AccessibilityNodeInfoCompatApi22: can't find referenced method 'void setTraversalBefore(android.view.View,int)' in library class android.view.accessibility.AccessibilityNodeInfo
Warning:com.inmobi.commons.internal.ActivityRecognitionManager$a: can't find referenced class com.google.android.gms.common.GooglePlayServicesUtil
         You may need to add missing library jars or update their versions.
Warning:there were 6 unresolved references to classes or interfaces.
Warning:com.inmobi.commons.uid.a: can't find referenced class com.google.android.gms.common.GooglePlayServicesUtil
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 7 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
:app:proguardRelease FAILED
Error:Execution failed for task ':app:proguardRelease'.
> java.io.IOException: Please correct the above warnings first.
Information:BUILD FAILED

3条回答
Summer. ? 凉城
2楼-- · 2019-07-22 08:38

You might have to replace the buildtypes codepart with this

signingConfigs {
    release {
        storeFile file("release.keystore")
        storePassword "******"
        keyAlias "******"
        keyPassword "******"
    }
}

buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}
查看更多
对你真心纯属浪费
3楼-- · 2019-07-22 08:59

I had the same problem. Note that in the log they are pointing you to go to http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember and there it says:

If you're developing for Android and ProGuard complains that it can't find a method that is only available in a recent version of the Android run-time, you should change the build target in your project.properties file or build.gradle file to that recent version. You can still specify a different minSdkVersion and a different targetSdkVersion in your AndroidManifest.xml file.

I changed the compileSdkVersion & targetSdkVersion from 21 to 22 and it worked.

查看更多
做自己的国王
4楼-- · 2019-07-22 08:59

@That Thatson :

Just update your buildTypes instead your . Try this way.

buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
查看更多
登录 后发表回答