Android Library: Release .aar getting classes.jar empty when using proguard

Dan*_*ilo 7 android proguard gradle android-library android-proguard

I'm trying to generate a library with minifyEnabled true but, inside the release .aar, classes.jar is getting empty.

I have checked my proguard-rules.pro and it seems to be all right.

I've even created a new module with the default .gradle files and when i set minifyEnable true the release version still gets the classes.jar with no class inside.

After all, is it possible to generate an android library obfuscating the code?

EDIT 1: Adding module build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.0'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

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

    lintOptions {
        abortOnError false
    }
}

repositories {
    maven { url 'https://maven.google.com' }
    jcenter()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'org.apache.httpcomponents:httpcore:4.3.3'
    compile('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }

    compile 'fr.bmartel:jspeedtest:1.25'
    compile "com.android.support:appcompat-v7:27.0.0"
    testCompile 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*ilo 5

好的,一段时间后我解决了我的问题。

我将默认的 proguard 规则配置(library.pro)复制/粘贴到我的proguard-rules.pro 中。您可以在path-to-your-sdk/tools/proguard/examples 中找到此文件和更多示例

有关更多信息,请阅读

在我的build.gradle 中,我提出:

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
    release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
}
Run Code Online (Sandbox Code Playgroud)

到:

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
     release {
         minifyEnabled true
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         consumerProguardFiles 'proguard-rules.pro' //added this line
     }
 }
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!