首页 文章

Android库:释放.aar使用proguard时将classes.jar清空

提问于
浏览
4

我正在尝试使用 minifyEnabled true 生成一个库,但是在发行版.aar中,classes.jar变空了 .

我检查了我的 proguard-rules.pro ,似乎没事 .

我甚至用默认的.gradle文件创建了一个新模块,当我设置 minifyEnable true 时,发布版本仍然获得没有类内的classes.jar .

毕竟,是否有可能生成一个模糊代码的android库?

编辑1:添加模块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'
}

1 回答

  • 1

    好的,过了一段时间我解决了我的问题 .

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

    有关更多信息,请阅读this .

    在我的 build.gradle 中chagend:

    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'
            }
    }
    

    至:

    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
         }
     }
    

    谢谢您的帮助!

相关问题