Proguard ignores config file of library

前端 未结 4 1305
挽巷
挽巷 2020-11-27 14:31

I\'m facing a really weird problem for days now...

I have a Gradle app with two modules, one main module and one library module.

  • In both modules I have
4条回答
  •  醉梦人生
    2020-11-27 15:28

    You typically should not enable ProGuard in the library project. ProGuard processes the application and the library together in the application project, which is the most effective approach.

    In the library project, you can specify any library-specific ProGuard configuration in build.gradle, e.g.:

    defaultConfig {
        consumerProguardFiles 'proguard-rules.txt'
    }
    

    This file is then packaged in the library aar as proguard.txt and automatically applied in the application project.

    If you do enable ProGuard in a library project (maybe because you want to distribute the library), then you also have to add the proper configuration for processing the library. The Android Gradle build doesn't seem to do this automatically. You can:

    1. Copy android-sdk/tools/proguard/examples/library.pro to proguard-project.txt in your library project.
    2. Remove the sample input/output lines -injars, -outjars, -libraryjars, -printmapping from the file. The Gradle build process automatically provides these options.
    3. Reference the configuration from the build.gradle of the library project.

    Enabling/disabling ProGuard independently for the library project and for the application project works fine for me.

提交回复
热议问题