【问题标题】:Can't get around warnings with gradle and proguard in Android Studio无法在 Android Studio 中使用 gradle 和 proguard 绕过警告
【发布时间】:2016-11-20 16:01:13
【问题描述】:

我最近从 eclipse 切换到 Android Studio 并开始在我的 android 应用程序中使用 gradle。 一段时间以来,在尝试在 Android Studio 中构建我的 apk 时,我一直在与一些警告作斗争。 这是错误日志:

Error:this warning is that reflective operations on this class will incorrectly
Error:compiler that did not target the modern .class file format. The recommended
Error:indicate that it is *not* an inner class.
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:(org.apache.commons.collections.BeanMap$5) that doesn't come with an
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:solution is to recompile the class from source, using an up-to-date compiler

我的 build.gradle

repositories {
    mavenCentral()
}

apply plugin: 'com.android.application'


android {
    lintOptions {
        abortOnError false
    }
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        targetSdkVersion 24
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }    

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    buildTypes {
        debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'

        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'
        }
    }
}

configurations {
    all*.exclude group: 'commons-logging', module: 'commons-logging'
}

dependencies {
    compile 'com.github.paolorotolo:appintro:4.1.0'
    compile 'com.opencsv:opencsv:3.8'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.github.tonivade:tinydb:0.7.1'
}

我尝试过使用不同的 proguard 选项,但都没有解决问题:

-keepattributes EnclosingMethod
-keepattributes InnerClasses
-dontwarn org.apache.commons.**
-keep class org.apache.commons.** 

有人知道如何解决这个问题吗? 非常感谢!

【问题讨论】:

    标签: android android-studio gradle proguard


    【解决方案1】:

    试试

    -keep class org.apache.commons.** {
        *;
    }
    

    而不是

    -keep class org.apache.commons.**
    

    【讨论】:

    • 谢谢,但问题仍然存在。
    猜你喜欢
    • 1970-01-01
    • 2015-03-15
    • 2017-05-14
    • 2019-12-30
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    相关资源
    最近更新 更多